org.mortbay.jetty.nio
public class SelectChannelConnector extends AbstractNIOConnector
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
SelectChannelConnector.ConnectorEndPoint |
static class |
SelectChannelConnector.RetryContinuation |
AbstractBuffers.ThreadBuffers| Modifier and Type | Field and Description |
|---|---|
protected java.nio.channels.ServerSocketChannel |
_acceptChannel |
_lowResourceMaxIdleTime, _maxIdleTime, _soLingerTime| Constructor and Description |
|---|
SelectChannelConnector()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
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) |
org.mortbay.util.ajax.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.
|
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. |
getUseDirectBuffers, newBuffer, setUseDirectBufferscheckForwardedHeaders, 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, toStringgetBuffer, getHeaderBufferSize, getRequestBufferSize, getResponseBufferSize, returnBuffer, setHeaderBufferSize, setRequestBufferSize, setResponseBufferSizeaddLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetHeaderBufferSize, getRequestBufferSize, getResponseBufferSize, setHeaderBufferSize, setRequestBufferSize, setResponseBufferSizeaddLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopgetBuffer, returnBufferprotected transient java.nio.channels.ServerSocketChannel _acceptChannel
public void accept(int acceptorID)
throws java.io.IOException
accept in class AbstractConnectorjava.io.IOExceptionpublic void close()
throws java.io.IOException
java.io.IOExceptionpublic void customize(EndPoint endpoint, Request request) throws java.io.IOException
Connectorcustomize in interface Connectorcustomize in class AbstractConnectorjava.io.IOExceptionpublic void persist(EndPoint endpoint) throws java.io.IOException
Connectorpersist in interface Connectorpersist in class AbstractConnectorjava.io.IOExceptionpublic java.lang.Object getConnection()
public boolean getDelaySelectKeyUpdate()
public int getLocalPort()
public org.mortbay.util.ajax.Continuation newContinuation()
newContinuation in interface ConnectornewContinuation in class AbstractConnectorpublic void open()
throws java.io.IOException
Connectorjava.io.IOExceptionpublic void setDelaySelectKeyUpdate(boolean delay)
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.public void setMaxIdleTime(int maxIdleTime)
AbstractConnectorSocket.setSoTimeout(int) call, although with NIO
implementations other mechanisms may be used to implement the timeout.
The max idle time is applied: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).
setMaxIdleTime in interface ConnectorsetMaxIdleTime in class AbstractConnectormaxIdleTime - The maxIdleTime to set.public long getLowResourcesConnections()
public void setLowResourcesConnections(long lowResourcesConnections)
lowResourcesConnections - the number of connections#setLowResourcesMaxIdleTime(long)}public long getLowResourcesMaxIdleTime()
public void setLowResourcesMaxIdleTime(long lowResourcesMaxIdleTime)
setLowResourceMaxIdleTime(int)getLowResourcesConnections() connections. This allows the server to rapidly close idle connections
in order to gracefully handle high load situations.lowResourcesMaxIdleTime - the period in ms that a connection is allowed to be idle when resources are low.#setMaxIdleTime(long)}public void setLowResourceMaxIdleTime(int lowResourcesMaxIdleTime)
getLowResourcesConnections() connections. This allows the server to rapidly close idle connections
in order to gracefully handle high load situations.setLowResourceMaxIdleTime in interface ConnectorsetLowResourceMaxIdleTime in class AbstractConnectorlowResourcesMaxIdleTime - the period in ms that a connection is allowed to be idle when resources are low.#setMaxIdleTime(long)}protected void doStart()
throws java.lang.Exception
doStart in class AbstractConnectorjava.lang.Exceptionprotected void doStop()
throws java.lang.Exception
doStop in class AbstractConnectorjava.lang.Exceptionprotected SelectChannelEndPoint newEndPoint(java.nio.channels.SocketChannel channel, SelectorManager.SelectSet selectSet, java.nio.channels.SelectionKey key) throws java.io.IOException
java.io.IOExceptionprotected Connection newConnection(java.nio.channels.SocketChannel channel, SelectChannelEndPoint endpoint)
Copyright © 2009 Mortbay Consulting Pty. Ltd. All Rights Reserved.