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 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() |
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(SocketChannel channel,
SelectChannelEndPoint endpoint) |
org.mortbay.util.ajax.Continuation |
newContinuation() |
protected SelectChannelEndPoint |
newEndPoint(SocketChannel channel,
SelectorManager.SelectSet selectSet,
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, setUseDirectBuffers
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
getBuffer, getHeaderBufferSize, getRequestBufferSize, getResponseBufferSize, returnBuffer, setHeaderBufferSize, setRequestBufferSize, setResponseBufferSize
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getHeaderBufferSize, getRequestBufferSize, getResponseBufferSize, setHeaderBufferSize, setRequestBufferSize, setResponseBufferSize
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
getBuffer, returnBuffer
protected transient ServerSocketChannel _acceptChannel
public void accept(int acceptorID) throws IOException
accept
in class AbstractConnector
IOException
public void close() throws IOException
IOException
public void customize(EndPoint endpoint, Request request) throws IOException
Connector
customize
in interface Connector
customize
in class AbstractConnector
IOException
public void persist(EndPoint endpoint) throws IOException
Connector
persist
in interface Connector
persist
in class AbstractConnector
IOException
public Object getConnection()
public boolean getDelaySelectKeyUpdate()
public int getLocalPort()
public org.mortbay.util.ajax.Continuation newContinuation()
newContinuation
in interface Connector
newContinuation
in class AbstractConnector
public void open() throws IOException
Connector
IOException
public 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)
AbstractConnector
Socket.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 Connector
setMaxIdleTime
in class AbstractConnector
maxIdleTime
- 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 Connector
setLowResourceMaxIdleTime
in class AbstractConnector
lowResourcesMaxIdleTime
- the period in ms that a connection is allowed to be idle when resources are low.#setMaxIdleTime(long)}
protected void doStart() throws Exception
doStart
in class AbstractConnector
Exception
protected void doStop() throws Exception
doStop
in class AbstractConnector
Exception
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key) throws IOException
IOException
protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
Copyright © 2009 Mortbay Consulting Pty. Ltd. All Rights Reserved.