org.apache.tomcat.util.net

Class NioEndpoint

public class NioEndpoint extends Object

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 classNioEndpoint.Acceptor
Server socket acceptor thread.
interfaceNioEndpoint.Handler
Bare bones interface used for socket processing.
static classNioEndpoint.KeyAttachment
classNioEndpoint.NioBufferHandler
classNioEndpoint.Poller
Poller class.
classNioEndpoint.PollerEvent
PollerEvent, cacheable object for poller events to avoid GC
static classNioEndpoint.SendfileData
SendfileData class.
protected classNioEndpoint.SocketProcessor
This class is the equivalent of the Worker, but will simply use in an external Executor thread pool.
static classNioEndpoint.TaskQueue
protected classNioEndpoint.Worker
Server processor class.
classNioEndpoint.WorkerStack
Field Summary
protected intacceptorThreadCount
Acceptor thread count.
protected intacceptorThreadPriority
Priority of the acceptor threads.
protected AtomicIntegeractiveSocketProcessors
Keep track of how many threads are in use
protected InetAddressaddress
Address for the server socket.
protected Stringalgorithm
protected intbacklog
Allows the server developer to specify the backlog that should be used for server sockets.
protected Stringciphers
protected String[]ciphersarr
protected StringclientAuth
protected intcurThreads
Current worker threads count.
protected intcurThreadsBusy
Current worker threads busy count.
static StringCERTIFICATE_KEY
The Request attribute key for the client certificate chain.
static StringCIPHER_SUITE_KEY
The Request attribute key for the cipher suite.
protected booleandaemon
The default is true - the created threads will be in daemon mode.
protected ConcurrentLinkedQueue<NioEndpoint.PollerEvent>eventCache
Cache for poller events
protected Executorexecutor
External Executor based thread pool.
protected NioEndpoint.Handlerhandler
Handling of accepted sockets.
protected booleaninitialized
Track the initialization state of the endpoint.
protected ConcurrentLinkedQueue<NioEndpoint.KeyAttachment>keyCache
Cache for key attachment objects
protected StringkeystoreFile
protected StringkeystorePass
protected StringkeystoreType
static StringKEY_SIZE_KEY
The Request attribute key for the key size.
protected static Loglog
protected intmaxThreads
Maximum amount of worker threads.
protected Stringname
Name of the thread pool, which will be used for naming child threads.
protected ConcurrentLinkedQueue<NioChannel>nioChannels
Bytebuffer cache, each channel holds a set of buffers (two, except for SSL holds four)
protected intoomParachute
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 StringoomParachuteMsg
Make sure this string has already been allocated
static intOP_CALLBACK
static intOP_REGISTER
protected booleanpaused
Will be set to true whenever the endpoint is paused.
protected AtomicIntegerpollerRotater
protected NioEndpoint.Poller[]pollers
The socket poller.
protected intpollerThreadCount
Poller thread count.
protected intpollerThreadPriority
Priority of the poller threads.
protected intport
Server socket port.
protected ConcurrentLinkedQueue<NioEndpoint.SocketProcessor>processorCache
Cache for SocketProcessor objects
protected booleanrunning
Running state of the endpoint.
protected booleansecure
protected NioSelectorPoolselectorPool
protected longselectorTimeout
protected intsequence
Sequence number used to generate thread names.
protected ServerSocketChannelserverSock
Server socket "pointer".
protected intsessionCacheSize
protected intsessionCacheTimeout
protected static StringManagersm
protected SocketPropertiessocketProperties
protected SSLContextsslContext
protected StringsslEnabledProtocols
protected String[]sslEnabledProtocolsarr
protected StringsslProtocol
protected CountDownLatchstopLatch
static StringSESSION_ID_KEY
The Request attribute key for the session id.
protected booleanSSLEnabled
SSL engine.
protected intthreadPriority
Priority of the worker threads.
protected StringtruststoreFile
protected StringtruststorePass
protected StringtruststoreType
protected booleanuseComet
Allow comet request handling.
protected booleanuseExecutor
protected booleanuseSendfile
use send file
protected NioEndpoint.WorkerStackworkers
Available workers.
Method Summary
StringadjustRelativePath(String path, String relativeTo)
protected voidcheckParachute()
protected SSLEnginecreateSSLEngine()
protected NioEndpoint.WorkercreateWorkerThread()
Create (or allocate) and return an available processor for use in processing a specific HTTP request, if possible.
StringdefaultIfNull(String val, String defaultValue)
voiddestroy()
Deallocate NIO memory pools, and close server socket.
intgetAcceptorThreadCount()
intgetAcceptorThreadPriority()
InetAddressgetAddress()
StringgetAlgorithm()
intgetBacklog()
StringgetCiphers()
StringgetClientAuth()
intgetCurrentThreadCount()
Return the amount of threads that are managed by the pool.
intgetCurrentThreadsBusy()
Return the amount of threads that are in use
booleangetDaemon()
ExecutorgetExecutor()
NioEndpoint.HandlergetHandler()
intgetKeepAliveCount()
Number of keepalive sockets.
StringgetKeyAlias()
StringgetKeystore()
StringgetKeystoreFile()
StringgetKeystorePass()
StringgetKeystoreType()
intgetMaxSpareThreads()
Dummy maxSpareThreads property.
intgetMaxThreads()
intgetMinSpareThreads()
Dummy minSpareThreads property.
StringgetName()
intgetOomParachute()
byte[]getOomParachuteData()
NioEndpoint.PollergetPoller0()
Return an available poller in true round robin fashion
intgetPollerThreadCount()
intgetPollerThreadPriority()
intgetPort()
intgetReadBufSize()
booleangetSecure()
NioSelectorPoolgetSelectorPool()
longgetSelectorTimeout()
protected intgetSequence()
Get a sequence number used for thread naming.
intgetSessionCacheSize()
intgetSessionCacheTimeout()
SocketPropertiesgetSocketProperties()
intgetSoLinger()
Socket linger.
intgetSoTimeout()
Socket timeout.
StringgetSslProtocol()
SSLContextgetSSLContext()
booleangetTcpNoDelay()
Socket TCP no delay.
intgetThreadPriority()
StringgetTruststoreFile()
StringgetTruststorePass()
StringgetTruststoreType()
booleangetUseComet()
booleangetUseExecutor()
booleangetUseSendfile()
protected NioEndpoint.WorkergetWorkerThread()
Return a new worker thread, and block while to worker is available.
intgetWriteBufSize()
voidinit()
Initialize the endpoint.
booleanisPaused()
Return the state of the endpoint.
booleanisRunning()
Return the state of the endpoint.
booleanisSSLEnabled()
protected booleanisWorkerAvailable()
Returns true if a worker thread is available for processing.
protected NioEndpoint.WorkernewWorkerThread()
Create and return a new processor suitable for processing HTTP requests and returning the corresponding responses.
voidpause()
Pause the endpoint, which will make it stop accepting new sockets.
protected booleanprocessSocket(NioChannel socket)
Process given socket.
protected booleanprocessSocket(NioChannel socket, SocketStatus status)
Process given socket for an event.
protected booleanprocessSocket(NioChannel socket, SocketStatus status, boolean dispatch)
protected booleanreclaimParachute(boolean force)
protected voidrecycleWorkerThread(NioEndpoint.Worker workerThread)
Recycle the specified Processor so that it can be used again.
protected voidreleaseCaches()
voidresume()
Resume the endpoint, which will make it start accepting new sockets again.
voidsetAcceptorThreadCount(int acceptorThreadCount)
voidsetAcceptorThreadPriority(int acceptorThreadPriority)
voidsetAddress(InetAddress address)
voidsetAlgorithm(String s)
voidsetBacklog(int backlog)
voidsetCiphers(String s)
voidsetClientAuth(String s)
voidsetDaemon(boolean b)
voidsetExecutor(Executor executor)
voidsetHandler(NioEndpoint.Handler handler)
voidsetKeyAlias(String s)
voidsetKeystore(String s)
voidsetKeystoreFile(String s)
voidsetKeystorePass(String s)
voidsetKeystoreType(String s)
voidsetMaxThreads(int maxThreads)
voidsetName(String name)
voidsetOomParachute(int oomParachute)
voidsetOomParachuteData(byte[] oomParachuteData)
voidsetPollerThreadCount(int pollerThreadCount)
voidsetPollerThreadPriority(int pollerThreadPriority)
voidsetPort(int port)
booleansetProperty(String name, String value)
Generic properties, introspected
voidsetSecure(boolean b)
voidsetSelectorPool(NioSelectorPool selectorPool)
voidsetSelectorTimeout(long timeout)
voidsetSessionCacheSize(int i)
voidsetSessionCacheTimeout(int i)
protected booleansetSocketOptions(SocketChannel socket)
Process the specified connection.
voidsetSocketProperties(SocketProperties socketProperties)
voidsetSoLinger(int soLinger)
voidsetSoTimeout(int soTimeout)
voidsetSslEnabledProtocols(String s)
voidsetSslProtocol(String s)
voidsetSSLContext(SSLContext c)
voidsetSSLEnabled(boolean SSLEnabled)
voidsetTcpNoDelay(boolean tcpNoDelay)
voidsetThreadPriority(int threadPriority)
voidsetTruststoreFile(String s)
voidsetTruststorePass(String truststorePass)
voidsetTruststoreType(String truststoreType)
voidsetUseComet(boolean useComet)
voidsetUseExecutor(boolean useexec)
voidsetUseSendfile(boolean useSendfile)
voidstart()
Start the NIO endpoint, creating acceptor, poller threads.
voidstop()
Stop the endpoint.
protected voidunlockAccept()
Unlock the server socket accept using a bogus connection.
KeyManager[]wrap(KeyManager[] managers)

