org.apache.tomcat.util.net
Class NioEndpoint

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

public class NioEndpoint
extends java.lang.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  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
protected  class NioEndpoint.SocketEventProcessor
          This class is the equivalent of the Worker, but will simply use in an external Executor thread pool.
protected  class NioEndpoint.SocketOptionsProcessor
          This class is the equivalent of the Worker, but will simply use in an external Executor thread pool.
protected  class NioEndpoint.SocketProcessor
          This class is the equivalent of the Worker, but will simply use in an external Executor thread pool.
protected  class NioEndpoint.Worker
          Server processor class.
 class NioEndpoint.WorkerStack
           
 
Field Summary
protected  int acceptorThreadCount
          Acceptor thread count.
protected  java.net.InetAddress address
          Address for the server socket.
protected  java.lang.String algorithm
           
protected  int backlog
          Allows the server developer to specify the backlog that should be used for server sockets.
static java.lang.String CERTIFICATE_KEY
          The Request attribute key for the client certificate chain.
static java.lang.String CIPHER_SUITE_KEY
          The Request attribute key for the cipher suite.
protected  java.lang.String ciphers
           
protected  java.lang.String[] ciphersarr
           
protected  boolean clientAuth
           
protected  int curThreads
          Current worker threads count.
protected  int curThreadsBusy
          Current worker threads busy count.
protected  boolean daemon
          The default is true - the created threads will be in daemon mode.
protected  java.util.concurrent.ConcurrentLinkedQueue<NioEndpoint.PollerEvent> eventCache
          Cache for poller events
protected  java.util.concurrent.Executor executor
          External Executor based thread pool.
protected  int firstReadTimeout
          Timeout on first request read before going to the poller, in ms.
protected  NioEndpoint.Handler handler
          Handling of accepted sockets.
protected  boolean initialized
          Track the initialization state of the endpoint.
static java.lang.String KEY_SIZE_KEY
          The Request attribute key for the key size.
protected  java.util.concurrent.ConcurrentLinkedQueue<NioEndpoint.KeyAttachment> keyCache
          Cache for key attachment objects
protected  java.lang.String keystoreFile
           
protected  java.lang.String keystorePass
           
protected  java.lang.String keystoreType
           
protected static Log log
           
protected  int maxThreads
          Maximum amount of worker threads.
protected  java.lang.String name
          Name of the thread pool, which will be used for naming child threads.
protected  java.util.concurrent.ConcurrentLinkedQueue<NioChannel> nioChannels
          Bytebuffer cache, each channel holds a set of buffers (two, except for SSL holds four)
static int OP_REGISTER
           
protected  boolean paused
          Will be set to true whenever the endpoint is paused.
protected  int pollerRoundRobin
           
protected  NioEndpoint.Poller[] pollers
          The socket poller.
protected  int pollerThreadCount
          Poller thread count.
protected  int port
          Server socket port.
protected  boolean running
          Running state of the endpoint.
protected  boolean secure
           
protected  NioSelectorPool selectorPool
           
protected  long selectorTimeout
           
protected  int sequence
          Sequence number used to generate thread names.
protected  java.nio.channels.ServerSocketChannel serverSock
          Server socket "pointer".
static java.lang.String SESSION_ID_KEY
          The Request attribute key for the session id.
protected static StringManager sm
           
protected  SocketProperties socketProperties
           
protected  javax.net.ssl.SSLContext sslContext
           
protected  boolean SSLEnabled
          SSL engine.
protected  java.lang.String sslEnabledProtocols
           
protected  java.lang.String[] sslEnabledProtocolsarr
           
protected  java.lang.String sslProtocol
           
protected  int threadPriority
          Priority of the acceptor and poller threads.
protected  boolean useComet
          Allow comet request handling.
protected  NioEndpoint.WorkerStack workers
          Available workers.
 
Constructor Summary
NioEndpoint()
           
 
Method Summary
protected  javax.net.ssl.SSLEngine createSSLEngine()
           
