org.mortbay.http.nio
Class SocketChannelListener

java.lang.Object
  extended byorg.mortbay.util.ThreadPool
      extended byorg.mortbay.http.nio.SocketChannelListener
All Implemented Interfaces:
HttpListener, LifeCycle, java.io.Serializable

public class SocketChannelListener
extends ThreadPool
implements HttpListener

EXPERIMENTAL NIO listener!

Version:
$Revision: 1.6 $
Author:
gregw
See Also:
Serialized Form

Nested Class Summary
 
Nested classes 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
SocketChannelListener()
          Constructor.
 
Method Summary
 void customizeRequest(HttpConnection connection, HttpRequest request)
          Customize a request for a listener/connection combination.
 int getBufferReserve()
          Get the size of the header reserve area.
 int getBufferSize()
          Get the size of the buffers used by connections from this listener.
 int getConfidentialPort()
          Get the protocol port to use for confidential redirections.
 java.lang.String getConfidentialScheme()
          Get the protocol scheme to use for confidential redirections.
 java.lang.String getDefaultScheme()
          Get the default scheme for requests.
 java.lang.String getHost()
          Get the host or IP of the interface used by this listener.
 HttpHandler getHttpHandler()
          Get an optional HttpHandler for the listener.
 HttpServer getHttpServer()
          Get the HttpServer instance for this HttpListener.
 int getIntegralPort()
          Get the protocol port to use for integral redirections.
 java.lang.String getIntegralScheme()
          Get the protocol scheme to use for integral redirections.
 int getLingerTimeSecs()
           
 int getPort()
          Get the port number of the listener.
 int getSslPort()
          get_sslPort.
 boolean isConfidential(HttpConnection connection)
          Get the confidential status of a connection.
 boolean isIntegral(HttpConnection connection)
          Get the integral status of a connection.
 boolean isLowOnResources()
          Get the low on resources state of the listener.
 boolean isOutOfResources()
          Get the out of resources state of the listener.
 void persistConnection(HttpConnection connection)
          Prepare a connection for persistance.
 void setBufferReserve(int size)
           
 void setBufferSize(int size)
           
 void setHost(java.lang.String host)
          Set the host or IP of the interface used by this listener.
 void setHttpHandler(HttpHandler handler)
           
 void setHttpServer(HttpServer server)
          Set the HttpServer instance for this HttpListener.
 void setLingerTimeSecs(int ls)
           
 void setPort(int port)
          Set the port number of the listener.
 void setSslPort(int p)
          set_sslPort.
 void start()
          Start the LifeCycle.
 void stop()
          Stop the LifeCycle.
 
Methods inherited from class org.mortbay.util.ThreadPool
getIdleThreads, getMaxIdleTimeMs, getMaxThreads, getMinThreads, getName, getPoolName, getThreads, getThreadsPriority, isDaemon, isStarted, join, run, setDaemon, setMaxIdleTimeMs, setMaxStopTimeMs, setMaxThreads, setMinThreads, setName, setPoolName, setThreadsPriority, shrink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mortbay.util.LifeCycle
isStarted
 

Constructor Detail

SocketChannelListener

public SocketChannelListener()
Constructor.

Method Detail

setHttpServer

public void setHttpServer(HttpServer server)
Description copied from interface: HttpListener
Set the HttpServer instance for this HttpListener. This method is called by the HttpServer.addListener method. It should not be called directly.

Specified by:
setHttpServer in interface HttpListener
Parameters:
server - The HttpServer instance this HttpListener has been added to.

getHttpServer

public HttpServer getHttpServer()
Description copied from interface: HttpListener
Get the HttpServer instance for this HttpListener.

Specified by:
getHttpServer in interface HttpListener
Returns:
The HttpServer instance this HttpListener has been added to, or null if the listener is not added to any HttpServer.

setHost

public void setHost(java.lang.String host)
             throws java.net.UnknownHostException
Description copied from interface: HttpListener
Set the host or IP of the interface used by this listener.

Specified by:
setHost in interface HttpListener
Parameters:
host - The hostname or IP address of the interface used by this listeners. If null or "0.0.0.0" then all available interfaces are used by this listener.
Throws:
java.net.UnknownHostException
See Also:
HttpListener.setHost(java.lang.String)

getHost

public java.lang.String getHost()
Description copied from interface: HttpListener
Get the host or IP of the interface used by this listener.

Specified by:
getHost in interface HttpListener
Returns:
The hostname or IP address of the interface used by this listeners. If null or "0.0.0.0" then all available interfaces are used by this listener.

setPort

public void setPort(int port)
Description copied from interface: HttpListener
Set the port number of the listener.

Specified by:
setPort in interface HttpListener
Parameters:
port - The TCP/IP port number to be used by this listener.

getPort

public int getPort()
Description copied from interface: HttpListener
Get the port number of the listener.

Specified by:
getPort in interface HttpListener
Returns:
The TCP/IP port number used by this listener.

setBufferSize

public void setBufferSize(int size)

getBufferSize

public int getBufferSize()
Description copied from interface: HttpListener
Get the size of the buffers used by connections from this listener.

Specified by:
getBufferSize in interface HttpListener
Returns:
The default buffer size in bytes.

setBufferReserve

public void setBufferReserve(int size)

getBufferReserve