Field Detail

acceptorThreadCount

protected int acceptorThreadCount
Acceptor thread count.

acceptorThreadPriority

protected int acceptorThreadPriority
Priority of the acceptor threads.

activeSocketProcessors

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

address

protected InetAddress address
Address for the server socket.

algorithm

protected String algorithm

backlog

protected int backlog
Allows the server developer to specify the backlog that should be used for server sockets. By default, this value is 100.

ciphers

protected String ciphers

ciphersarr

protected String[] ciphersarr

clientAuth

protected String clientAuth

curThreads

protected int curThreads
Current worker threads count.

curThreadsBusy

protected int curThreadsBusy
Current worker threads busy count.

CERTIFICATE_KEY

public static final String CERTIFICATE_KEY
The Request attribute key for the client certificate chain.

CIPHER_SUITE_KEY

public static final String CIPHER_SUITE_KEY
The Request attribute key for the cipher suite.

daemon

protected boolean daemon
The default is true - the created threads will be in daemon mode. If set to false, the control thread will not be daemon - and will keep the process alive.

eventCache

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

executor

protected Executor executor
External Executor based thread pool.

handler

protected NioEndpoint.Handler handler
Handling of accepted sockets.

initialized

protected boolean initialized
Track the initialization state of the endpoint.

keyCache

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

