org.tranche.httpd
Class SocketHandler

java.lang.Object
  extended by java.lang.Thread
      extended by org.tranche.httpd.SocketHandler
All Implemented Interfaces:
java.lang.Runnable, IFileResources

public class SocketHandler
extends java.lang.Thread
implements IFileResources

This class services the next socket from the queue. From the HTTP request it looksup the appropriate AbstractHttpHandler. It then initializes the state of the handler. Currently on HTTP-GET is supported.

Author:
TPapoulias

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static boolean DEBUG
          Debug flag reserved for midium level of stdout vebrocity.
static boolean DEBUG_VERBOSE
          Debug flag reserver for a higher level of stdout vebrocity.
static boolean ECHO
          Flag for debugging an input stream.
static int READ_AHEAD
          Size to be used in marking an input stream.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface org.tranche.httpd.IFileResources
HTTP_PAGE_DIRECTORY, HTTP_PROPERTIES_DIRECTORY, HTTP_RESPONSE_MESSAGES_PROP_FILE, LOCALE
 
Constructor Summary
SocketHandler(Queue queue, int threadNumber)
          Constructor
 
Method Summary
 void dropConnection()
          Cleans up any streams to the sockets and sets the working state to false.
 void finilize()
          Drops connections if this object is about to be deleted.
 boolean isWorking()
          Getter method for isWorking attribute.
 void killThread()
          Sets the isRunning variable to false.
 void run()
          The main loop of this thread is acomplished.
protected  void sendError(HttpConstant errorNumber, java.lang.String errorDetails)
          Helper method for reporting any errors.
 
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

DEBUG

public static final boolean DEBUG
Debug flag reserved for midium level of stdout vebrocity.

See Also:
Constant Field Values

DEBUG_VERBOSE

public static final boolean DEBUG_VERBOSE
Debug flag reserver for a higher level of stdout vebrocity.

See Also:
Constant Field Values

ECHO

public static final boolean ECHO
Flag for debugging an input stream. Usually used to activate a block of code that marks an input stream.

See Also:
Constant Field Values

READ_AHEAD

public static final int READ_AHEAD
Size to be used in marking an input stream.

See Also:
Constant Field Values
Constructor Detail

SocketHandler

public SocketHandler(Queue queue,
                     int threadNumber)
Constructor

Parameters:
queue - Reference to the queue to look for sockets to service
threadNumber - The thread number assigned by the calling object to this object
Method Detail

finilize

public void finilize()
Drops connections if this object is about to be deleted.


run

public void run()
The main loop of this thread is acomplished. The next socket from the queue is retrieved and a call to handle() is made to accomplish the request.

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

isWorking

public boolean isWorking()
Getter method for isWorking attribute. Calling objects can assess if this thread is actively handling a socket request.

Returns:

killThread

public void killThread()
Sets the isRunning variable to false. Used by calling objects to kill this thread.


dropConnection

public void dropConnection()
Cleans up any streams to the sockets and sets the working state to false.


sendError

protected void sendError(HttpConstant errorNumber,
                         java.lang.String errorDetails)
                  throws java.io.IOException
Helper method for reporting any errors. It reports errors to the browser and stderr.

Parameters:
errorNumber - The HTTP error number.
errorDetails - A description of the error
Throws:
java.io.IOException


This code is free for use both commercially and non-commercially as stated in the project's license