org.mortbay.http

Class SocketListener

Implemented Interfaces:
HttpListener, LifeCycle, Serializable
Known Direct Subclasses:
HostSocketListener, JsseListener, SslListener

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.38 2005/08/13 00:01:24 gregwilkins Exp $
Author:
Greg Wilkins (gregw)

Nested Class Summary

Nested classes/interfaces inherited from class org.mortbay.util.ThreadPool

ThreadPool.PoolThread

Field Summary

Fields inherited from class org.mortbay.util.ThreadPool

__DAEMON, __PRIORITY

Fields inherited from interface org.mortbay.http.HttpListener

ATTRIBUTE

Constructor Summary

SocketListener()
SocketListener(InetAddrPort address)

Method Summary

protected HttpConnection
createConnection(Socket socket)
Create an HttpConnection instance.
protected void
customizeRequest(Socket socket, HttpRequest request)
Customize request from socket.
void
customizeRequest(HttpConnection connection, HttpRequest request)
Customize the request from connection.
int
getBufferReserve()
int
getBufferSize()
int
getConfidentialPort()
String
getConfidentialScheme()
String
getDefaultScheme()
HttpHandler
getHttpHandler()
HttpServer
getHttpServer()
boolean
getIdentifyListener()
int
getIntegralPort()
String
getIntegralScheme()
int
getLowResourcePersistTimeMs()
int
getLowResources()
void
handleConnection(Socket socket)
Handle Job.
boolean
isConfidential(HttpConnection connection)
boolean
isIntegral(HttpConnection connection)
boolean
isLowOnResources()
Get the lowOnResource state of the listener.
boolean
isOutOfResources()
Get the outOfResource state of the listener.
void
persistConnection(HttpConnection connection)
Persist the connection.
void
setBufferReserve(int size)
void
setBufferSize(int size)
void
setConfidentialPort(int confidentialPort)
void
setConfidentialScheme(String confidentialScheme)
void
setDefaultScheme(String scheme)
void
setHttpHandler(HttpHandler handler)
void
setHttpServer(HttpServer server)
void
setIdentifyListener(boolean identifyListener)
void
setIntegralPort(int integralPort)
void
setIntegralScheme(String integralScheme)
void
setLowResourcePersistTimeMs(int ms)
Set the low resource persistace time.
void
setLowResources(int lowResources)
void
start()
void
stop()

Methods inherited from class org.mortbay.util.ThreadedServer

acceptSocket, acceptSocket, getAcceptQueueSize, getAcceptorThreads, getHost, getInetAddrPort, getInetAddress, getLingerTimeSecs, getMaxReadTimeMs, getPort, getServerSocket, getTcpNoDelay, handle, handleConnection, handleConnection, newServerSocket, open, setAcceptQueueSize, setAcceptorThreads, setHost, setInetAddrPort, setInetAddress, setLingerTimeSecs, setMaxReadTimeMs, setPort, setTcpNoDelay, start, stop, stopJob, toString

Methods inherited from class org.mortbay.util.ThreadPool

getIdleThreads, getMaxIdleTimeMs, getMaxThreads, getMinThreads, getName, getPoolName, getThreads, getThreadsPriority, handle, isDaemon, isStarted, join, run, setDaemon, setMaxIdleTimeMs, setMaxStopTimeMs, setMaxThreads, setMinThreads, setName, setPoolName, setThreadsPriority, shrink, start, stop, stopJob

Constructor Details

SocketListener

public SocketListener()

SocketListener

public SocketListener(InetAddrPort address)

Method Details

createConnection

protected HttpConnection createConnection(Socket socket)
            throws IOException
Create an HttpConnection instance. This method can be used to override the connection instance.
Parameters:
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.
Parameters:
request -

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.
Specified by:
customizeRequest in interface HttpListener
Parameters:
request -

getBufferReserve

public int getBufferReserve()
Specified by:
getBufferReserve in interface HttpListener

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface HttpListener

getConfidentialPort

public int getConfidentialPort()
Specified by:
getConfidentialPort in interface HttpListener

getConfidentialScheme

public String getConfidentialScheme()
Specified by:
getConfidentialScheme in interface HttpListener

getDefaultScheme

public String getDefaultScheme()
Specified by:
getDefaultScheme in interface HttpListener

getHttpHandler

public HttpHandler getHttpHandler()
Specified by:
getHttpHandler in interface HttpListener

getHttpServer

public HttpServer getHttpServer()
Specified by:
getHttpServer in interface HttpListener

getIdentifyListener

public boolean getIdentifyListener()

getIntegralPort

public int getIntegralPort()
Specified by:
getIntegralPort in interface HttpListener

getIntegralScheme

public String getIntegralScheme()
Specified by:
getIntegralScheme in interface HttpListener

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)
            throws IOException
Handle Job. Implementation of ThreadPool.handle(), calls handleConnection.
Overrides:
handleConnection in interface ThreadedServer
Parameters:
socket - A Connection.

isConfidential

public boolean isConfidential(HttpConnection connection)
Specified by:
isConfidential in interface HttpListener

isIntegral

public boolean isIntegral(HttpConnection connection)
Specified by:
isIntegral in interface HttpListener

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)
Specified by:
isLowOnResources in interface HttpListener
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.
Specified by:
isOutOfResources in interface HttpListener
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.
Specified by:
persistConnection in interface HttpListener
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)
Specified by:
setHttpServer in interface HttpListener

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()
            throws Exception
Specified by:
start in interface LifeCycle
Overrides:
start in interface ThreadedServer

stop

public void stop()
            throws InterruptedException
Specified by:
stop in interface LifeCycle
Overrides:
stop in interface ThreadedServer

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.