keystoreFile

protected String keystoreFile

keystorePass

protected String keystorePass

keystoreType

protected String keystoreType

KEY_SIZE_KEY

public static final String KEY_SIZE_KEY
The Request attribute key for the key size.

log

protected static Log log

maxThreads

protected int maxThreads
Maximum amount of worker threads.

name

protected String name
Name of the thread pool, which will be used for naming child threads.

nioChannels

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

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

OP_CALLBACK

public static final int OP_CALLBACK

OP_REGISTER

public static final int OP_REGISTER

paused

protected volatile boolean paused
Will be set to true whenever the endpoint is paused.

pollerRotater

protected AtomicInteger pollerRotater

pollers

protected NioEndpoint.Poller[] pollers
The socket poller.

pollerThreadCount

protected int pollerThreadCount
Poller thread count.

pollerThreadPriority

protected int pollerThreadPriority
Priority of the poller threads.

port

protected int port
Server socket port.

processorCache

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

running

protected volatile boolean running
Running state of the endpoint.

secure

protected boolean secure

selectorPool

protected NioSelectorPool selectorPool

selectorTimeout

protected long selectorTimeout

sequence

protected int sequence
Sequence number used to generate thread names.

serverSock

protected ServerSocketChannel serverSock
Server socket "pointer".

sessionCacheSize

protected int sessionCacheSize

sessionCacheTimeout

protected int sessionCacheTimeout

