marquee.xmlrpc
Class XmlRpcServerConnection

java.lang.Object
  extended by java.lang.Thread
      extended by marquee.xmlrpc.XmlRpcServerConnection
All Implemented Interfaces:
java.lang.Runnable

public class XmlRpcServerConnection
extends java.lang.Thread

Handles a connection to a client in a separate thread. The XmlRpcServerConnection threads are pooled to increase performance.

Since:
JDK 1.1
Version:
$Revision: 1.6 $
Author:
Greger Ohlson (greger.ohlson@marquee.se)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static byte[] CLOSE_CONNECTION
          Byte array for a Close Connection header
static byte[] CONTENT_LENGTH
          Byte array for the Content Length header
static byte[] CONTENT_TYPE
          Byte array for the Content Type header
static byte[] CRLF
          Byte array for the end of HTTP headers mark
static byte[] ERROR
          Byte array for an HTTP IE header
static byte[] GZIP_ENCODING
          Byte array for the GZIP Encoding header
static byte[] KEEP_CONNECTION
          Byte array for a Keep Connection header
static byte[] OK
          Byte array for an HTTP OK header
static byte[] SERVER
          Byte array for the server header
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
XmlRpcServerConnection()
          Marks the thread with a prefix and sequence number so we may trace which thread is doing what.
 
Method Summary
static XmlRpcServerConnection getConnection(XmlRpcDispatcher dispatcher)
          Retrieves a connection from the pool or creates a new one, assuming we have not reached the connection limit.
 void handleConnection(java.net.Socket socket)
          The thread executing the handleConnection() is the thread that is accepting connections in the XmlRpcServer.runAsService() method.
static java.lang.String readHttpHeader(java.io.InputStream is, byte[] httpBuffer)
          Reads a string from the supplied input string.
 void run()
          The XmlRpcServerConnection thread runs indefinitely, or until interrupted, handling XML-RPC messages on the socket assigned in handleConnection().
static void setLimits(int connectionLimit, int poolLimit)
          Sets the maximum allowed number of simultaneously active connections, and the number of connections that should be pooled.
 
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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OK

public static final byte[] OK
Byte array for an HTTP OK header


ERROR

public static final byte[] ERROR
Byte array for an HTTP IE header


SERVER

public static final byte[] SERVER
Byte array for the server header


CLOSE_CONNECTION

public static final byte[] CLOSE_CONNECTION
Byte array for a Close Connection header


KEEP_CONNECTION

public static final byte[] KEEP_CONNECTION
Byte array for a Keep Connection header


CONTENT_TYPE

public static final byte[] CONTENT_TYPE
Byte array for the Content Type header


GZIP_ENCODING

public static final byte[] GZIP_ENCODING
Byte array for the GZIP Encoding header


CONTENT_LENGTH

public static final byte[] CONTENT_LENGTH
Byte array for the Content Length header


CRLF

public static final byte[] CRLF
Byte array for the end of HTTP headers mark

Constructor Detail

XmlRpcServerConnection

public XmlRpcServerConnection()
Marks the thread with a prefix and sequence number so we may trace which thread is doing what.

Method Detail

getConnection

public static XmlRpcServerConnection getConnection(XmlRpcDispatcher dispatcher)
Retrieves a connection from the pool or creates a new one, assuming we have not reached the connection limit.

Parameters:
dispatcher - The dispatcher this connection shall use when the HTTP information ha been extracted from the call.
Returns:
An XmlRpcServerConnection to handle the call, or null, if no connection is available.

setLimits

public static void setLimits(int connectionLimit,
                             int poolLimit)
Sets the maximum allowed number of simultaneously active connections, and the number of connections that should be pooled. That is, the Connection class will handle up to number of simultaneous connections, but will only put number of connections back into the pool. This allows the Connection class to handle a higher number of connections at increased load but limiting the number of allocated threads at low/normal load.

Lowering the connection limit or pool limit during operation will not immediately affect the number of connections or connections in the pool. They will be decreased as requests are handled and connections are disposed after those requests.

Parameters:
connectionLimit - The maximum allowed number of active connections
poolLimit - The number of connections to pool

handleConnection

public void handleConnection(java.net.Socket socket)
The thread executing the handleConnection() is the thread that is accepting connections in the XmlRpcServer.runAsService() method. This thread sets the socket of this object (which is also a thread) and then notifies this object that there is work to do. The calling thread returns to handle new inbound calls. The notified thread continues working on the the supplied socket.

Parameters:
socket - The socket containing the XML-RPC post to be handled.

run

public void run()
The XmlRpcServerConnection thread runs indefinitely, or until interrupted, handling XML-RPC messages on the socket assigned in handleConnection(). The acquireSocket() call hangs until there is a socket available to work with or until the thread is interrupted.

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

readHttpHeader

public static java.lang.String readHttpHeader(java.io.InputStream is,
                                              byte[] httpBuffer)
                                       throws java.io.IOException
Reads a string from the supplied input string. This method is only used internally by the run() method and converts uppercase letters to lowercase. This way we don't have to use String.toLowerCase() when examining the HTTP headers resulting in additional string objects.

Parameters:
is - The input stream to read an HTTP header from
Returns:
The lowercase version of the HTTP header.
Throws:
java.io.IOException