org.apache.tomcat.util.net

Class JIoEndpoint

public class JIoEndpoint extends Object

Handle incoming TCP connections. This class implement a simple server model: one listener thread accepts on a socket and creates a new worker thread for each incoming connection. More advanced Endpoints will reuse the threads, use queues, etc.

Author: James Duncan Davidson Jason Hunter James Todd Costin Manolache Gal Shachor Yoav Shapira Remy Maucherat

Nested Class Summary
protected classJIoEndpoint.Acceptor
Server socket acceptor thread.
interfaceJIoEndpoint.Handler
Bare bones interface used for socket processing.
protected classJIoEndpoint.SocketProcessor
This class is the equivalent of the Worker, but will simply use in an external Executor thread pool.
protected classJIoEndpoint.Worker
classJIoEndpoint.WorkerStack
Field Summary
protected intacceptorThreadCount
Acceptor thread count.
protected InetAddressaddress
Address for the server socket.
protected intbacklog
Allows the server developer to specify the backlog that should be used for server sockets.
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 Executorexecutor
External Executor based thread pool.
protected JIoEndpoint.Handlerhandler
Handling of accepted sockets.
protected booleaninitialized
Track the initialization state of the endpoint.
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 booleanpaused
Will be set to true whenever the endpoint is paused.
protected intport
Server socket port.
protected booleanrunning
Running state of the endpoint.
protected intsequence
Sequence number used to generate thread names.
protected ServerSocketserverSocket
Associated server socket.
protected ServerSocketFactoryserverSocketFactory
Server socket factory.
protected StringManagersm
protected intsoLinger
Socket linger.
protected intsoTimeout
Socket timeout.
static StringSESSION_ID_KEY
The Request attribute key for the session id.
protected booleantcpNoDelay
Socket TCP no delay.
protected intthreadPriority
Priority of the acceptor and poller threads.
protected intunlockTimeout
Unlock timeout.
protected JIoEndpoint.WorkerStackworkers
Available workers.
Method Summary
protected JIoEndpoint.WorkercreateWorkerThread()
Create (or allocate) and return an available processor for use in processing a specific HTTP request, if possible.
voiddestroy()
Deallocate APR memory pools, and close server socket.
intgetAcceptorThreadCount()
InetAddressgetAddress()
intgetBacklog()
intgetCurrentThreadCount()
Return the amount of threads that are managed by the pool.
intgetCurrentThreadsBusy()
Return the amount of threads that are in use
booleangetDaemon()
ExecutorgetExecutor()
JIoEndpoint.HandlergetHandler()
intgetMaxThreads()
StringgetName()
intgetPort()
ServerSocketFactorygetServerSocketFactory()
intgetSoLinger()
intgetSoTimeout()
booleangetTcpNoDelay()
intgetThreadPriority()
intgetUnlockTimeout()
protected JIoEndpoint.WorkergetWorkerThread()
Return a new worker thread, and block while to worker is available.
voidinit()
booleanisPaused()
booleanisRunning()
protected JIoEndpoint.WorkernewWorkerThread()
Create and return a new processor suitable for processing HTTP requests and returning the corresponding responses.
voidpause()
protected booleanprocessSocket(Socket socket)
Process given socket.
protected voidrecycleWorkerThread(JIoEndpoint.Worker workerThread)
Recycle the specified Processor so that it can be used again.
voidresume()
voidsetAcceptorThreadCount(int acceptorThreadCount)
voidsetAddress(InetAddress address)
voidsetBacklog(int backlog)
voidsetDaemon(boolean b)
voidsetExecutor(Executor executor)
voidsetHandler(JIoEndpoint.Handler handler)
voidsetMaxThreads(int maxThreads)
voidsetName(String name)
voidsetPort(int port)
voidsetServerSocketFactory(ServerSocketFactory factory)
protected booleansetSocketOptions(Socket socket)
Set the options for the current socket.
voidsetSoLinger(int soLinger)
voidsetSoTimeout(int soTimeout)
voidsetTcpNoDelay(boolean tcpNoDelay)
voidsetThreadPriority(int threadPriority)
voidsetUnlockTimeout(int unlockTimeout)
voidstart()
voidstop()
protected voidunlockAccept()
Unlock the accept by using a local connection.

Field Detail

acceptorThreadCount

protected int acceptorThreadCount
Acceptor thread count.

address

protected InetAddress address
Address for the server socket.

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.

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.

executor

protected Executor executor
External Executor based thread pool.

handler

protected JIoEndpoint.Handler handler
Handling of accepted sockets.

initialized

protected boolean initialized
Track the initialization state of the endpoint.

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.

paused

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

port

protected int port
Server socket port.

running

protected volatile boolean running
Running state of the endpoint.

sequence

protected int sequence
Sequence number used to generate thread names.

serverSocket

protected ServerSocket serverSocket
Associated server socket.

serverSocketFactory

protected ServerSocketFactory serverSocketFactory
Server socket factory.

sm

protected StringManager sm

soLinger

protected int soLinger
Socket linger.

soTimeout

protected int soTimeout
Socket timeout.

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.

tcpNoDelay

protected boolean tcpNoDelay
Socket TCP no delay.

threadPriority

protected int threadPriority
Priority of the acceptor and poller threads.

unlockTimeout

protected int unlockTimeout
Unlock timeout.

workers

protected JIoEndpoint.WorkerStack workers
Available workers.

Method Detail

createWorkerThread

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

destroy

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

getAcceptorThreadCount

public int getAcceptorThreadCount()

getAddress

public InetAddress getAddress()

getBacklog

public int getBacklog()

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 JIoEndpoint.Handler getHandler()

getMaxThreads

public int getMaxThreads()

getName

public String getName()

getPort

public int getPort()

getServerSocketFactory

public ServerSocketFactory getServerSocketFactory()

getSoLinger

public int getSoLinger()

getSoTimeout

public int getSoTimeout()

getTcpNoDelay

public boolean getTcpNoDelay()

getThreadPriority

public int getThreadPriority()

getUnlockTimeout

public int getUnlockTimeout()

getWorkerThread

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

init

public void init()

isPaused

public boolean isPaused()

isRunning

public boolean isRunning()

newWorkerThread

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

pause

public void pause()

processSocket

protected boolean processSocket(Socket socket)
Process given socket.

recycleWorkerThread

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

Parameters: workerThread The processor to be recycled

resume

public void resume()

setAcceptorThreadCount

public void setAcceptorThreadCount(int acceptorThreadCount)

setAddress

public void setAddress(InetAddress address)

setBacklog

public void setBacklog(int backlog)

setDaemon

public void setDaemon(boolean b)

setExecutor

public void setExecutor(Executor executor)

setHandler

public void setHandler(JIoEndpoint.Handler handler)

setMaxThreads

public void setMaxThreads(int maxThreads)

setName

public void setName(String name)

setPort

public void setPort(int port)

setServerSocketFactory

public void setServerSocketFactory(ServerSocketFactory factory)

setSocketOptions

protected boolean setSocketOptions(Socket socket)
Set the options for the current socket.

setSoLinger

public void setSoLinger(int soLinger)

setSoTimeout

public void setSoTimeout(int soTimeout)

setTcpNoDelay

public void setTcpNoDelay(boolean tcpNoDelay)

setThreadPriority

public void setThreadPriority(int threadPriority)

setUnlockTimeout

public void setUnlockTimeout(int unlockTimeout)

start

public void start()

stop

public void stop()

unlockAccept

protected void unlockAccept()
Unlock the accept by using a local connection.
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.