Top Description Fields Constructors Methods
org.mortbay.jetty.nio

public Class SelectChannelConnector

extends AbstractNIOConnector
Class Inheritance
Imports
java.io.IOException, java.net.InetSocketAddress, .Socket, java.nio.channels.SelectionKey, .ServerSocketChannel, .SocketChannel, org.mortbay.io.Connection, .EndPoint, org.mortbay.io.nio.SelectChannelEndPoint, .SelectorManager, .SelectorManager.SelectSet, org.mortbay.jetty.HttpConnection, .Request, org.mortbay.log.Log, org.mortbay.thread.Timeout.Task

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 org.mortbay.util.ajax.Continuation, threadless waits are supported. When a filter or servlet calls getEvent on a Continuation, a org.mortbay.jetty.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

Field Summary

Modifier and TypeField and Description
private transient ServerSocketChannel
private long
private long
private SelectorManager

Constructor Summary

AccessConstructor and Description
public
SelectChannelConnector()

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
accept(int acceptorID)

Implements abstract org.mortbay.jetty.AbstractConnector.accept.

public void
public void
customize(EndPoint endpoint, Request request)

Overrides org.mortbay.jetty.AbstractConnector.customize.

Implements org.mortbay.jetty.Connector.customize.

Customize a request for an endpoint.
protected void
protected void
public Object
public int
public long

Returns:

the lowResourcesConnections
getLowResourcesConnections
()

public long

Returns:

the lowResourcesMaxIdleTime
getLowResourcesMaxIdleTime
()

protected Connection
protected SelectChannelEndPoint
public void
open()

Implements org.mortbay.jetty.Connector.open.

Opens the connector
public void
public void
setLowResourceMaxIdleTime(int
the period in ms that a connection is allowed to be idle when resources are low.
lowResourcesMaxIdleTime
)

Overrides org.mortbay.jetty.AbstractConnector.setLowResourceMaxIdleTime.

Implements org.mortbay.jetty.Connector.setLowResourceMaxIdleTime.

Set the period in ms that a connection is allowed to be idle when this there are more than getLowResourcesConnections() connections.
public void
setLowResourcesConnections(long
the number of connections
lowResourcesConnections
)

Set the number of connections, which if exceeded places this manager in low resources state.

public void
setLowResourcesMaxIdleTime(long
the period in ms that a connection is allowed to be idle when resources are low.
lowResourcesMaxIdleTime
)

Set the period in ms that a connection is allowed to be idle when this there are more than getLowResourcesConnections() connections.
public void
setMaxIdleTime(int
The maxIdleTime to set.
maxIdleTime
)

Overrides org.mortbay.jetty.AbstractConnector.setMaxIdleTime.

Implements org.mortbay.jetty.Connector.setMaxIdleTime.

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.
Inherited from org.mortbay.jetty.nio.AbstractNIOConnector:
getUseDirectBuffersnewBuffersetUseDirectBuffers

Field Detail

_acceptChannelback to summary
private transient ServerSocketChannel _acceptChannel
_lowResourcesConnectionsback to summary
private long _lowResourcesConnections
_lowResourcesMaxIdleTimeback to summary
private long _lowResourcesMaxIdleTime
_managerback to summary
private SelectorManager _manager

Constructor Detail

SelectChannelConnectorback to summary
public SelectChannelConnector()

Constructor.

Method Detail

acceptback to summary
public void accept(int acceptorID) throws IOException

Implements abstract org.mortbay.jetty.AbstractConnector.accept.

closeback to summary
public void close() throws IOException

Implements org.mortbay.jetty.Connector.close.

customizeback to summary
public void customize(EndPoint endpoint, Request request) throws IOException

Overrides org.mortbay.jetty.AbstractConnector.customize.

Implements org.mortbay.jetty.Connector.customize.

Doc from org.mortbay.jetty.Connector.customize.

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

Annotations
@Override
doStartback to summary
protected void doStart() throws Exception

Overrides org.mortbay.jetty.AbstractConnector.doStart.

doStopback to summary
protected void doStop() throws Exception

Overrides org.mortbay.jetty.AbstractConnector.doStop.

getConnectionback to summary
public Object getConnection()

Implements org.mortbay.jetty.Connector.getConnection.

Returns:Object

Doc from org.mortbay.jetty.Connector.getConnection.

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

getLocalPortback to summary
public int getLocalPort()

Implements org.mortbay.jetty.Connector.getLocalPort.

Returns:int

Doc from org.mortbay.jetty.Connector.getLocalPort.

The actual port the connector is listening on or -1 if there is no port or the connector is not open.

getLowResourcesConnectionsback to summary
public long getLowResourcesConnections()
Returns:long

the lowResourcesConnections

getLowResourcesMaxIdleTimeback to summary
public long getLowResourcesMaxIdleTime()
Returns:long

the lowResourcesMaxIdleTime

newConnectionback to summary
protected Connection newConnection(SocketChannel channel, final SelectChannelEndPoint endpoint)
newEndPointback to summary
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key) throws IOException
openback to summary
public void open() throws IOException

Implements org.mortbay.jetty.Connector.open.

Doc from org.mortbay.jetty.Connector.open.

Opens the connector

persistback to summary
public void persist(EndPoint endpoint) throws IOException

Overrides org.mortbay.jetty.AbstractConnector.persist.

Implements org.mortbay.jetty.Connector.persist.

Doc from org.mortbay.jetty.Connector.persist.

Persist an endpoint. Called after every request if the connection is to remain open.

Annotations
@Override
setLowResourceMaxIdleTimeback to summary
public void setLowResourceMaxIdleTime(int lowResourcesMaxIdleTime)

Overrides org.mortbay.jetty.AbstractConnector.setLowResourceMaxIdleTime.

Implements org.mortbay.jetty.Connector.setLowResourceMaxIdleTime.

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:int

the period in ms that a connection is allowed to be idle when resources are low.

See Also
setMaxIdleTime(long)
setLowResourcesConnectionsback to summary
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:long

the number of connections

See Also
setLowResourcesMaxIdleTime(long)
setLowResourcesMaxIdleTimeback to summary
public void setLowResourcesMaxIdleTime(long 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.

Parameters
lowResourcesMaxIdleTime:long

the period in ms that a connection is allowed to be idle when resources are low.

See Also
setMaxIdleTime(long)
setMaxIdleTimeback to summary
public void setMaxIdleTime(int maxIdleTime)

Overrides org.mortbay.jetty.AbstractConnector.setMaxIdleTime.

Implements org.mortbay.jetty.Connector.setMaxIdleTime.

Doc from org.mortbay.jetty.AbstractConnector.setMaxIdleTime.

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

Parameters
maxIdleTime:int

The maxIdleTime to set.