Apache Tomcat 7.0.2

org.apache.tomcat.util.net
Class NioEndpoint

java.lang.Object
  extended by org.apache.tomcat.util.net.AbstractEndpoint
      extended by org.apache.tomcat.util.net.NioEndpoint

public class NioEndpoint
extends AbstractEndpoint

NIO tailored thread pool, providing the following services:

When switching to Java 5, there's an opportunity to use the virtual machine's thread pool.

Author:
Mladen Turk, Remy Maucherat, Filip Hanik

Nested Class Summary
protected  class NioEndpoint.Acceptor
          Server socket acceptor thread.
static interface NioEndpoint.Handler
          Bare bones interface used for socket processing.
static class NioEndpoint.KeyAttachment
           
 class NioEndpoint.NioBufferHandler
           
 class NioEndpoint.Poller
          Poller class.
 class NioEndpoint.PollerEvent
          PollerEvent, cacheable object for poller events to avoid GC
static class NioEndpoint.SendfileData
          SendfileData class.
protected  class NioEndpoint.SocketProcessor
          This class is the equivalent of the Worker, but will simply use in an external Executor thread pool.
 
Field Summary
protected  int acceptorThreadCount
          Acceptor thread count.
protected  int acceptorThreadPriority
          Priority of the acceptor threads.
protected  AtomicInteger activeSocketProcessors
          Keep track of how many threads are in use
protected  ConcurrentLinkedQueue<NioEndpoint.PollerEvent> eventCache
          Cache for poller events
protected  NioEndpoint.Handler handler
          Handling of accepted sockets.
protected  ConcurrentLinkedQueue<NioEndpoint.KeyAttachment> keyCache
          Cache for key attachment objects
protected  ConcurrentLinkedQueue<NioChannel> nioChannels
          Bytebuffer cache, each channel holds a set of buffers (two, except for SSL holds four)
protected  int oomParachute
          The size of the OOM parachute.
protected  byte[] oomParachuteData
          The oom parachute, when an OOM error happens, will release the data, giving the JVM instantly a chunk of data to be able to recover with.
protected static String oomParachuteMsg
          Make sure this string has already been allocated
static int OP_CALLBACK
           
static int OP_REGISTER
           
protected  AtomicInteger pollerRotater
           
protected  NioEndpoint.Poller[] pollers
          The socket poller.
protected  int pollerThreadCount
          Poller thread count.
protected  int pollerThreadPriority
          Priority of the poller threads.
protected  ConcurrentLinkedQueue<NioEndpoint.SocketProcessor> processorCache
          Cache for SocketProcessor objects
protected  NioSelectorPool selectorPool
           
protected  long selectorTimeout
           
protected  ServerSocketChannel serverSock
          Server socket "pointer".
protected  SSLContext sslContext
           
protected  CountDownLatch stopLatch
           
protected  boolean useComet
          Allow comet request handling.
protected  boolean useSendfile
          use send file
 
Fields inherited from class org.apache.tomcat.util.net.AbstractEndpoint
CERTIFICATE_KEY, CIPHER_SUITE_KEY, initialized, internalExecutor, KEY_SIZE_KEY, paused, running, SESSION_ID_KEY, SESSION_MGR, sm, socketProperties, SSL_ATTR_ALGORITHM, SSL_ATTR_ALLOW_UNSAFE_RENEG, SSL_ATTR_CIPHERS, SSL_ATTR_CIPHERS_ARRAY, SSL_ATTR_CLIENT_AUTH, SSL_ATTR_CRL_FILE, SSL_ATTR_KEY_ALIAS, SSL_ATTR_KEY_PASS, SSL_ATTR_KEYSTORE_FILE, SSL_ATTR_KEYSTORE_PASS, SSL_ATTR_KEYSTORE_PROVIDER, SSL_ATTR_KEYSTORE_TYPE, SSL_ATTR_SESSION_CACHE_SIZE, SSL_ATTR_SESSION_TIMEOUT, SSL_ATTR_SSL_PROTOCOL, SSL_ATTR_TRUST_MAX_CERT_LENGTH, SSL_ATTR_TRUSTSTORE_ALGORITHM, SSL_ATTR_TRUSTSTORE_FILE, SSL_ATTR_TRUSTSTORE_PASS, SSL_ATTR_TRUSTSTORE_PROVIDER, SSL_ATTR_TRUSTSTORE_TYPE, threadPriority
 
Constructor Summary
NioEndpoint()
           
 
Method Summary
protected  void checkParachute()
           
protected  SSLEngine createSSLEngine()
           
 void destroy()
          Deallocate NIO memory pools, and close server socket.
 int getAcceptorThreadCount()
           
 int getAcceptorThreadPriority()
           
 NioEndpoint.Handler getHandler()
           
 int getKeepAliveCount()
          Number of keepalive sockets.
 int getOomParachute()
           
 byte[] getOomParachuteData()
           
 NioEndpoint.Poller getPoller0()
          Return an available poller in true round robin fashion
 int getPollerThreadCount()
           
 int getPollerThreadPriority()
           
 int getReadBufSize()
           
 NioSelectorPool getSelectorPool()
           
 long getSelectorTimeout()
           
 SSLContext getSSLContext()
           
 boolean getUseComet()
           
 boolean getUseSendfile()
           
 int getWriteBufSize()
           
 void init()
          Initialize the endpoint.
 boolean isPaused()
          Return the state of the endpoint.
 boolean isRunning()
          Return the state of the endpoint.
