atg.server.tcp
Class RequestServerHandler

java.lang.Object
  extended by java.lang.Thread
      extended by atg.core.util.DictionaryThread
          extended by atg.server.tcp.RequestServerHandler
All Implemented Interfaces:
java.lang.Runnable

public class RequestServerHandler
extends atg.core.util.DictionaryThread

This is the base class for objects that handle individual requests. Subclasses should override handleRequest().


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String CLASS_VERSION
          Class version string
protected  RequestServer mServer
          The RequestServer that this belongs to
protected  boolean mShuttingDown
          Flag if we are in the process of shutting down
protected  java.net.Socket mSocket
          The Socket this should use, if a one-shot handler
protected  boolean mWaitingForClient
          Flag set to true if we are in the middle of waiting for the client.
protected  boolean mZombie
          Flag showing if this server has been killed
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
RequestServerHandler(java.lang.ThreadGroup pGroup, java.lang.String pThreadName, RequestServer pServer, java.net.Socket pSocket)
          Constructs a new RequestServerHandler that belongs to the specified RequestServer.
 
Method Summary
 long getCurrentRequestStartTime()
          Returns the time at which the request began processing
 boolean getHandlingRequest()
          Returns the flag indicating if this is currently handling a request
 long getRequestLastActivityTime()
          Returns the last time activity occurred on this request
 RequestServer getRequestServer()
          Returns the RequestServer this handler was created from
 boolean getShuttingDown()
          Returns the flag indicating if this is currently shutting down
 boolean getWaitingForClient()
          Returns true if we are in the middle of writing data to the client.
 boolean getZombie()
          Returns the flag indicating if this thread has been killed.
protected  void handlerCleanup()
          Called before this handler exits.
protected  void handleRequest(java.net.Socket pSocket)
          This is the method that actually handles the request from the specified socket.
 void killHandler()
          Kills this thread.
static void logErrorForException(java.lang.Throwable t, ApplicationLogging pLogger, boolean bSkipTopException)
          Use log error to log the exception, following the cain of container exceptions.
 void run()
          Runs this handler.
 void setCurrentRequestStartTime(long pCurrentRequestStartTime)
          Sets the time at which the request began processing
 void setHandlingRequest(boolean pHandlingRequest)
          Sets the flag indicating if this is currently handling a request
 void setRequestLastActivityTime(long pRequestLastActivityTime)
          Sets the last time activity occurred on this request
 void setShuttingDown(boolean pShuttingDown)
          Sets the flag indicating if this is currently shutting down
 void setWaitingForClient(boolean pWaitingForClient)
          Sets the flag indicating if this is currently waiting for the client.
 void setZombie(boolean pZombie)
          Sets the flag indicating if this thread has been killed.
 
Methods inherited from class atg.core.util.DictionaryThread
getDictionary, getObject, getThreadDictionary
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


mServer

protected RequestServer mServer
The RequestServer that this belongs to


mSocket

protected java.net.Socket mSocket
The Socket this should use, if a one-shot handler


mShuttingDown

protected boolean mShuttingDown
Flag if we are in the process of shutting down


mWaitingForClient

protected boolean mWaitingForClient
Flag set to true if we are in the middle of waiting for the client. Subclasses can set this flag in part for diagnostics and in part for the server monitor to know when the client is the bottleneck.


mZombie

protected boolean mZombie
Flag showing if this server has been killed

Constructor Detail

RequestServerHandler

public RequestServerHandler(java.lang.ThreadGroup pGroup,
                            java.lang.String pThreadName,
                            RequestServer pServer,
                            java.net.Socket pSocket)
Constructs a new RequestServerHandler that belongs to the specified RequestServer.

Parameters:
pGroup - the ThreadGroup to which this will belong
pThreadName - the name that should be given to this Thread
pServer - the RequestServer handling this
pSocket - the socket this should use to handle its request. If non-null, then this handler's run method should handle a single request from the socket and exist. If null, then the handler's run method should repeatedly obtain sockets and handle requests from the server by calling "acceptConnection".
Method Detail

getRequestServer

public RequestServer getRequestServer()
Returns the RequestServer this handler was created from


run

public void run()
Runs this handler. The handler will repeatedly wait for requests, then handle those requests by calling handleRequest.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

handleRequest

protected void handleRequest(java.net.Socket pSocket)
This is the method that actually handles the request from the specified socket. Subclasses may override this method to handle the request as they see fit.

Note for subclasses overriding handleRequest(). You must check the mShuttingDown field if you enter into an inner loop. Otherwize the RequestServer may be forced during shutdown to kill your thread even while you are handling a request.


killHandler

public void killHandler()
Kills this thread.


getHandlingRequest

public boolean getHandlingRequest()
Returns the flag indicating if this is currently handling a request


setHandlingRequest

public void setHandlingRequest(boolean pHandlingRequest)
Sets the flag indicating if this is currently handling a request


getShuttingDown

public boolean getShuttingDown()
Returns the flag indicating if this is currently shutting down


setShuttingDown

public void setShuttingDown(boolean pShuttingDown)
Sets the flag indicating if this is currently shutting down


getZombie

public boolean getZombie()
Returns the flag indicating if this thread has been killed.


setZombie

public void setZombie(boolean pZombie)
Sets the flag indicating if this thread has been killed.


getWaitingForClient

public boolean getWaitingForClient()
Returns true if we are in the middle of writing data to the client.


setWaitingForClient

public void setWaitingForClient(boolean pWaitingForClient)
Sets the flag indicating if this is currently waiting for the client. This affects the server monitor and is a useful statistics for diagnostic purposes. It must be set by the specific subclass of RequestServer for it to have any effect.


getCurrentRequestStartTime

public long getCurrentRequestStartTime()
Returns the time at which the request began processing


setCurrentRequestStartTime

public void setCurrentRequestStartTime(long pCurrentRequestStartTime)
Sets the time at which the request began processing


getRequestLastActivityTime

public long getRequestLastActivityTime()
Returns the last time activity occurred on this request


setRequestLastActivityTime

public void setRequestLastActivityTime(long pRequestLastActivityTime)
Sets the last time activity occurred on this request


handlerCleanup

protected void handlerCleanup()
Called before this handler exits.


logErrorForException

public static void logErrorForException(java.lang.Throwable t,
                                        ApplicationLogging pLogger,
                                        boolean bSkipTopException)
Use log error to log the exception, following the cain of container exceptions.