org.apache.tomcat.util.net
Class AprEndpoint

java.lang.Object
  extended byorg.apache.tomcat.util.net.AprEndpoint

public class AprEndpoint
extends java.lang.Object

APR 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

Nested Class Summary
protected  class AprEndpoint.Acceptor
          Server socket acceptor thread.
static interface AprEndpoint.Handler
          Bare bones interface used for socket processing.
 class AprEndpoint.Poller
          Poller class.
 class AprEndpoint.Sendfile
          Sendfile class.
static class AprEndpoint.SendfileData
          SendfileData class.
protected  class AprEndpoint.Worker
          Server processor class.
 class AprEndpoint.WorkerStack
           
 
Field Summary
protected  int acceptorThreadCount
          Acceptor thread count.
protected  java.net.InetAddress address
          Address for the server socket.
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  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  int firstReadTimeout
          Timeout on first request read before going to the poller, in ms.
protected  AprEndpoint.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 static org.apache.commons.logging.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  boolean paused
          Will be set to true whenever the endpoint is paused.
protected  int pollerRoundRobin
           
protected  AprEndpoint.Poller[] pollers
          The socket poller.
protected  int pollerSize
          Size of the socket poller.
protected  int pollerThreadCount
          Poller thread count.
protected  int pollTime
          Poll interval, in microseconds.
protected  int port
          Server socket port.
protected  long rootPool
          Root APR memory pool.
protected  boolean running
          Running state of the endpoint.
protected  int sendfileRoundRobin
           
protected  AprEndpoint.Sendfile[] sendfiles
          The static file sender.
protected  int sendfileSize
          Size of the sendfile (= concurrent files which can be served).
protected  int sendfileThreadCount
          Sendfile thread count.
protected  int sequence
          Sequence number used to generate thread names.
protected  long serverSock
          Server socket "pointer".
protected  long serverSockPool
          APR memory pool for the server socket.
static java.lang.String SESSION_ID_KEY
          The Request attribute key for the session id.
protected static StringManager sm
           
protected  int soLinger
          Socket linger.
protected  int soTimeout
          Socket timeout.
protected  java.lang.String SSLCACertificateFile
          SSL CA certificate file.
protected  java.lang.String SSLCACertificatePath
          SSL CA certificate path.
protected  java.lang.String SSLCARevocationFile
          SSL CA revocation file.
protected  java.lang.String SSLCARevocationPath
          SSL CA revocation path.
protected  java.lang.String SSLCertificateChainFile
          SSL certificate chain file.
protected  java.lang.String SSLCertificateFile
          SSL certificate file.
protected  java.lang.String SSLCertificateKeyFile
          SSL certificate key file.
protected  java.lang.String SSLCipherSuite
          SSL cipher suite.
protected  long sslContext
          SSL context.
protected  java.lang.String SSLEngine
          SSL engine.
protected  java.lang.String SSLPassword
          SSL password (if a cert is encrypted, and no password has been provided, a callback will ask for a password).
protected  java.lang.String SSLProtocol
          SSL protocols.
protected  java.lang.String SSLVerifyClient
          SSL verify client.
protected  int SSLVerifyDepth
          SSL verify depth.
protected  boolean tcpNoDelay
          Socket TCP no delay.
protected  int threadPriority
          Priority of the acceptor and poller threads.
protected  boolean useSendfile
          Use endfile for sending static files.
protected  AprEndpoint.WorkerStack workers
          Available workers.
 
Constructor Summary
AprEndpoint()
           
 
Method Summary
protected  long allocatePoller(int size, long pool, int timeout)
          Allocate a new poller of the specified size.
protected  AprEndpoint.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()
           
 int getBacklog()
           
 int getCurrentThreadCount()
          Return the amount of threads that are managed by the pool.
 int getCurrentThreadsBusy()
          Return the amount of threads currently busy.
 boolean getDaemon()
           
 int getFirstReadTimeout()
           
 AprEndpoint.Handler getHandler()
           
 int getKeepAliveCount()
          Number of keepalive sockets.
 int getMaxHeaderCount()
           
 int getMaxSpareThreads()
          Dummy maxSpareThreads property.
 int getMaxThreads()
           
 int getMinSpareThreads()
          Dummy minSpareThreads property.
 java.lang.String getName()
           
 AprEndpoint.Poller getPoller()
           
 int getPollerSize()
           
 int getPollerThreadCount()
           
 int getPollTime()
           
 int getPort()
           
 AprEndpoint.Sendfile getSendfile()
           
 int getSendfileCount()
          Number of sendfile sockets.
 int getSendfileSize()
           
 int getSendfileThreadCount()
           
