com.radekzitek.userver
Class HandlerPool

java.lang.Object
  extended bycom.radekzitek.userver.HandlerPool

public class HandlerPool
extends java.lang.Object

HandlerPool is used to manage pools of the various handlers used in the run time. The HandlerPool maintains two vectors for each class of handler - pool vector with available handlers and active vector with handlers which were provided to the listeners to serve the clients.

Author:
rzitek

Field Summary
(package private)  java.util.Hashtable classActives
          Table with the active vectors for all the classes.
(package private)  java.util.Hashtable classPools
          Table with the pool vectors for all the classes.
private static int idNumber
          Static field used to for unique id of the created handlers.
private static org.apache.log4j.Logger LOG
          Log4j logger.
 
Constructor Summary
HandlerPool()
          Constructor for the HandlerPool.
 
Method Summary
private  java.util.Vector getClassActive(java.lang.Class handlerClass)
          Provides the active vector for the given class.
private  java.util.Vector getClassPool(java.lang.Class handlerClass)
          Provides the pool vector for the given class.
 HandlerThread getHandler(java.lang.Class handlerClass)
          Provides handler of the given class to the listener.
 void returnHandler(HandlerThread handler)
          Returns the handler into the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final org.apache.log4j.Logger LOG
Log4j logger.


idNumber

private static int idNumber
Static field used to for unique id of the created handlers.


classPools

java.util.Hashtable classPools
Table with the pool vectors for all the classes. The class is the key to the table. The element in the table is the pool vector.


classActives

java.util.Hashtable classActives
Table with the active vectors for all the classes. The class is the key to the table. The element in the table is the active vector.

Constructor Detail

HandlerPool

public HandlerPool()
Constructor for the HandlerPool. It only initializes the two tables used to store the pool and active vectors.

Method Detail

getHandler

public HandlerThread getHandler(java.lang.Class handlerClass)
                         throws java.lang.InstantiationException,
                                java.lang.IllegalAccessException
Provides handler of the given class to the listener. If there is available handler in the pool of the given class this handler is returned. If there is no available handler in the pool new handler is created. When the new handler is created this method takes care of registering the HandlerPool with the new handler so the handler can return itself to the pool. The handler returned is always included in the active vector for the given class.

Parameters:
handlerClass - the class of the handler to be provided
Returns:
new handler for the job
Throws:
java.lang.IllegalAccessException - Thrown when the new handler can not be instantiated.
java.lang.InstantiationException - Thrown when the new handler can not be instantiated.

getClassPool

private java.util.Vector getClassPool(java.lang.Class handlerClass)
Provides the pool vector for the given class.

Parameters:
handlerClass - the class for which the pool vector is needed
Returns:
the pool vector for the given class

getClassActive

private java.util.Vector getClassActive(java.lang.Class handlerClass)
Provides the active vector for the given class.

Parameters:
handlerClass - the class for which the active vector is needed
Returns:
the active vector for the given class

returnHandler

public void returnHandler(HandlerThread handler)
Returns the handler into the pool. The handler is removed from the active vector and returned to the pool verctor. All for the given class obviously.

Parameters:
handler - the handler to be returned