protected  boolean isWorkerAvailable()
          Returns true if a worker thread is available for processing.
 void pause()
          Pause the endpoint, which will make it stop accepting new sockets.
 boolean processSocket(NioChannel socket, SocketStatus status, boolean dispatch)
           
protected  boolean reclaimParachute(boolean force)
           
protected  void releaseCaches()
           
 void resume()
          Resume the endpoint, which will make it start accepting new sockets again.
 void setAcceptorThreadCount(int acceptorThreadCount)
           
 void setAcceptorThreadPriority(int acceptorThreadPriority)
           
 void setHandler(NioEndpoint.Handler handler)
           
 void setOomParachute(int oomParachute)
           
 void setOomParachuteData(byte[] oomParachuteData)
           
 void setPollerThreadCount(int pollerThreadCount)
           
 void setPollerThreadPriority(int pollerThreadPriority)
           
 boolean setProperty(String name, String value)
          Generic properties, introspected
 void setSelectorPool(NioSelectorPool selectorPool)
           
 void setSelectorTimeout(long timeout)
           
protected  boolean setSocketOptions(SocketChannel socket)
          Process the specified connection.
 void setSocketProperties(SocketProperties socketProperties)
           
 void setSSLContext(SSLContext c)
           
 void setUseComet(boolean useComet)
           
 void setUseSendfile(boolean useSendfile)
           
 void start()
          Start the NIO endpoint, creating acceptor, poller threads.
 void stop()
          Stop the endpoint.
 KeyManager[] wrap(KeyManager[] managers)
           
 
Methods inherited from class org.apache.tomcat.util.net.AbstractEndpoint
adjustRelativePath, createExecutor, defaultIfNull, getAddress, getAlgorithm, getAllowUnsafeLegacyRenegotiation, getBacklog, getCiphers, getCiphersArray, getClientAuth, getCrlFile, getCurrentThreadCount, getCurrentThreadsBusy, getDaemon, getExecutor, getKeepAliveTimeout, getKeyAlias, getKeyPass, getKeystoreFile, getKeystorePass, getKeystoreProvider, getKeystoreType, getMaxConnections, getMaxKeepAliveRequests, getMaxThreads, getMinSpareThreads, getName, getPort, getSessionCacheSize, getSessionTimeout, getSocketProperties, getSoLinger, getSoTimeout, getSslEnabledProtocolsArray, getSslProtocol, getTcpNoDelay, getThreadPriority, getTrustMaxCertLength, getTruststoreAlgorithm, getTruststoreFile, getTruststorePass, getTruststoreProvider, getTruststoreType, isSSLEnabled, setAddress, setAlgorithm, setAllowUnsafeLegacyRenegotiation, setBacklog, setCiphers, setClientAuth, setCrlFile, setDaemon, setExecutor, setKeepAliveTimeout, setKeyAlias, setKeyPass, setKeystoreFile, setKeystorePass, setKeystoreProvider, setKeystoreType, setMaxConnections, setMaxKeepAliveRequests, setMaxThreads, setMinSpareThreads, setName, setPort, setSessionCacheSize, setSessionTimeout, setSoLinger, setSoTimeout, setSSLEnabled, setSslEnabledProtocols, setSslProtocol, setTcpNoDelay, setThreadPriority, setTrustMaxCertLength, setTruststoreAlgorithm, setTruststoreFile, setTruststorePass, setTruststoreProvider, setTruststoreType, shutdownExecutor, unlockAccept
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OP_REGISTER

public static final int OP_REGISTER
See Also:
Constant Field Values

OP_CALLBACK

public static final int OP_CALLBACK
See Also:
Constant Field Values

selectorPool

protected NioSelectorPool selectorPool

serverSock

protected ServerSocketChannel serverSock
Server socket "pointer".


useSendfile

protected boolean useSendfile
use send file


oomParachute

protected int oomParachute
The size of the OOM parachute.


oomParachuteData

protected byte[] oomParachuteData
The oom parachute, when an OOM error happens, will release the data, giving the JVM instantly a chunk of data to be able to recover with.


oomParachuteMsg

protected static final String oomParachuteMsg
Make sure this string has already been allocated

See Also:
Constant Field Values

activeSocketProcessors

protected AtomicInteger activeSocketProcessors
Keep track of how many threads are in use


stopLatch

protected volatile CountDownLatch stopLatch

processorCache

protected ConcurrentLinkedQueue<NioEndpoint.SocketProcessor> processorCache
Cache for SocketProcessor objects


keyCache

protected ConcurrentLinkedQueue<NioEndpoint.KeyAttachment> keyCache
Cache for key attachment objects


