rabbit.io
Class ConnectionHandler

java.lang.Object
  extended byjava.lang.Thread
      extended byrabbit.io.ConnectionHandler
All Implemented Interfaces:
java.lang.Runnable

public class ConnectionHandler
extends java.lang.Thread

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


Nested Class Summary
 class ConnectionHandler.Address
          A class to handle the addresses of the connections.
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ConnectionHandler()
          Create a new ConnectionHandler for use.
 
Method Summary
 java.util.Enumeration getAddresses()
          Get the addresses we have connections to.
 WebConnection getConnection(HTTPHeader header)
          Get a WebConnection for the given header.
 java.util.Enumeration getConnections()
          Get the connections keept.
 long getKeepaliveTime()
          Get the current keep alive time.
 java.util.Vector getPool(ConnectionHandler.Address a)
          Get the pool for an Address.
 boolean isCleanerRunning()
          Check if the cleaner of this ConnectionHandler is running.
static void main(java.lang.String[] args)
          Simple self test.
 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(java.util.Properties config)
          Configure the connection handler system from the given config.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionHandler

public ConnectionHandler()
Create a new ConnectionHandler for use.

Method Detail

isCleanerRunning

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


getConnections

public java.util.Enumeration getConnections()
Get the connections keept.

Returns:
an Enumeration of Vectors with WebConnections.

getAddresses

public java.util.Enumeration getAddresses()
Get the addresses we have connections to.


getPool

public java.util.Vector getPool(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.

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.


main

public static void main(java.lang.String[] args)
Simple self test.


setup

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

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