org.mortbay.http

Class SocketListener

public class SocketListener extends ThreadedServer implements HttpListener

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. 
 

Version: $Id: SocketListener.java,v 1.39 2006/02/27 13:03:50 gregwilkins Exp $

Author: Greg Wilkins (gregw)

Constructor Summary
SocketListener()
SocketListener(InetAddrPort address)
Method Summary
protected HttpConnectioncreateConnection(Socket socket)
Create an HttpConnection instance.
voidcustomizeRequest(HttpConnection connection, HttpRequest request)
Customize the request from connection.
protected voidcustomizeRequest(Socket socket, HttpRequest request)
Customize request from socket.
intgetBufferReserve()
intgetBufferSize()
intgetConfidentialPort()
StringgetConfidentialScheme()
StringgetDefaultScheme()
HttpHandlergetHttpHandler()
HttpServergetHttpServer()
booleangetIdentifyListener()
intgetIntegralPort()
StringgetIntegralScheme()
intgetLowResourcePersistTimeMs()
intgetLowResources()
voidhandleConnection(Socket socket)
Handle Job.
booleanisConfidential(HttpConnection connection)
booleanisIntegral(HttpConnection connection)
booleanisLowOnResources()
Get the lowOnResource state of the listener.
booleanisOutOfResources()
Get the outOfResource state of the listener.
voidpersistConnection(HttpConnection connection)
Persist the connection.
voidsetBufferReserve(int size)
voidsetBufferSize(int size)
voidsetConfidentialPort(int confidentialPort)
voidsetConfidentialScheme(String confidentialScheme)
voidsetDefaultScheme(String scheme)
voidsetHttpHandler(HttpHandler handler)
voidsetHttpServer(HttpServer server)
voidsetIdentifyListener(boolean identifyListener)
voidsetIntegralPort(int integralPort)
voidsetIntegralScheme(String integralScheme)
voidsetLowResourcePersistTimeMs(int ms)
Set the low resource persistace time.
voidsetLowResources(int lowResources)
voidstart()
voidstop()

Constructor Detail

SocketListener

public SocketListener()

SocketListener

public SocketListener(InetAddrPort address)

Method Detail

createConnection

protected HttpConnection createConnection(Socket socket)
Create an HttpConnection instance. This method can be used to override the connection instance.

Parameters: socket The underlying socket.

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.

Parameters: request

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.

Parameters: request

getBufferReserve

public int getBufferReserve()

getBufferSize

public int getBufferSize()

getConfidentialPort

public int getConfidentialPort()

getConfidentialScheme

public String getConfidentialScheme()

getDefaultScheme

public String getDefaultScheme()

getHttpHandler

public HttpHandler getHttpHandler()

getHttpServer

public HttpServer getHttpServer()

getIdentifyListener

public boolean getIdentifyListener()

getIntegralPort

public int getIntegralPort()

getIntegralScheme

public String getIntegralScheme()

getLowResourcePersistTimeMs

public int getLowResourcePersistTimeMs()

Returns: time in ms that connections will persist if listener is low on resources.

getLowResources

public int getLowResources()

Returns: Returns the lowResources threshold

handleConnection

public void handleConnection(Socket socket)
Handle Job. Implementation of ThreadPool.handle(), calls handleConnection.

Parameters: socket A Connection.

isConfidential

public boolean isConfidential(HttpConnection connection)

isIntegral

public boolean isIntegral(HttpConnection connection)

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)

Returns: 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.

Returns: 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.

Parameters: 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)

setHttpServer

public void setHttpServer(HttpServer server)

setIdentifyListener

public void setIdentifyListener(boolean identifyListener)

Parameters: 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.

Parameters: ms time in ms that connections will persist if listener is low on resources.

setLowResources

public void setLowResources(int lowResources)

Parameters: lowResources The number of idle threads needed to not be in low resources state.

start

public void start()

stop

public void stop()
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.