sm

protected static StringManager sm

socketProperties

protected SocketProperties socketProperties

sslContext

protected SSLContext sslContext

sslEnabledProtocols

protected String sslEnabledProtocols

sslEnabledProtocolsarr

protected String[] sslEnabledProtocolsarr

sslProtocol

protected String sslProtocol

stopLatch

protected volatile CountDownLatch stopLatch

SESSION_ID_KEY

public static final String SESSION_ID_KEY
The Request attribute key for the session id. This one is a Tomcat extension to the Servlet spec.

SSLEnabled

protected boolean SSLEnabled
SSL engine.

threadPriority

protected int threadPriority
Priority of the worker threads.

truststoreFile

protected String truststoreFile

truststorePass

protected String truststorePass

truststoreType

protected String truststoreType

useComet

protected boolean useComet
Allow comet request handling.

useExecutor

protected boolean useExecutor

useSendfile

protected boolean useSendfile
use send file

workers

protected NioEndpoint.WorkerStack workers
Available workers.

Method Detail

adjustRelativePath

public String adjustRelativePath(String path, String relativeTo)

checkParachute

protected void checkParachute()

createSSLEngine

protected SSLEngine createSSLEngine()

createWorkerThread

protected NioEndpoint.Worker createWorkerThread()
Create (or allocate) and return an available processor for use in processing a specific HTTP request, if possible. If the maximum allowed processors have already been created and are in use, return null instead.

defaultIfNull

public String defaultIfNull(String val, String defaultValue)

destroy

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

getAcceptorThreadCount

public int getAcceptorThreadCount()

getAcceptorThreadPriority

public int getAcceptorThreadPriority()

getAddress

public InetAddress getAddress()

getAlgorithm

public String getAlgorithm()

getBacklog

public int getBacklog()

getCiphers

public String getCiphers()

getClientAuth

public String getClientAuth()

getCurrentThreadCount

public int getCurrentThreadCount()
Return the amount of threads that are managed by the pool.

Returns: the amount of threads that are managed by the pool

getCurrentThreadsBusy

public int getCurrentThreadsBusy()
Return the amount of threads that are in use

Returns: the amount of threads that are in use

getDaemon

public boolean getDaemon()

getExecutor

public Executor getExecutor()

getHandler

public NioEndpoint.Handler getHandler()

getKeepAliveCount

public int getKeepAliveCount()
Number of keepalive sockets.

getKeyAlias

public String getKeyAlias()

getKeystore

public String getKeystore()

getKeystoreFile

public String getKeystoreFile()

getKeystorePass

public String getKeystorePass()

getKeystoreType

public String getKeystoreType()

getMaxSpareThreads

public int getMaxSpareThreads()
Dummy maxSpareThreads property.

getMaxThreads

public int getMaxThreads()

getMinSpareThreads

public int getMinSpareThreads()
Dummy minSpareThreads property.

getName

public String getName()

getOomParachute

public int getOomParachute()

getOomParachuteData

public byte[] getOomParachuteData()

getPoller0

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

Returns:

getPollerThreadCount

public int getPollerThreadCount()

getPollerThreadPriority

public int getPollerThreadPriority()

getPort

public int getPort()

getReadBufSize

public int getReadBufSize()

getSecure

public boolean getSecure()

getSelectorPool

public NioSelectorPool getSelectorPool()

getSelectorTimeout

public long getSelectorTimeout()

getSequence

protected int getSequence()
Get a sequence number used for thread naming.

getSessionCacheSize

public int getSessionCacheSize()

getSessionCacheTimeout

public int getSessionCacheTimeout()

getSocketProperties

public SocketProperties getSocketProperties()

getSoLinger

public int getSoLinger()
Socket linger.

getSoTimeout

public int getSoTimeout()
Socket timeout.

getSslProtocol

public String getSslProtocol()

getSSLContext

public SSLContext getSSLContext()

getTcpNoDelay

public boolean getTcpNoDelay()
Socket TCP no delay.

getThreadPriority

public int getThreadPriority()

getTruststoreFile

public String getTruststoreFile()

getTruststorePass

public String getTruststorePass()

getTruststoreType

public String getTruststoreType()

getUseComet

public boolean getUseComet()