eventCache

protected ConcurrentLinkedQueue<NioEndpoint.PollerEvent> eventCache
Cache for poller events


nioChannels

protected ConcurrentLinkedQueue<NioChannel> nioChannels
Bytebuffer cache, each channel holds a set of buffers (two, except for SSL holds four)


acceptorThreadPriority

protected int acceptorThreadPriority
Priority of the acceptor threads.


pollerThreadPriority

protected int pollerThreadPriority
Priority of the poller threads.


handler

protected NioEndpoint.Handler handler
Handling of accepted sockets.


useComet

protected boolean useComet
Allow comet request handling.


acceptorThreadCount

protected int acceptorThreadCount
Acceptor thread count.


pollerThreadCount

protected int pollerThreadCount
Poller thread count.


selectorTimeout

protected long selectorTimeout

pollers

protected NioEndpoint.Poller[] pollers
The socket poller.


pollerRotater

protected AtomicInteger pollerRotater

sslContext

protected SSLContext sslContext
Constructor Detail

NioEndpoint

public NioEndpoint()
Method Detail

setProperty

public boolean setProperty(String name,
                           String value)
Generic properties, introspected

Overrides:
setProperty in class AbstractEndpoint

setAcceptorThreadPriority

public void setAcceptorThreadPriority(int acceptorThreadPriority)

getAcceptorThreadPriority

public int getAcceptorThreadPriority()

setPollerThreadPriority

public void setPollerThreadPriority(int pollerThreadPriority)

getPollerThreadPriority

public int getPollerThreadPriority()

setHandler

public void setHandler(NioEndpoint.Handler handler)

getHandler

public NioEndpoint.Handler getHandler()

setUseComet

public void setUseComet(boolean useComet)

getUseComet

public boolean getUseComet()

setAcceptorThreadCount

public void setAcceptorThreadCount(int acceptorThreadCount)

getAcceptorThreadCount

public int getAcceptorThreadCount()

setPollerThreadCount

public void setPollerThreadCount(int pollerThreadCount)

getPollerThreadCount

public int getPollerThreadCount()

setSelectorTimeout

public void setSelectorTimeout(long timeout)

getSelectorTimeout

public long getSelectorTimeout()

getPoller0

public NioEndpoint.Poller getPoller0()
Return an available poller in true round robin fashion


setSelectorPool

public void setSelectorPool(NioSelectorPool selectorPool)

setSocketProperties

public void setSocketProperties(SocketProperties socketProperties)

setUseSendfile

public void setUseSendfile(boolean useSendfile)

setOomParachute

public void setOomParachute(int oomParachute)

setOomParachuteData

public void setOomParachuteData(byte[] oomParachuteData)

getSSLContext

public SSLContext getSSLContext()

setSSLContext

public void setSSLContext(SSLContext c)

checkParachute

protected void checkParachute()

reclaimParachute

protected boolean reclaimParachute(boolean force)

releaseCaches

protected void releaseCaches()

getKeepAliveCount

public int getKeepAliveCount()
Number of keepalive sockets.


isRunning

public boolean isRunning()
Return the state of the endpoint.

Overrides:
isRunning in class AbstractEndpoint
Returns:
true if the endpoint is running, false otherwise

isPaused

public boolean isPaused()
Return the state of the endpoint.

Overrides:
isPaused in class AbstractEndpoint
Returns:
true if the endpoint is paused, false otherwise

init

public void init()
          throws Exception
Initialize the endpoint.

Specified by:
init in class AbstractEndpoint
Throws:
Exception

wrap

public KeyManager[] wrap(KeyManager[] managers)

start

public void start()
           throws Exception
Start the NIO endpoint, creating acceptor, poller threads.

Specified by:
start in class AbstractEndpoint
Throws:
Exception

pause

public void pause()
Pause the endpoint, which will make it stop accepting new sockets.

Specified by:
pause in class AbstractEndpoint

resume

public void resume()
Resume the endpoint, which will make it start accepting new sockets again.

Specified by:
resume in class AbstractEndpoint

stop

public void stop()
Stop the endpoint. This will cause all processing threads to stop.


destroy

public void destroy()
             throws Exception
Deallocate NIO memory pools, and close server socket.

Specified by:
destroy in class AbstractEndpoint
Throws:
Exception

getWriteBufSize

public int getWriteBufSize()

getReadBufSize

public int getReadBufSize()

getSelectorPool

public NioSelectorPool getSelectorPool()

getUseSendfile

public boolean getUseSendfile()

getOomParachute

public int getOomParachute()

getOomParachuteData

public byte[] getOomParachuteData()

setSocketOptions

protected boolean setSocketOptions(SocketChannel socket)
Process the specified connection.


createSSLEngine

protected SSLEngine createSSLEngine()

isWorkerAvailable

protected boolean isWorkerAvailable()
Returns true if a worker thread is available for processing.

Returns:
boolean

processSocket

public boolean processSocket(NioChannel socket,
                             SocketStatus status,
                             boolean dispatch)

Apache Tomcat 7.0.2

Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.