rabbit.io
Class ConnectionHandler

java.lang.Object
  extended by rabbit.io.ConnectionHandler
All Implemented Interfaces:
java.lang.Runnable

public class ConnectionHandler
extends java.lang.Object
implements java.lang.Runnable

A class to handle the connections to the net. Should reuse connections if possible.


Nested Class Summary
static class ConnectionHandler.Address
          A class to handle the addresses of the connections.
 
Constructor Summary
ConnectionHandler(Logger logger, Counter counter, Resolver resolver, NLSOHandler nlsoHandler)
          Create a new ConnectionHandler for use.
 
Method Summary
 java.util.Iterator<ConnectionHandler.Address> getAddresses()
          Get the addresses we have connections to.
 WebConnection getConnection(HTTPHeader header)
          Get a WebConnection for the given header.
 long getKeepaliveTime()
          Get the current keep alive time.
 java.util.Iterator<ConnectionHandler.Address> getPipelineAddresses()
          Get the pipeline address we have.
 java.util.List<WebConnection> getPipelinePool(ConnectionHandler.Address a)
          Get the pool for an Address.
 java.util.List<WebConnection> getPool(ConnectionHandler.Address a)
          Get the pool for an Address.
 boolean isCleanerRunning()
          Check if the cleaner of this ConnectionHandler is running.
 void markForPipelining(WebConnection wc)
          Mark a WebConnection ready for pipelining.
 void releaseConnection(WebConnection wc)
          Return a WebConnection to the pool so that it may be reused.
 void run()
          The cleaner thread.
 void setKeepaliveTime(long milis)
          Set the keep alive time for this handler.
 void setup(SProperties config)
          Configure the connection handler system from the given config.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionHandler

public ConnectionHandler(Logger logger,
                         Counter counter,
                         Resolver resolver,
                         NLSOHandler nlsoHandler)
                  throws java.io.IOException
Create a new ConnectionHandler for use.

Throws:
java.io.IOException
Method Detail

isCleanerRunning

public boolean isCleanerRunning()
Check if the cleaner of this ConnectionHandler is running.


getAddresses

public java.util.Iterator<ConnectionHandler.Address> getAddresses()
Get the addresses we have connections to.


getPipelineAddresses

public java.util.Iterator<ConnectionHandler.Address> getPipelineAddresses()
Get the pipeline address we have.


getPool

public java.util.List<WebConnection> getPool(ConnectionHandler.Address a)
Get the pool for an Address. NOTE! synchronize on the pool if you are taking connections from it.


getPipelinePool

public java.util.List<WebConnection> getPipelinePool(ConnectionHandler.Address a)
Get the pool for an Address. NOTE! synchronize on the pool if you are taking connections from it.


getConnection

public WebConnection getConnection(HTTPHeader header)
                            throws java.io.IOException
Get a WebConnection for the given header.

Parameters:
header - the HTTPHeader containing the URL to connect to.
Returns:
a WebConnection.
Throws:
java.io.IOException

releaseConnection

public void releaseConnection(WebConnection wc)
Return a WebConnection to the pool so that it may be reused.

Parameters:
wc - the WebConnection to return.

markForPipelining

public void markForPipelining(WebConnection wc)
Mark a WebConnection ready for pipelining.

Parameters:
wc - the WebConnection to mark ready for pipelining.

setKeepaliveTime

public void setKeepaliveTime(long milis)
Set the keep alive time for this handler.

Parameters:
milis - the keep alive time in miliseconds.

getKeepaliveTime

public long getKeepaliveTime()
Get the current keep alive time.

Returns:
the keep alive time in miliseconds.

run

public void run()
The cleaner thread.

Specified by:
run in interface java.lang.Runnable

setup

public void setup(SProperties config)
           throws IllegalConfigurationException
Configure the connection handler system from the given config.

Parameters:
config - the properties describing the cache settings.
Throws:
IllegalConfigurationException - if some setting is strange.