org.mortbay.jetty.nio
Class SelectChannelConnector

java.lang.Object
  extended byorg.mortbay.component.AbstractLifeCycle
      extended byorg.mortbay.jetty.AbstractConnector
          extended byorg.mortbay.jetty.nio.AbstractNIOConnector
              extended byorg.mortbay.jetty.nio.SelectChannelConnector
All Implemented Interfaces:
Buffers, Connector, LifeCycle, NIOConnector

public class SelectChannelConnector
extends AbstractNIOConnector

Selecting NIO connector.

This connector uses efficient NIO buffers with a non blocking threading model. Direct NIO buffers are used and threads are only allocated to connections with requests. Synchronization is used to simulate blocking for the servlet API, and any unflushed content at the end of request handling is written asynchronously.

This connector is best used when there are a many connections that have idle periods.

When used with Continuation, threadless waits are supported. When a filter or servlet calls getEvent on a Continuation, a RetryRequest runtime exception is thrown to allow the thread to exit the current request handling. Jetty will catch this exception and will not send a response to the client. Instead the thread is released and the Continuation is placed on the timer queue. If the Continuation timeout expires, or it's resume method is called, then the request is again allocated a thread and the request is retried. The limitation of this approach is that request content is not available on the retried request, thus if possible it should be read after the continuation or saved as a request attribute or as the associated object of the Continuation instance.

Author:
gregw

Nested Class Summary
static class SelectChannelConnector.RetryContinuation
           
static class SelectChannelConnector.SelectChannelEndPoint
           
 class SelectChannelConnector.SelectSet
           
 
Field Summary
 
Fields inherited from class org.mortbay.jetty.AbstractConnector
_lowResourceMaxIdleTime, _maxIdleTime, _soLingerTime
 
Constructor Summary
SelectChannelConnector()
          Constructor.
 
Method Summary
 void accept(int acceptorID)
           
 void close()
           
 void customize(EndPoint endpoint, Request request)
          Customize a request for an endpoint.
protected  void doStart()
           
protected  void doStop()
           
 Object getConnection()
           
 boolean getDelaySelectKeyUpdate()
          Assume Short Dispatch If true, the select set is not updated when a endpoint is dispatched for reading.
 int getLocalPort()
           
 Continuation newContinuation()
           
 HttpChannelEndPoint newHttpChannelEndPoint(SelectChannelConnector connector, SocketChannel channel, SelectChannelConnector.SelectSet selectSet, SelectionKey sKey)
           
 void open()
          Opens the connector
 void setDelaySelectKeyUpdate(boolean delay)
           
 
Methods inherited from class org.mortbay.jetty.nio.AbstractNIOConnector
getUseDirectBuffers, newBuffer, setUseDirectBuffers
 
Methods inherited from class org.mortbay.jetty.AbstractConnector
configure, connectionClosed, connectionOpened, getAcceptors, getAcceptQueueSize, getBuffer, getConfidentialPort, getConfidentialScheme, getConnections, getConnectionsDurationAve, getConnectionsDurationMax, getConnectionsDurationMin, getConnectionsDurationTotal, getConnectionsOpen, getConnectionsOpenMax, getConnectionsOpenMin, getConnectionsRequestsAve, getConnectionsRequestsMax, getConnectionsRequestsMin, getHeaderBufferSize, getHost, getIntegralPort, getIntegralScheme, getLowResourceMaxIdleTime, getMaxIdleTime, getName, getPort, getRequestBufferSize, getRequests, getResolveNames, getResponseBufferSize, getServer, getSoLingerTime, getStatsOn, getStatsOnMs, getThreadPool, isConfidential, isIntegral, join, returnBuffer, setAcceptors, setAcceptQueueSize, setConfidentialPort, setConfidentialScheme, setHeaderBufferSize, setHost, setIntegralPort, setIntegralScheme, setLowResourceMaxIdleTime, setMaxIdleTime, setName, setPort, setRequestBufferSize, setResolveNames, setResponseBufferSize, setServer, setSoLingerTime, setStatsOn, setThreadPool, statsReset, toString
 
Methods inherited from class org.mortbay.component.AbstractLifeCycle
isFailed, isRunning, isStarted, isStarting, isStopping, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mortbay.component.LifeCycle
isFailed, isRunning, isStarted, isStarting, isStopping, start, stop
 

Constructor Detail

SelectChannelConnector

public SelectChannelConnector()
Constructor.

Method Detail

getConnection

public Object getConnection()
Returns:
the underlying socket, channel, buffer etc. for the connector.

getDelaySelectKeyUpdate

public boolean getDelaySelectKeyUpdate()
Assume Short Dispatch If true, the select set is not updated when a endpoint is dispatched for reading. The assumption is that the task will be short and thus will probably be complete before the select is tried again.

Returns:
Returns the assumeShortDispatch.

setDelaySelectKeyUpdate

public void setDelaySelectKeyUpdate(boolean delay)
Parameters:
delay - If true, updating a SelectionKey is delayed until a redundant event is schedules. This is an optimization that assumes event handling can be completed before the next select completes.

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class AbstractConnector
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Overrides:
doStop in class AbstractConnector
Throws:
Exception

open

public void open()
          throws IOException
Description copied from interface: Connector
Opens the connector

Specified by:
open in interface Connector
Specified by:
open in class AbstractConnector
Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException

accept

public void accept(int acceptorID)
            throws IOException
Specified by:
accept in class AbstractConnector
Throws:
IOException

customize

public void customize(EndPoint endpoint,
                      Request request)
               throws IOException
Description copied from interface: Connector
Customize a request for an endpoint. Called on every request to allow customization of the request for the particular endpoint (eg security properties from a SSL connection).

Specified by:
customize in interface Connector
Overrides:
customize in class AbstractConnector
Throws:
IOException

newHttpChannelEndPoint

public HttpChannelEndPoint newHttpChannelEndPoint(SelectChannelConnector connector,
                                                  SocketChannel channel,
                                                  SelectChannelConnector.SelectSet selectSet,
                                                  SelectionKey sKey)
                                           throws IOException
Throws:
IOException

getLocalPort

public int getLocalPort()
Returns:
The actual port the connector is listening on or -1 if there is no port or the connector is not open.

newContinuation

public Continuation newContinuation()
Specified by:
newContinuation in interface Connector
Overrides:
newContinuation in class AbstractConnector