org.tranche.httpd
Class Httpd

java.lang.Object
  extended by java.lang.Thread
      extended by org.tranche.httpd.Httpd
All Implemented Interfaces:
java.lang.Runnable

public class Httpd
extends java.lang.Thread

The httpd thread configures the server socket and the queue and waits for connections. Upon reception it adds the connecting socket to a queue where it will be serviced by and AbstractHttpHandler object.

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
 
Constructor Summary
Httpd(int port, int backLog, int queueLength, int minNumThreads, int maxNumThreads)
          Constructor
 
Method Summary
 void finilize()
          If this object is destroyed shutdowns and connections that are still open.
 int getPort()
          Getter method for the port attribute.
 void run()
          Implementation of the run method of the Thread.
 void setTimeout(int timeout)
          Setter for the timeout of any open connections
 boolean startServer()
          All the work for starting up the server is done here.
 void stopServer()
          Method for stopping the server.
 
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

Httpd

public Httpd(int port,
             int backLog,
             int queueLength,
             int minNumThreads,
             int maxNumThreads)
Constructor

Parameters:
port - The port to setup the server socket
backLog - The size of connection to be managed by the server socket itself
queueLength - The max size of the Queue
minNumThreads - The min number of SocketHandling threads active
maxNumThreads - The max number of SocketHandling threads active
Method Detail

finilize

public void finilize()
If this object is destroyed shutdowns and connections that are still open.


setTimeout

public void setTimeout(int timeout)
Setter for the timeout of any open connections

Parameters:
timeout -

startServer

public boolean startServer()
All the work for starting up the server is done here. A server socket is created that listens to a port and backlog.

Returns:

run

public void run()
Implementation of the run method of the Thread. As long as the isRunning flag is true the server will wait for a connection and add it to the queue of connections for further handling.

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

stopServer

public void stopServer()
Method for stopping the server. Sets the isRunning flag to false and closes the connections.


getPort

public int getPort()
Getter method for the port attribute.

Returns:
the port number


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