Socket HTTP Listener.
The behaviour of the listener can be controlled with the
attributues of the ThreadedServer and ThreadPool from which it is
derived. Specifically:
MinThreads - Minumum threads waiting to service requests.
MaxThread - Maximum thread that will service requests.
MaxIdleTimeMs - Time for an idle thread to wait for a request or read.
LowResourcePersistTimeMs - time in ms that connections will persist if listener is
low on resources.
createConnection
protected HttpConnection createConnection(Socket socket)
throws IOException
Create an HttpConnection instance. This method can be used to
override the connection instance.
socket
- The underlying socket.
customizeRequest
protected void customizeRequest(Socket socket,
HttpRequest request)
Customize request from socket.
Derived versions of SocketListener may specialize this method
to customize the request with attributes of the socket used (eg
SSL session ids).
This version resets the SoTimeout if it has been reduced due to
low resources. Derived implementations should call
super.customizeRequest(socket,request) unless persistConnection
has also been overridden and not called.
customizeRequest
public void customizeRequest(HttpConnection connection,
HttpRequest request)
Customize the request from connection.
This method extracts the socket from the connection and calls
the customizeRequest(Socket,HttpRequest) method.
- customizeRequest in interface HttpListener
getIdentifyListener
public boolean getIdentifyListener()
getLowResourcePersistTimeMs
public int getLowResourcePersistTimeMs()
- time in ms that connections will persist if listener is
low on resources.
getLowResources
public int getLowResources()
- Returns the lowResources threshold
handleConnection
public void handleConnection(Socket socket)
throws IOException
Handle Job.
Implementation of ThreadPool.handle(), calls handleConnection.
- handleConnection in interface ThreadedServer
isLowOnResources
public boolean isLowOnResources()
Get the lowOnResource state of the listener.
A SocketListener is considered low on resources if the total number of
the number of idle threads is less than the lowResource value (or minThreads if not set)
- isLowOnResources in interface HttpListener
- True if low on idle threads.
isOutOfResources
public boolean isOutOfResources()
Get the outOfResource state of the listener.
A SocketListener is considered out of resources if the total number of
threads is maxThreads and the number of idle threads is zero.
- isOutOfResources in interface HttpListener
- True if out of resources.
persistConnection
public void persistConnection(HttpConnection connection)
Persist the connection.
This method is called by the HttpConnection in order to prepare a
connection to be persisted. For this implementation,
if the listener is low on resources, the connection read
timeout is set to lowResourcePersistTimeMs. The
customizeRequest method is used to reset this to the normal
value after a request has been read.
- persistConnection in interface HttpListener
connection
- The HttpConnection to use.
setBufferReserve
public void setBufferReserve(int size)
setBufferSize
public void setBufferSize(int size)
setConfidentialPort
public void setConfidentialPort(int confidentialPort)
setConfidentialScheme
public void setConfidentialScheme(String confidentialScheme)
setDefaultScheme
public void setDefaultScheme(String scheme)
setHttpHandler
public void setHttpHandler(HttpHandler handler)
setIdentifyListener
public void setIdentifyListener(boolean identifyListener)
identifyListener
- If true, the listener name is added to all
requests as the org.mortbay.http.HttListener attribute
setIntegralPort
public void setIntegralPort(int integralPort)
setIntegralScheme
public void setIntegralScheme(String integralScheme)
setLowResourcePersistTimeMs
public void setLowResourcePersistTimeMs(int ms)
Set the low resource persistace time.
When the listener is low on resources, this timeout is used for idle
persistent connections. It is desirable to have this set to a short
period of time so that idle persistent connections do not consume
resources on a busy server.
ms
- time in ms that connections will persist if listener is
low on resources.
setLowResources
public void setLowResources(int lowResources)
lowResources
- The number of idle threads needed to not be in
low resources state.