protected  NioEndpoint.Worker createWorkerThread()
          Create (or allocate) and return an available processor for use in processing a specific HTTP request, if possible.
 void destroy()
          Deallocate APR memory pools, and close server socket.
 int getAcceptorThreadCount()
           
 java.net.InetAddress getAddress()
           
 java.lang.String getAlgorithm()
           
 int getBacklog()
           
 java.lang.String getCiphers()
           
 boolean getClientAuth()
           
 NioEndpoint.Poller getCometPoller0()
          The socket poller used for Comet support.
 int getCurrentThreadCount()
          Return the amount of threads that are managed by the pool.
 int getCurrentThreadsBusy()
          Return the amount of threads currently busy.
 boolean getDaemon()
           
 java.util.concurrent.Executor getExecutor()
           
 int getFirstReadTimeout()
           
 NioEndpoint.Handler getHandler()
           
 int getKeepAliveCount()
          Number of keepalive sockets.
 java.lang.String getKeystore()
           
 java.lang.String getKeystoreFile()
           
 java.lang.String getKeystorePass()
           
 java.lang.String getKeystoreType()
           
 int getMaxSpareThreads()
          Dummy maxSpareThreads property.
 int getMaxThreads()
           
 int getMinSpareThreads()
          Dummy minSpareThreads property.
 java.lang.String getName()
           
 NioEndpoint.Poller getPoller0()
           
 int getPollerThreadCount()
           
 int getPort()
           
 int getReadBufSize()
           
 boolean getSecure()
           
 NioSelectorPool getSelectorPool()
           
 long getSelectorTimeout()
           
protected  int getSequence()
          Get a sequence number used for thread naming.
 SocketProperties getSocketProperties()
           
 int getSoLinger()
          Socket linger.
 int getSoTimeout()
          Socket timeout.
 javax.net.ssl.SSLContext getSSLContext()
           
 java.lang.String getSslProtocol()
           
 boolean getTcpNoDelay()
          Socket TCP no delay.
 int getThreadPriority()
           
 boolean getUseComet()
           
protected  NioEndpoint.Worker getWorkerThread()
          Return a new worker thread, and block while to worker is available.
 int getWriteBufSize()
           
 void init()
          Initialize the endpoint.
 boolean isPaused()
          Return the state of the endpoint.
 boolean isRunning()
          Return the state of the endpoint.
 boolean isSSLEnabled()
           
protected  NioEndpoint.Worker newWorkerThread()
          Create and return a new processor suitable for processing HTTP requests and returning the corresponding responses.
 void pause()
          Pause the endpoint, which will make it stop accepting new sockets.
protected  boolean processSocket(NioChannel socket)
          Process given socket.
protected  boolean processSocket(NioChannel socket, SocketStatus status)
          Process given socket for an event.
protected  boolean processSocket(java.nio.channels.SocketChannel socket)
           
protected  void recycleWorkerThread(NioEndpoint.Worker workerThread)
          Recycle the specified Processor so that it can be used again.
 void resume()
          Resume the endpoint, which will make it start accepting new sockets again.
 void setAcceptorThreadCount(int acceptorThreadCount)
           
 void setAddress(java.net.InetAddress address)
           
 void setAlgorithm(java.lang.String s)
           
 void setBacklog(int backlog)
           
 void setCiphers(java.lang.String s)
           
 void setClientAuth(boolean b)
           
 void setDaemon(boolean b)
           
 void setExecutor(java.util.concurrent.Executor executor)
           
 void setFirstReadTimeout(int firstReadTimeout)
           
 void setHandler(NioEndpoint.Handler handler)
           
 void setKeystore(java.lang.String s)
           
 void setKeystoreFile(java.lang.String s)
           
 void setKeystorePass(java.lang.String s)
           
 void setKeystoreType(java.lang.String s)
           
 void setMaxThreads(int maxThreads)
           
 void setName(java.lang.String name)
           
 void setPollerThreadCount(int pollerThreadCount)
           
 void setPort(int port)
           
 void setProperty(java.lang.String name, java.lang.String value)
          Generic properties, introspected
 void setSecure(boolean b)
           
 void setSelectorPool(NioSelectorPool selectorPool)
           
 void setSelectorTimeout(long timeout)
           