getUseExecutor

public boolean getUseExecutor()

getUseSendfile

public boolean getUseSendfile()

getWorkerThread

protected NioEndpoint.Worker getWorkerThread()
Return a new worker thread, and block while to worker is available.

getWriteBufSize

public int getWriteBufSize()

init

public void init()
Initialize the endpoint.

isPaused

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

Returns: true if the endpoint is paused, false otherwise

isRunning

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

Returns: true if the endpoint is running, false otherwise

isSSLEnabled

public boolean isSSLEnabled()

isWorkerAvailable

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

Returns: boolean

newWorkerThread

protected NioEndpoint.Worker newWorkerThread()
Create and return a new processor suitable for processing HTTP requests and returning the corresponding responses.

pause

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

processSocket

protected boolean processSocket(NioChannel socket)
Process given socket.

processSocket

protected boolean processSocket(NioChannel socket, SocketStatus status)
Process given socket for an event.

processSocket

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

reclaimParachute

protected boolean reclaimParachute(boolean force)

recycleWorkerThread

protected void recycleWorkerThread(NioEndpoint.Worker workerThread)
Recycle the specified Processor so that it can be used again.

Parameters: workerThread The processor to be recycled

releaseCaches

protected void releaseCaches()

resume

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

setAcceptorThreadCount

public void setAcceptorThreadCount(int acceptorThreadCount)

setAcceptorThreadPriority

public void setAcceptorThreadPriority(int acceptorThreadPriority)

setAddress

public void setAddress(InetAddress address)

setAlgorithm

public void setAlgorithm(String s)

setBacklog

public void setBacklog(int backlog)

setCiphers

public void setCiphers(String s)

setClientAuth

public void setClientAuth(String s)

setDaemon

public void setDaemon(boolean b)

setExecutor

public void setExecutor(Executor executor)

setHandler

public void setHandler(NioEndpoint.Handler handler)

setKeyAlias

public void setKeyAlias(String s)

setKeystore

public void setKeystore(String s)

setKeystoreFile

public void setKeystoreFile(String s)

setKeystorePass

public void setKeystorePass(String s)

setKeystoreType

public void setKeystoreType(String s)

setMaxThreads

public void setMaxThreads(int maxThreads)

setName

public void setName(String name)

setOomParachute

public void setOomParachute(int oomParachute)

setOomParachuteData

public void setOomParachuteData(byte[] oomParachuteData)

setPollerThreadCount

public void setPollerThreadCount(int pollerThreadCount)

setPollerThreadPriority

public void setPollerThreadPriority(int pollerThreadPriority)

setPort

public void setPort(int port)

setProperty

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

setSecure

public void setSecure(boolean b)

setSelectorPool

public void setSelectorPool(NioSelectorPool selectorPool)

setSelectorTimeout

public void setSelectorTimeout(long timeout)

setSessionCacheSize

public void setSessionCacheSize(int i)

setSessionCacheTimeout

public void setSessionCacheTimeout(int i)

setSocketOptions

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

setSocketProperties

public void setSocketProperties(SocketProperties socketProperties)

setSoLinger

public void setSoLinger(int soLinger)

setSoTimeout

public void setSoTimeout(int soTimeout)

setSslEnabledProtocols

public void setSslEnabledProtocols(String s)

setSslProtocol

public void setSslProtocol(String s)

setSSLContext

public void setSSLContext(SSLContext c)

setSSLEnabled

public void setSSLEnabled(boolean SSLEnabled)

setTcpNoDelay

public void setTcpNoDelay(boolean tcpNoDelay)

setThreadPriority

public void setThreadPriority(int threadPriority)

setTruststoreFile

public void setTruststoreFile(String s)

setTruststorePass

public void setTruststorePass(String truststorePass)

setTruststoreType

public void setTruststoreType(String truststoreType)

setUseComet

public void setUseComet(boolean useComet)

setUseExecutor

public void setUseExecutor(boolean useexec)

setUseSendfile

public void setUseSendfile(boolean useSendfile)

start

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

stop

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

unlockAccept

protected void unlockAccept()
Unlock the server socket accept using a bogus connection.

wrap

public KeyManager[] wrap(KeyManager[] managers)
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.