Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mortbay.jetty.nio
Class SelectChannelConnector

    java.lang.Object
      org.mortbay.component.AbstractLifeCycle
          org.mortbay.jetty.AbstractBuffers
              org.mortbay.jetty.AbstractConnector
                  org.mortbay.jetty.nio.AbstractNIOConnector
                      org.mortbay.jetty.nio.SelectChannelConnector

All Implemented Interfaces:
  LifeCycle, Buffers, Connector, NIOConnector

Direct Known Subclasses:
  InheritedChannelConnector, SslSelectChannelConnector

    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.ConnectorEndPoint`
`static class` | `SelectChannelConnector.RetryContinuation`

Nested classes/interfaces inherited from class org.mortbay.jetty.AbstractBuffers
`AbstractBuffers.ThreadBuffers`

Nested classes/interfaces inherited from interface org.mortbay.component.LifeCycle
`LifeCycle.Listener`

Field Summary
`protected java.nio.channels.ServerSocketChannel` | `_acceptChannel`

Fields inherited from class org.mortbay.jetty.AbstractConnector
`_lowResourceMaxIdleTime, _maxIdleTime, _soLingerTime`

Fields inherited from class org.mortbay.component.AbstractLifeCycle
`_listeners`

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()`
`java.lang.Object` | `getConnection()`
`boolean` | `getDelaySelectKeyUpdate()` Get delay select key update If true, the select set is not updated when a endpoint is dispatched for reading.
`int` | `getLocalPort()`
`long` | `getLowResourcesConnections()`
`long` | `getLowResourcesMaxIdleTime()`
`protected Connection` | `newConnection(java.nio.channels.SocketChannel channel, SelectChannelEndPoint endpoint)`
`Continuation` | `newContinuation()`
`protected SelectChannelEndPoint` | `newEndPoint(java.nio.channels.SocketChannel channel, SelectorManager.SelectSet selectSet, java.nio.channels.SelectionKey key)`
`void` | `open()` Opens the connector
`void` | `persist(EndPoint endpoint)` Persist an endpoint.
`void` | `setDelaySelectKeyUpdate(boolean delay)`
`void` | `setLowResourceMaxIdleTime(int lowResourcesMaxIdleTime)` Set the period in ms that a connection is allowed to be idle when this there are more than `getLowResourcesConnections()` connections.
`void` | `setLowResourcesConnections(long lowResourcesConnections)` Set the number of connections, which if exceeded places this manager in low resources state.
`void` | `setLowResourcesMaxIdleTime(long lowResourcesMaxIdleTime)` Deprecated. use `setLowResourceMaxIdleTime(int)`
`void` | `setMaxIdleTime(int maxIdleTime)` Set the maximum Idle time for a connection, which roughly translates to the `Socket.setSoTimeout(int)` call, although with NIO implementations other mechanisms may be used to implement the timeout.

Methods inherited from class org.mortbay.jetty.nio.AbstractNIOConnector
`getUseDirectBuffers, newBuffer, setUseDirectBuffers`

Methods inherited from class org.mortbay.jetty.AbstractConnector
`checkForwardedHeaders, configure, connectionClosed, connectionOpened, getAcceptorPriorityOffset, getAcceptors, getAcceptQueueSize, getConfidentialPort, getConfidentialScheme, getConnections, getConnectionsDurationAve, getConnectionsDurationMax, getConnectionsDurationMin, getConnectionsDurationTotal, getConnectionsOpen, getConnectionsOpenMax, getConnectionsOpenMin, getConnectionsRequestsAve, getConnectionsRequestsMax, getConnectionsRequestsMin, getForwardedForHeader, getForwardedHostHeader, getForwardedServerHeader, getHost, getHostHeader, getIntegralPort, getIntegralScheme, getLeftMostValue, getLowResourceMaxIdleTime, getMaxIdleTime, getName, getPort, getRequests, getResolveNames, getReuseAddress, getServer, getSoLingerTime, getStatsOn, getStatsOnMs, getThreadPool, isConfidential, isForwarded, isIntegral, join, setAcceptorPriorityOffset, setAcceptors, setAcceptQueueSize, setConfidentialPort, setConfidentialScheme, setForwarded, setForwardedForHeader, setForwardedHostHeader, setForwardedServerHeader, setHost, setHostHeader, setIntegralPort, setIntegralScheme, setName, setPort, setResolveNames, setReuseAddress, setServer, setSoLingerTime, setStatsOn, setThreadPool, statsReset, stopAccept, toString`

Methods inherited from class org.mortbay.jetty.AbstractBuffers
`getBuffer, getHeaderBufferSize, getRequestBufferSize, getResponseBufferSize, returnBuffer, setHeaderBufferSize, setRequestBufferSize, setResponseBufferSize`

Methods inherited from class org.mortbay.component.AbstractLifeCycle
`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, 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.jetty.Connector
`getHeaderBufferSize, getRequestBufferSize, getResponseBufferSize, setHeaderBufferSize, setRequestBufferSize, setResponseBufferSize`

Methods inherited from interface org.mortbay.component.LifeCycle
`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Methods inherited from interface org.mortbay.io.Buffers
`getBuffer, returnBuffer`

Field Detail

### _acceptChannel

    protected transient java.nio.channels.ServerSocketChannel _acceptChannel