protected  int getSequence()
          Get a sequence number used for thread naming.
 int getSoLinger()
           
 int getSoTimeout()
           
 java.lang.String getSSLCACertificateFile()
           
 java.lang.String getSSLCACertificatePath()
           
 java.lang.String getSSLCARevocationFile()
           
 java.lang.String getSSLCARevocationPath()
           
 java.lang.String getSSLCertificateChainFile()
           
 java.lang.String getSSLCertificateFile()
           
 java.lang.String getSSLCertificateKeyFile()
           
 java.lang.String getSSLCipherSuite()
           
 java.lang.String getSSLEngine()
           
 java.lang.String getSSLPassword()
           
 java.lang.String getSSLProtocol()
           
 java.lang.String getSSLVerifyClient()
           
 int getSSLVerifyDepth()
           
 boolean getTcpNoDelay()
           
 int getThreadPriority()
           
 boolean getUseSendfile()
           
protected  AprEndpoint.Worker getWorkerThread()
          Return a new worker thread, and block while to worker is available.
 void init()
          Initialize the endpoint.
 boolean isPaused()
          Return the state of the endpoint.
 boolean isRunning()
          Return the state of the endpoint.
protected  AprEndpoint.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  void recycleWorkerThread(AprEndpoint.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 setBacklog(int backlog)
           
 void setDaemon(boolean b)
           
 void setFirstReadTimeout(int firstReadTimeout)
           
 void setHandler(AprEndpoint.Handler handler)
           
 void setMaxHeaderCount(int maxHeaderCount)
           
 void setMaxThreads(int maxThreads)
           
 void setName(java.lang.String name)
           
 void setPollerSize(int pollerSize)
           
 void setPollerThreadCount(int pollerThreadCount)
           
 void setPollTime(int pollTime)
           
 void setPort(int port)
           
 void setSendfileSize(int sendfileSize)
           
 void setSendfileThreadCount(int sendfileThreadCount)
           
protected  boolean setSocketOptions(long socket)
          Process the specified connection.
 void setSoLinger(int soLinger)
           
 void setSoTimeout(int soTimeout)
           
 void setSSLCACertificateFile(java.lang.String SSLCACertificateFile)
           
 void setSSLCACertificatePath(java.lang.String SSLCACertificatePath)
           
 void setSSLCARevocationFile(java.lang.String SSLCARevocationFile)
           
 void setSSLCARevocationPath(java.lang.String SSLCARevocationPath)
           
 void setSSLCertificateChainFile(java.lang.String SSLCertificateChainFile)
           
 void setSSLCertificateFile(java.lang.String SSLCertificateFile)
           
 void setSSLCertificateKeyFile(java.lang.String SSLCertificateKeyFile)
           
 void setSSLCipherSuite(java.lang.String SSLCipherSuite)
           
 void setSSLEngine(java.lang.String SSLEngine)
           
 void setSSLPassword(java.lang.String SSLPassword)
           
 void setSSLProtocol(java.lang.String SSLProtocol)
           
 void setSSLVerifyClient(java.lang.String SSLVerifyClient)
           
 void setSSLVerifyDepth(int SSLVerifyDepth)
           
 void setTcpNoDelay(boolean tcpNoDelay)
           
 void setThreadPriority(int threadPriority)
           
 void setUseSendfile(boolean useSendfile)
           
 void start()
          Start the APR endpoint, creating acceptor, poller and sendfile threads.
 void stop()
          Stop the endpoint.
protected  void unlockAccept()
          Unlock the server socket accept using a bugus connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.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

workers

protected AprEndpoint.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.


rootPool

protected long rootPool
Root APR memory pool.


serverSock

protected long serverSock
Server socket "pointer".


serverSockPool

protected long serverSockPool
APR memory pool for the server socket.


sslContext

protected long sslContext
SSL context.


maxThreads

protected int maxThreads
Maximum amount of worker threads.


threadPriority

protected int threadPriority
Priority of the acceptor and poller threads.


pollerSize

protected int pollerSize
Size of the socket poller.


sendfileSize

protected int sendfileSize
Size of the sendfile (= concurrent files which can be served).


port

protected int port
Server socket port.


address

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


handler

protected AprEndpoint.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.


tcpNoDelay

protected boolean tcpNoDelay
Socket TCP no delay.


soLinger

protected int soLinger
Socket linger.


soTimeout

protected int soTimeout
Socket timeout.


firstReadTimeout

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


pollTime

protected int pollTime
Poll interval, in microseconds. The smaller the value, the more CPU the poller will use, but the more responsive to activity it will be.


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.


useSendfile

protected boolean useSendfile
Use endfile for sending static files.


acceptorThreadCount

protected int acceptorThreadCount
Acceptor thread count.


sendfileThreadCount

protected int sendfileThreadCount
Sendfile thread count.


pollerThreadCount

protected int pollerThreadCount
Poller thread count.


pollers

protected AprEndpoint.Poller[] pollers
The socket poller.


pollerRoundRobin

protected int pollerRoundRobin

sendfiles

protected AprEndpoint.Sendfile[] sendfiles
The static file sender.


sendfileRoundRobin

protected int sendfileRoundRobin

SSLEngine

protected java.lang.String SSLEngine
SSL engine.


SSLProtocol

protected java.lang.String SSLProtocol
SSL protocols.


SSLPassword

protected java.lang.String SSLPassword
SSL password (if a cert is encrypted, and no password has been provided, a callback will ask for a password).


SSLCipherSuite

protected java.lang.String SSLCipherSuite
SSL cipher suite.


SSLCertificateFile

protected java.lang.String SSLCertificateFile
SSL certificate file.


SSLCertificateKeyFile

protected java.lang.String SSLCertificateKeyFile
SSL certificate key file.


SSLCertificateChainFile

protected java.lang.String SSLCertificateChainFile
SSL certificate chain file.


SSLCACertificatePath

protected java.lang.String SSLCACertificatePath
SSL CA certificate path.


SSLCACertificateFile

protected java.lang.String SSLCACertificateFile
SSL CA certificate file.


SSLCARevocationPath

protected java.lang.String SSLCARevocationPath
SSL CA revocation path.


SSLCARevocationFile

protected java.lang.String SSLCARevocationFile
SSL CA revocation file.


SSLVerifyClient

protected java.lang.String SSLVerifyClient
SSL verify client.


SSLVerifyDepth

protected int SSLVerifyDepth
SSL verify depth.

Constructor Detail

AprEndpoint

public AprEndpoint()
Method Detail

setMaxThreads

public void setMaxThreads(int maxThreads)

getMaxThreads

public int getMaxThreads()

setThreadPriority

public void setThreadPriority(int threadPriority)

getThreadPriority

public int getThreadPriority()

setPollerSize

public void setPollerSize(int pollerSize)

getPollerSize

public int getPollerSize()

setSendfileSize

public void setSendfileSize(int sendfileSize)

getSendfileSize

public int getSendfileSize()

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(AprEndpoint.Handler handler)

getHandler

public AprEndpoint.Handler getHandler()

setBacklog

public void setBacklog(int backlog)

getBacklog

public int getBacklog()

getTcpNoDelay

public boolean getTcpNoDelay()

setTcpNoDelay

public void setTcpNoDelay(boolean tcpNoDelay)

getSoLinger

public int getSoLinger()

setSoLinger

public void setSoLinger(int soLinger)

getSoTimeout

public int getSoTimeout()

setSoTimeout

public void setSoTimeout(int soTimeout)

getFirstReadTimeout

public int getFirstReadTimeout()

setFirstReadTimeout

public void setFirstReadTimeout(int firstReadTimeout)

getPollTime

public int getPollTime()

setPollTime

public void setPollTime(int pollTime)

setDaemon

public void setDaemon(boolean b)

getDaemon

public boolean getDaemon()

setName

public void setName(java.lang.String name)

getName

public java.lang.String getName()

setUseSendfile

public void setUseSendfile(boolean useSendfile)

getUseSendfile

public boolean getUseSendfile()

setAcceptorThreadCount

public void setAcceptorThreadCount(int acceptorThreadCount)

getAcceptorThreadCount

public int getAcceptorThreadCount()

setSendfileThreadCount

public void setSendfileThreadCount(int sendfileThreadCount)

getSendfileThreadCount

public int getSendfileThreadCount()

setPollerThreadCount

public void setPollerThreadCount(int pollerThreadCount)

getPollerThreadCount

public int getPollerThreadCount()

getPoller

public AprEndpoint.Poller getPoller()

getSendfile

public AprEndpoint.Sendfile getSendfile()

getMaxSpareThreads

public int getMaxSpareThreads()
Dummy maxSpareThreads property.


getMinSpareThreads

public int getMinSpareThreads()
Dummy minSpareThreads property.


getSSLEngine

public java.lang.String getSSLEngine()

setSSLEngine

public void setSSLEngine(java.lang.String SSLEngine)

getSSLProtocol

public java.lang.String getSSLProtocol()

setSSLProtocol

public void setSSLProtocol(java.lang.String SSLProtocol)

getSSLPassword

public java.lang.String getSSLPassword()

setSSLPassword

public void setSSLPassword(java.lang.String SSLPassword)

getSSLCipherSuite

public java.lang.String getSSLCipherSuite()

setSSLCipherSuite

public void setSSLCipherSuite(java.lang.String SSLCipherSuite)

getSSLCertificateFile

public java.lang.String getSSLCertificateFile()

setSSLCertificateFile

public void setSSLCertificateFile(java.lang.String SSLCertificateFile)

getSSLCertificateKeyFile

public java.lang.String getSSLCertificateKeyFile()

setSSLCertificateKeyFile

public void setSSLCertificateKeyFile(java.lang.String SSLCertificateKeyFile)

getSSLCertificateChainFile

public java.lang.String getSSLCertificateChainFile()

setSSLCertificateChainFile

public void setSSLCertificateChainFile(java.lang.String SSLCertificateChainFile)

getSSLCACertificatePath

public java.lang.String getSSLCACertificatePath()

setSSLCACertificatePath

public void setSSLCACertificatePath(java.lang.String SSLCACertificatePath)

getSSLCACertificateFile

public java.lang.String getSSLCACertificateFile()

setSSLCACertificateFile

public void setSSLCACertificateFile(java.lang.String SSLCACertificateFile)

getSSLCARevocationPath

public java.lang.String getSSLCARevocationPath()

setSSLCARevocationPath

public void setSSLCARevocationPath(java.lang.String SSLCARevocationPath)

getSSLCARevocationFile

public java.lang.String getSSLCARevocationFile()

setSSLCARevocationFile

public void setSSLCARevocationFile(java.lang.String SSLCARevocationFile)

getSSLVerifyClient

public java.lang.String getSSLVerifyClient()

setSSLVerifyClient

public void setSSLVerifyClient(java.lang.String SSLVerifyClient)

getSSLVerifyDepth

public int getSSLVerifyDepth()

setSSLVerifyDepth

public void setSSLVerifyDepth(int SSLVerifyDepth)

getMaxHeaderCount

public int getMaxHeaderCount()

setMaxHeaderCount

public void setMaxHeaderCount(int maxHeaderCount)

getKeepAliveCount

public int getKeepAliveCount()
Number of keepalive sockets.


getSendfileCount

public int getSendfileCount()
Number of sendfile 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 and sendfile 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.


unlockAccept

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


setSocketOptions

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


createWorkerThread

protected AprEndpoint.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 AprEndpoint.Worker newWorkerThread()
Create and return a new processor suitable for processing HTTP requests and returning the corresponding responses.


getWorkerThread

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


recycleWorkerThread

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

Parameters:
workerThread - The processor to be recycled

allocatePoller

protected long allocatePoller(int size,
                              long pool,
                              int timeout)
Allocate a new poller of the specified size.



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