rabbit.io
Class WebConnection

java.lang.Object
  extended by rabbit.io.WebConnection
All Implemented Interfaces:
Closeable

public class WebConnection
extends Object
implements Closeable

A class to handle a connection to the Internet.

Author:
Robert Olofsson

Constructor Summary
WebConnection(Address address, SocketBinder binder, Counter counter)
          Create a new WebConnection to the given InetAddress and port.
 
Method Summary
 void close()
           
 void connect(NioHandler nioHandler, WebConnectionListener wcl)
          Try to establish the network connection.
 Address getAddress()
          Get the address that this connection is connected to
 SocketChannel getChannel()
          Get the actual SocketChannel that is used
 boolean getKeepalive()
          Get the keepalive value of this WebConnection.
 long getReleasedAt()
          Get the time that this WebConnection was released.
 boolean mayPipeline()
          Check if this WebConnection may be used for pipelining.
 void setKeepalive(boolean b)
          Set the keepalive value for this WebConnection, Can only be turned off.
 void setMayPipeline(boolean b)
          Mark this WebConnection for pipelining.
 void setReleased()
          Mark this WebConnection as released at current time.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WebConnection

public WebConnection(Address address,
                     SocketBinder binder,
                     Counter counter)
Create a new WebConnection to the given InetAddress and port.

Parameters:
address - the computer to connect to.
binder - the SocketBinder to use when creating the network socket
counter - the Counter to used to collect statistics
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getAddress

public Address getAddress()
Get the address that this connection is connected to

Returns:
the network address that the underlying socket is connected to

getChannel

public SocketChannel getChannel()
Get the actual SocketChannel that is used

Returns:
the network channel

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

connect

public void connect(NioHandler nioHandler,
                    WebConnectionListener wcl)
             throws IOException
Try to establish the network connection.

Parameters:
nioHandler - the NioHandler to use for network tasks
wcl - the listener that will be notified when the connection has been extablished.
Throws:
IOException - if the network operations fail

setKeepalive

public void setKeepalive(boolean b)
Set the keepalive value for this WebConnection, Can only be turned off.

Parameters:
b - the new keepalive value.

getKeepalive

public boolean getKeepalive()
Get the keepalive value of this WebConnection.

Returns:
true if this WebConnection may be reused.

setReleased

public void setReleased()
Mark this WebConnection as released at current time.


getReleasedAt

public long getReleasedAt()
Get the time that this WebConnection was released.

Returns:
the time this WebConnection was last released.

setMayPipeline

public void setMayPipeline(boolean b)
Mark this WebConnection for pipelining.

Parameters:
b - if true this connection may be used for pipelining.

mayPipeline

public boolean mayPipeline()
Check if this WebConnection may be used for pipelining.

Returns:
true if this connection may be used for pipelining