protected  boolean setSocketOptions(java.nio.channels.SocketChannel socket)
          Process the specified connection.
 void setSocketProperties(SocketProperties socketProperties)
           
 void setSoLinger(int soLinger)
           
 void setSoTimeout(int soTimeout)
           
 void setSSLContext(javax.net.ssl.SSLContext c)
           
 void setSSLEnabled(boolean SSLEnabled)
           
 void setSslEnabledProtocols(java.lang.String s)
           
 void setSslProtocol(java.lang.String s)
           
 void setTcpNoDelay(boolean tcpNoDelay)
           
 void setThreadPriority(int threadPriority)
           
 void setUseComet(boolean useComet)
           
 void start()
          Start the APR endpoint, creating acceptor, poller threads.
 void stop()
          Stop the endpoint.
protected  void unlockAccept()
          Unlock the server socket accept using a bogus connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Log log

sm

protected static StringManager sm

CIPHER_SUITE_KEY

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

See Also:
Constant Field Values

KEY_SIZE_KEY

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

See Also:
Constant Field Values

CERTIFICATE_KEY

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

See Also:
Constant Field Values

SESSION_ID_KEY

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

See Also:
Constant Field Values

OP_REGISTER

public static final int OP_REGISTER
See Also:
Constant Field Values

workers

protected NioEndpoint.WorkerStack workers
Available workers.


running

protected volatile boolean running
Running state of the endpoint.


paused

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


initialized

protected boolean initialized
Track the initialization state of the endpoint.


curThreadsBusy

protected int curThreadsBusy
Current worker threads busy count.


curThreads

protected int curThreads
Current worker threads count.


sequence

protected int sequence
Sequence number used to generate thread names.


selectorPool

protected NioSelectorPool selectorPool

serverSock

protected java.nio.channels.ServerSocketChannel serverSock
Server socket "pointer".


keyCache

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


eventCache

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


nioChannels

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


executor

protected java.util.concurrent.Executor executor
External Executor based thread pool.


maxThreads

protected int maxThreads
Maximum amount of worker threads.


threadPriority

protected int threadPriority
Priority of the acceptor and poller threads.


port

protected int port
Server socket port.


address

protected java.net.InetAddress address
Address for the server socket.


handler

protected NioEndpoint.Handler handler
Handling of accepted sockets.


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.


socketProperties

protected SocketProperties socketProperties

firstReadTimeout

protected int firstReadTimeout
Timeout on first request read before going to the poller, in ms.


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.


name

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


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.


pollerRoundRobin

protected int pollerRoundRobin

keystoreFile

protected java.lang.String keystoreFile

algorithm

protected java.lang.String algorithm

clientAuth

protected boolean clientAuth

keystorePass

protected java.lang.String keystorePass

keystoreType

protected java.lang.String keystoreType

sslProtocol

protected java.lang.String sslProtocol

sslEnabledProtocols

protected java.lang.String sslEnabledProtocols

sslEnabledProtocolsarr

protected java.lang.String[] sslEnabledProtocolsarr

ciphers

protected java.lang.String ciphers

ciphersarr

protected java.lang.String[] ciphersarr

SSLEnabled

protected boolean SSLEnabled
SSL engine.


secure

protected boolean secure

sslContext

protected javax.net.ssl.SSLContext sslContext
Constructor Detail

NioEndpoint

public NioEndpoint()
Method Detail

setExecutor

public void setExecutor(java.util.concurrent.Executor executor)

getExecutor

public java.util.concurrent.Executor getExecutor()

setMaxThreads

public void setMaxThreads(int maxThreads)

getMaxThreads

public int getMaxThreads()

setThreadPriority

public void setThreadPriority(int threadPriority)

getThreadPriority

public int getThreadPriority()

getPort

public int getPort()

setPort

public void setPort(int port)

getAddress

public java.net.InetAddress getAddress()

setAddress

public void setAddress(java.net.InetAddress address)

