com.radekzitek.userver
Class HandlerThread

java.lang.Object
  extended bycom.radekzitek.userver.HandlerThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
DumpHandler, EchoHandler, HttpProxyHandler

public abstract class HandlerThread
extends java.lang.Object
implements java.lang.Runnable

Handler thread is a base class for handler implementation.

Author:
rzitek

Field Summary
protected  java.net.Socket client
          The socket of the connected client.
private  HandlerPool hp
          Handler pool managing this handler.
private  java.lang.String id
          Unique id for the handler.
private static org.apache.log4j.Logger LOG
          Log4j logger.
 
Constructor Summary
HandlerThread()
           
 
Method Summary
 void handle(java.net.Socket client)
          The method called by the listener to request the handler to handle the client socket connection.
protected abstract  void localRun()
          The prototype for the localRun of the implementing class.
 void registerHandlerPool(HandlerPool hp)
          Called by the HandlerPool after the new thread is created to make sure the threat knows where to return itself.
 void run()
          The actuall thread execution method.
 void setId(java.lang.String id)
          Used to set the unique id.
 
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.


client

protected java.net.Socket client
The socket of the connected client.


hp

private HandlerPool hp
Handler pool managing this handler.


id

private java.lang.String id
Unique id for the handler.

Constructor Detail

HandlerThread

public HandlerThread()
Method Detail

registerHandlerPool

public void registerHandlerPool(HandlerPool hp)
Called by the HandlerPool after the new thread is created to make sure the threat knows where to return itself.

Parameters:
hp - the handler pool managing this handler

setId

public void setId(java.lang.String id)
Used to set the unique id. Done by the HandlerPool after the new thread is created.

Parameters:
id - the id

run

public void run()
The actuall thread execution method. All it does is call the localRun of the implementing class and deals with the potential exception thrown by this method.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

localRun

protected abstract void localRun()
                          throws HandlerThreadException
The prototype for the localRun of the implementing class. This method provides the actual handling functionality. This method must deal with any exception encountered or it has to propagate it up as a HandlerThreadException.

Throws:
HandlerThreadException - Thrown by the implementing class in case it encounter any unforeseen troubl.

handle

public void handle(java.net.Socket client)
The method called by the listener to request the handler to handle the client socket connection.

Parameters:
client - the client socket