org.mortbay.http
Class SocketListener

java.lang.Object
  |
  +--org.mortbay.util.ThreadPool
        |
        +--org.mortbay.util.ThreadedServer
              |
              +--org.mortbay.http.SocketListener
All Implemented Interfaces:
HttpListener, LifeCycle
Direct Known Subclasses:
JsseListener

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.
 MaxReadTimeMs - Time that a read on a request can block.
 LowResourcePersistTimeMs - time in ms that connections will persist if listener is
                            low on resources. 
 

Version:
$Id: SocketListener.java,v 1.5 2001/10/11 01:17:44 gregwilkins Exp $
Author:
Greg Wilkins (gregw)

Inner classes inherited from class org.mortbay.util.ThreadPool
ThreadPool.PoolThread
 
Fields inherited from class org.mortbay.util.ThreadPool
__nullLockChecks
 
Constructor Summary
SocketListener()
           
SocketListener(InetAddrPort address)
           
 
Method Summary
 void customizeRequest(HttpConnection connection, HttpRequest request)
          Customize the request from connection.
 void destroy()
          Destroy the LifeCycle.
 java.lang.String getDefaultScheme()
           
 HttpServer getHttpServer()
           
 int getLowResourcePersistTimeMs()
           
 void handleConnection(java.net.Socket socket)
          Handle Job.
 boolean isLowOnResources()
           
 boolean isOutOfResources()
           
 void persistConnection(HttpConnection connection)
          Persist the connection If the listener is low on resources, the connection read timeout is set to lowResourcePersistTimeMs.
 void setHttpServer(HttpServer server)
           
 void setLowResourcePersistTimeMs(int ms)
           
 void start()
          Start the LifeCycle.
 void stop()
          Stop the LifeCycle.
 
Methods inherited from class org.mortbay.util.ThreadedServer
getHost, getInetAddress, getInetAddrPort, getLingerTimeSecs, getMaxReadTimeMs, getPort, getServerSocket, handle, setAddress, setHost, setInetAddress, setLingerTimeSecs, setMaxReadTimeMs, setPort, toString
 
Methods inherited from class org.mortbay.util.ThreadPool
getIdleThreads, getMaxIdleTimeMs, getMaxSize, getMaxStopTimeMs, getMaxThreads, getMinSize, getMinThreads, getName, getSize, getThreadClass, getThreads, initialize, isDestroyed, isStarted, join, run, setMaxIdleTimeMs, setMaxSize, setMaxStopTimeMs, setMaxThreads, setMinSize, setMinThreads, setName, setThreadClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mortbay.http.HttpListener
getHost, getPort, getServerSocket, setHost, setPort
 
Methods inherited from interface org.mortbay.util.LifeCycle
isDestroyed, isStarted
 

Constructor Detail

SocketListener

public SocketListener()

SocketListener

public SocketListener(InetAddrPort address)
               throws java.io.IOException
Method Detail

setHttpServer

public void setHttpServer(HttpServer server)
Specified by:
setHttpServer in interface HttpListener

getHttpServer

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

getDefaultScheme

public java.lang.String getDefaultScheme()
Specified by:
getDefaultScheme in interface HttpListener

getLowResourcePersistTimeMs

public int getLowResourcePersistTimeMs()
Returns:
time in ms that connections will persist if listener is low on resources.

setLowResourcePersistTimeMs

public void setLowResourcePersistTimeMs(int ms)
Parameters:
ms - time in ms that connections will persist if listener is low on resources.

start

public void start()
           throws java.lang.Exception
Description copied from interface: LifeCycle
Start the LifeCycle.
Specified by:
start in interface LifeCycle
Overrides:
start in class ThreadedServer
Following copied from interface: org.mortbay.util.LifeCycle
Throws:
java.lang.Exception - An arbitrary exception may be thrown.

stop

public void stop()
          throws java.lang.InterruptedException
Description copied from interface: LifeCycle
Stop the LifeCycle. The LifeCycle may wait for current activities to complete normally, but it can be interrupted.
Specified by:
stop in interface LifeCycle
Overrides:
stop in class ThreadedServer

destroy

public void destroy()
Description copied from interface: LifeCycle
Destroy the LifeCycle. Activities are terminated.
Specified by:
destroy in interface LifeCycle
Overrides:
destroy in class ThreadedServer

handleConnection

public void handleConnection(java.net.Socket socket)
                      throws java.io.IOException
Handle Job. Implementation of ThreadPool.handle(), calls handleConnection.
Parameters:
job - A Connection.

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 -  

persistConnection

public void persistConnection(HttpConnection connection)
Persist the connection 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. -  

isLowOnResources

public boolean isLowOnResources()
Specified by:
isLowOnResources in interface HttpListener
Returns:
True if low on idle threads.

isOutOfResources

public boolean isOutOfResources()
Specified by:
isOutOfResources in interface HttpListener
Returns:
True if out of resources.


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