setHandler

public void setHandler(NioEndpoint.Handler handler)

getHandler

public NioEndpoint.Handler getHandler()

setBacklog

public void setBacklog(int backlog)

getBacklog

public int getBacklog()

getTcpNoDelay

public boolean getTcpNoDelay()
Socket TCP no delay.


setTcpNoDelay

public void setTcpNoDelay(boolean tcpNoDelay)

getSoLinger

public int getSoLinger()
Socket linger.


setSoLinger

public void setSoLinger(int soLinger)

getSoTimeout

public int getSoTimeout()
Socket timeout.


setSoTimeout

public void setSoTimeout(int soTimeout)

getFirstReadTimeout

public int getFirstReadTimeout()

setFirstReadTimeout

public void setFirstReadTimeout(int firstReadTimeout)

setDaemon

public void setDaemon(boolean b)

getDaemon

public boolean getDaemon()

setName

public void setName(java.lang.String name)

getName

public java.lang.String getName()

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

getCometPoller0

public NioEndpoint.Poller getCometPoller0()
The socket poller used for Comet support.


getMaxSpareThreads

public int getMaxSpareThreads()
Dummy maxSpareThreads property.


getMinSpareThreads

public int getMinSpareThreads()
Dummy minSpareThreads property.


setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Generic properties, introspected


getKeystoreFile

public java.lang.String getKeystoreFile()

setKeystoreFile

public void setKeystoreFile(java.lang.String s)

setKeystore

public void setKeystore(java.lang.String s)

getKeystore

public java.lang.String getKeystore()

getAlgorithm

public java.lang.String getAlgorithm()

setAlgorithm

public void setAlgorithm(java.lang.String s)

getClientAuth

public boolean getClientAuth()

setClientAuth

public void setClientAuth(boolean b)

getKeystorePass

public java.lang.String getKeystorePass()

setKeystorePass

public void setKeystorePass(java.lang.String s)

getKeystoreType

public java.lang.String getKeystoreType()

setKeystoreType

public void setKeystoreType(java.lang.String s)

getSslProtocol

public java.lang.String getSslProtocol()

setSslProtocol

public void setSslProtocol(java.lang.String s)

setSslEnabledProtocols

public void setSslEnabledProtocols(java.lang.String s)

getCiphers

public java.lang.String getCiphers()

setCiphers

public void setCiphers(java.lang.String s)

isSSLEnabled

public boolean isSSLEnabled()

setSSLEnabled

public void setSSLEnabled(boolean SSLEnabled)

getSecure

public boolean getSecure()

setSecure

public void setSecure(boolean b)

setSelectorPool

public void setSelectorPool(NioSelectorPool selectorPool)

setSocketProperties

public void setSocketProperties(SocketProperties socketProperties)

getSSLContext

public javax.net.ssl.SSLContext getSSLContext()

setSSLContext

public void setSSLContext(javax.net.ssl.SSLContext c)

getKeepAliveCount

public int getKeepAliveCount()
Number of keepalive sockets.


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 currently busy.

Returns:
the amount of threads currently busy

isRunning

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

Returns:
true if the endpoint is running, false otherwise

isPaused

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

Returns:
true if the endpoint is paused, false otherwise

init

public void init()
          throws java.lang.Exception
Initialize the endpoint.

Throws:
java.lang.Exception

start

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

Throws:
java.lang.Exception

pause

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


resume

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


stop

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


destroy

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

Throws:
java.lang.Exception

getSequence

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


getWriteBufSize

public int getWriteBufSize()

getReadBufSize

public int getReadBufSize()

getSelectorPool

public NioSelectorPool getSelectorPool()

getSocketProperties

public SocketProperties getSocketProperties()

unlockAccept

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


setSocketOptions

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


createSSLEngine

protected javax.net.ssl.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.


newWorkerThread

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


getWorkerThread

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


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

processSocket

protected boolean processSocket(java.nio.channels.SocketChannel socket)

processSocket

protected boolean processSocket(NioChannel socket)
Process given socket.


processSocket

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



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