Constructor Detail

### SelectChannelConnector

    public SelectChannelConnector()

  Constructor.

Method Detail

### accept

    public void accept(int acceptorID)
                throws java.io.IOException

  Specified by:
    `accept` in class `AbstractConnector`
  Throws:
    `java.io.IOException`

### close

    public void close()
               throws java.io.IOException

  Throws:
    `java.io.IOException`

### customize

    public void customize(EndPoint endpoint,
                          Request request)
                   throws java.io.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:
    `java.io.IOException`

### persist

    public void persist(EndPoint endpoint)
                 throws java.io.IOException

  Description copied from interface: `Connector`
  Persist an endpoint. Called after every request if the connection is to remain open.

  Specified by:
    `persist` in interface `Connector`
  Overrides:
    `persist` in class `AbstractConnector`
  Throws:
    `java.io.IOException`

### getConnection

    public java.lang.Object getConnection()

  Returns:
    the underlying socket, channel, buffer etc. for the connector.

### getDelaySelectKeyUpdate

    public boolean getDelaySelectKeyUpdate()

  Get delay select key update 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.

### 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`

### open

    public void open()
              throws java.io.IOException

  Description copied from interface: `Connector`
  Opens the connector

  Throws:
    `java.io.IOException`

### 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.

### setMaxIdleTime

    public void setMaxIdleTime(int maxIdleTime)

  Description copied from class: `AbstractConnector`
  Set the maximum Idle time for a connection, which roughly translates to the `Socket.setSoTimeout(int)` call, although with NIO implementations other mechanisms may be used to implement the timeout. The max idle time is applied:
  - When waiting for a new request to be received on a connection
  - When reading the headers and content of a request
  - When writing the headers and content of a response
  Jetty interprets this value as the maximum time between some progress being made on the connection. So if a single byte is read or written, then the timeout (if implemented by jetty) is reset. However, in many instances, the reading/writing is delegated to the JVM, and the semantic is more strictly enforced as the maximum time a single read/write operation can take. Note, that as Jetty supports writes of memory mapped file buffers, then a write may take many 10s of seconds for large content written to a slow device.

  Previously, Jetty supported separate idle timeouts and IO operation timeouts, however the expense of changing the value of soTimeout was significant, so these timeouts were merged. With the advent of NIO, it may be possible to again differentiate these values (if there is demand).

  Specified by:
    `setMaxIdleTime` in interface `Connector`
  Overrides:
    `setMaxIdleTime` in class `AbstractConnector`
  Parameters:
    `maxIdleTime` - The maxIdleTime to set.

### getLowResourcesConnections

    public long getLowResourcesConnections()

  Returns:
    the lowResourcesConnections

### setLowResourcesConnections

    public void setLowResourcesConnections(long lowResourcesConnections)

  Set the number of connections, which if exceeded places this manager in low resources state. This is not an exact measure as the connection count is averaged over the select sets.

  Parameters:
    `lowResourcesConnections` - the number of connections
  See Also:
    `#setLowResourcesMaxIdleTime(long)}`

### getLowResourcesMaxIdleTime

    public long getLowResourcesMaxIdleTime()

  Returns:
    the lowResourcesMaxIdleTime

### setLowResourcesMaxIdleTime

    public void setLowResourcesMaxIdleTime(long lowResourcesMaxIdleTime)

  Deprecated. use `setLowResourceMaxIdleTime(int)`

  Set the period in ms that a connection is allowed to be idle when this there are more than `getLowResourcesConnections()` connections. This allows the server to rapidly close idle connections in order to gracefully handle high load situations.

  Parameters:
    `lowResourcesMaxIdleTime` - the period in ms that a connection is allowed to be idle when resources are low.
  See Also:
    `#setMaxIdleTime(long)}`

### setLowResourceMaxIdleTime

    public void setLowResourceMaxIdleTime(int lowResourcesMaxIdleTime)

  Set the period in ms that a connection is allowed to be idle when this there are more than `getLowResourcesConnections()` connections. This allows the server to rapidly close idle connections in order to gracefully handle high load situations.

  Specified by:
    `setLowResourceMaxIdleTime` in interface `Connector`
  Overrides:
    `setLowResourceMaxIdleTime` in class `AbstractConnector`
  Parameters:
    `lowResourcesMaxIdleTime` - the period in ms that a connection is allowed to be idle when resources are low.
  See Also:
    `#setMaxIdleTime(long)}`

### doStart

    protected void doStart()
                    throws java.lang.Exception

  Overrides:
    `doStart` in class `AbstractConnector`
  Throws:
    `java.lang.Exception`

### doStop

    protected void doStop()
                   throws java.lang.Exception

  Overrides:
    `doStop` in class `AbstractConnector`
  Throws:
    `java.lang.Exception`

### newEndPoint

    protected SelectChannelEndPoint newEndPoint(java.nio.channels.SocketChannel channel,
                                                SelectorManager.SelectSet selectSet,
                                                java.nio.channels.SelectionKey key)
                                         throws java.io.IOException

  Throws:
    `java.io.IOException`

### newConnection

    protected Connection newConnection(java.nio.channels.SocketChannel channel,
                                       SelectChannelEndPoint endpoint)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.