public int getBufferReserve()
Description copied from interface: HttpListener
Get the size of the header reserve area. Get the size of the header reserve area within the buffers used by connections from this listener. The header reserve is space reserved in the first buffer of a response to allow a HTTP header to be written in the same packet. The reserve should be large enough to avoid moving data to fit the header, but not too large as to waste memory.

Specified by:
getBufferReserve in interface HttpListener
Returns:
The default buffer reserve size in bytes.

getDefaultScheme

public java.lang.String getDefaultScheme()
Description copied from interface: HttpListener
Get the default scheme for requests. If a request is received from a HttpConnection created by this listener, that does not include a scheme in it's request URL, then this method is used to determine the protocol scheme most likely used to connect to this listener.

Specified by:
getDefaultScheme in interface HttpListener
Returns:
The protocol scheme name (eg "http" or "https").

customizeRequest

public void customizeRequest(HttpConnection connection,
                             HttpRequest request)
Description copied from interface: HttpListener
Customize a request for a listener/connection combination. This method is called by HttpConnection after a request has been read from that connection and before processing that request. Implementations may use this callback to add additional listener and/or connection specific attributes to the request (eg SSL attributes).

Specified by:
customizeRequest in interface HttpListener
Parameters:
connection - The connection the request was received on, which must be a HttpConnection created by this listener.
request - The request to customize.

persistConnection

public void persistConnection(HttpConnection connection)
Description copied from interface: HttpListener
Prepare a connection for persistance. This method is called by the HttpConnection on a persistent connection after each request has been handled and before starting to read for the next connection. Implementations may use this callback to change the parameters or scheduling of the connection.

Specified by:
persistConnection in interface HttpListener
Parameters:
connection - The perstent connection, which must be a HttpConnection created by this listener.

isLowOnResources

public boolean isLowOnResources()
Description copied from interface: HttpListener
Get the low on resources state of the listener. For most implementations, Threads are the resource reported on by this method.

Specified by:
isLowOnResources in interface HttpListener
Returns:
True if the listener is out of resources.

isOutOfResources

public boolean isOutOfResources()
Description copied from interface: HttpListener
Get the out of resources state of the listener. For most implementations, Threads are the resource reported on by this method.

Specified by:
isOutOfResources in interface HttpListener
Returns:
True if the listener is out of resources.

getSslPort

public int getSslPort()
get_sslPort.

Returns:
Port to redirect integral and confidential requests to.

setSslPort

public void setSslPort(int p)
set_sslPort.

Parameters:
p - Port to redirect integral and confidential requests to.

isIntegral

public boolean isIntegral(HttpConnection connection)
Description copied from interface: HttpListener
Get the integral status of a connection.

Specified by:
isIntegral in interface HttpListener
Parameters:
connection - The connection to test.
Returns:
True of the connection checks the integrity of the data. For most implementations this is true for https connections.

getIntegralScheme

public java.lang.String getIntegralScheme()
Description copied from interface: HttpListener
Get the protocol scheme to use for integral redirections. If an INTEGRAL security constraint is not met for a request, the request is redirected to an integral port. This scheme return by this method is used for that redirection.

Specified by:
getIntegralScheme in interface HttpListener
Returns:
The integral scheme. For most implementations this is "https"

getIntegralPort

public int getIntegralPort()
Description copied from interface: HttpListener
Get the protocol port to use for integral redirections. If an INTEGRAL security constraint is not met for a request, the request is redirected to an integral port. This port return by this method is used for that redirection.

Specified by:
getIntegralPort in interface HttpListener
Returns:
The integral port. For most implementations this is 443 for https

isConfidential

public boolean isConfidential(HttpConnection connection)
Description copied from interface: HttpListener
Get the confidential status of a connection.

Specified by:
isConfidential in interface HttpListener
Parameters:
connection - The connection to test.
Returns:
True of the connection checks the integrity of the data. For most implementations this is true for https connections.

getConfidentialScheme

public java.lang.String getConfidentialScheme()
Description copied from interface: HttpListener
Get the protocol scheme to use for confidential redirections. If an CONFIDENTIAL security constraint is not met for a request, the request is redirected to an confidential port. This scheme return by this method is used for that redirection.

Specified by:
getConfidentialScheme in interface HttpListener
Returns:
The confidential scheme. For most implementations this is "https"

getConfidentialPort

public int getConfidentialPort()
Description copied from interface: HttpListener
Get the protocol port to use for confidential redirections. If an CONFIDENTIAL security constraint is not met for a request, the request is redirected to an confidential port. This port return by this method is used for that redirection.

Specified by:
getConfidentialPort in interface HttpListener
Returns:
The confidential port. For most implementations this is 443 for https

setLingerTimeSecs

public void setLingerTimeSecs(int ls)

getLingerTimeSecs

public int getLingerTimeSecs()
Returns:
seconds.

setHttpHandler

public void setHttpHandler(HttpHandler handler)

getHttpHandler

public HttpHandler getHttpHandler()
Description copied from interface: HttpListener
Get an optional HttpHandler for the listener. If Set, then HttpConnection will pass requests from this listener to this handler with an empty context path, before passing the request to the HttpServer. This allows listener specific handling to be added or even a HttpContext (which is a HttpHandler) to be bound directly to HttpListener.

Specified by:
getHttpHandler in interface HttpListener
See Also:
HttpListener.getHttpHandler()

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 ThreadPool
Throws:
java.lang.Exception

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 ThreadPool
Throws:
java.lang.InterruptedException


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