Package org.apache.tomcat.util.net
Class AprEndpoint
- All Implemented Interfaces:
SSLContext.SNICallBack
APR tailored thread pool, providing the following services:
- Socket acceptor thread
- Socket poller thread
- Sendfile thread
- Worker threads pool
- Author:
- Mladen Turk, Remy Maucherat
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classclassclassstatic classSendfileData class.static classstatic classprotected classThis class is the equivalent of the Worker, but will simply use in an external Executor thread pool.static classprotected classThis class is the equivalent of the Worker, but will simply use in an external Executor thread pool.Nested classes/interfaces inherited from class org.apache.tomcat.util.net.AbstractEndpoint
AbstractEndpoint.BindState, AbstractEndpoint.Handler<S> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanDefer accept.protected AprEndpoint.PollerThe socket poller.protected intPoll interval, in microseconds.protected longRoot APR memory pool.protected AprEndpoint.SendfileThe static file sender.protected intSize of the sendfile (= concurrent files which can be served).protected longServer socket "pointer".protected longAPR memory pool for the server socket.protected longSSL context.Fields inherited from class org.apache.tomcat.util.net.AbstractEndpoint
acceptor, acceptorThreadCount, acceptorThreadPriority, attributes, connections, internalExecutor, negotiableProtocols, paused, processorCache, running, sm, socketProperties, sslHostConfigs, threadPriority -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected longallocatePoller(int size, long pool, int timeout) Allocate a new poller of the specified size.voidbind()Initialize the endpoint.protected SocketProcessorBase<Long>createSocketProcessor(SocketWrapperBase<Long> socketWrapper, SocketEvent event) protected voidcreateSSLContext(SSLHostConfig sslHostConfig) Create the SSLContextfor the the given SSLHostConfig.protected voiddestroySocket(Long socket) Close the socket.protected voidActually close the server socket but don't perform any other clean-up.booleanbooleanintObtain the number of kept alive sockets.Obtain the network address the server socket is bound to.protected LoggetLog()intintObtain the number of sendfile sockets.intlonggetSslContext(String sniHostName) This callback is made during the TLS handshake when the client uses the SNI extension to request a specific TLS host.booleanIdentifies if the endpoint supports ALPN.protected booleanprocessSocket(long socket, SocketEvent event) Process the given socket.protected LongvoidsetDeferAccept(boolean deferAccept) voidsetIpv6v6only(boolean ipv6v6only) voidsetMaxConnections(int maxConnections) This endpoint does not support-1for unlimited connections, nor does it support setting this attribute while the endpoint is running.voidsetPollTime(int pollTime) voidsetSendfileSize(int sendfileSize) protected booleansetSocketOptions(Long socket) Process given socket.protected booleansetSocketOptions(SocketWrapperBase<Long> socketWrapper) Process the specified connection.voidsetUseSendfile(boolean useSendfile) voidStart the APR endpoint, creating acceptor, poller and sendfile threads.voidStop the endpoint.voidunbind()Deallocate APR memory pools, and close server socket.Methods inherited from class org.apache.tomcat.util.net.AbstractEndpoint
addNegotiatedProtocol, addSslHostConfig, addSslHostConfig, awaitConnectionsClose, closeServerSocketGraceful, closeSocket, countDownConnection, countUpOrAwaitConnection, createExecutor, destroy, destroySsl, findSslHostConfigs, getAcceptCount, getAcceptorThreadCount, getAcceptorThreadPriority, getAddress, getAttribute, getBindOnInit, getBindState, getConnectionCount, getConnectionLinger, getConnections, getConnectionTimeout, getCurrentThreadCount, getCurrentThreadsBusy, getDaemon, getDefaultSSLHostConfigName, getDomain, getExecutor, getExecutorTerminationTimeoutMillis, getHandler, getKeepAliveTimeout, getLocalPort, getMaxConnections, getMaxKeepAliveRequests, getMaxThreads, getMinSpareThreads, getName, getPort, getPortOffset, getPortWithOffset, getProperty, getSocketProperties, getSSLHostConfig, getTcpNoDelay, getThreadPriority, getUseAsyncIO, getUseSendfile, getUtilityExecutor, hasNegotiableProtocols, init, initializeConnectionLatch, isPaused, isRunning, isSSLEnabled, pause, processSocket, releaseSSLContext, reloadSslHostConfig, reloadSslHostConfigs, removeSslHostConfig, resume, setAcceptCount, setAcceptorThreadCount, setAcceptorThreadPriority, setAddress, setAttribute, setBindOnInit, setConnectionLinger, setConnectionTimeout, setDaemon, setDefaultSSLHostConfigName, setDomain, setExecutor, setExecutorTerminationTimeoutMillis, setHandler, setKeepAliveTimeout, setMaxKeepAliveRequests, setMaxThreads, setMinSpareThreads, setName, setPort, setPortOffset, setProperty, setSSLEnabled, setTcpNoDelay, setThreadPriority, setUseAsyncIO, setUtilityExecutor, shutdownExecutor, start, startAcceptorThread, stop, toTimeout, unlockAccept
-
Field Details
-
rootPool
protected long rootPoolRoot APR memory pool. -
serverSock
protected volatile long serverSockServer socket "pointer". -
serverSockPool
protected long serverSockPoolAPR memory pool for the server socket. -
sslContext
protected long sslContextSSL context. -
deferAccept
protected boolean deferAcceptDefer accept. -
sendfileSize
protected int sendfileSizeSize of the sendfile (= concurrent files which can be served). -
pollTime
protected int pollTimePoll interval, in microseconds. The smaller the value, the more CPU the poller will use, but the more responsive to activity it will be. -
poller
The socket poller. -
sendfile
The static file sender.
-
-
Constructor Details
-
AprEndpoint
public AprEndpoint()
-
-
Method Details
-
setDeferAccept
public void setDeferAccept(boolean deferAccept) -
getDeferAccept
public boolean getDeferAccept()- Specified by:
getDeferAcceptin classAbstractEndpoint<Long,Long>
-
setIpv6v6only
public void setIpv6v6only(boolean ipv6v6only) -
getIpv6v6only
public boolean getIpv6v6only() -
setSendfileSize
public void setSendfileSize(int sendfileSize) -
getSendfileSize
public int getSendfileSize() -
getPollTime
public int getPollTime() -
setPollTime
public void setPollTime(int pollTime) -
setUseSendfile
public void setUseSendfile(boolean useSendfile) - Overrides:
setUseSendfilein classAbstractEndpoint<Long,Long>
-
getPoller
-
getSendfile
-
getLocalAddress
Description copied from class:AbstractEndpointObtain the network address the server socket is bound to. This primarily exists to enable the correct address to be used when unlocking the server socket since it removes the guess-work involved if no address is specifically set.- Specified by:
getLocalAddressin classAbstractEndpoint<Long,Long> - Returns:
- The network address that the server socket is listening on or null if the server socket is not currently bound.
- Throws:
IOException- If there is a problem determining the currently bound socket
-
setMaxConnections
public void setMaxConnections(int maxConnections) This endpoint does not support-1for unlimited connections, nor does it support setting this attribute while the endpoint is running.- Overrides:
setMaxConnectionsin classAbstractEndpoint<Long,Long>
-
getKeepAliveCount
public int getKeepAliveCount()Obtain the number of kept alive sockets.- Returns:
- The number of open sockets currently managed by the Poller
-
getSendfileCount
public int getSendfileCount()Obtain the number of sendfile sockets.- Returns:
- The number of sockets currently managed by the Sendfile poller.
-
bind
Initialize the endpoint.- Specified by:
bindin classAbstractEndpoint<Long,Long> - Throws:
Exception
-
createSSLContext
Description copied from class:AbstractEndpointCreate the SSLContextfor the the given SSLHostConfig.- Specified by:
createSSLContextin classAbstractEndpoint<Long,Long> - Parameters:
sslHostConfig- The SSLHostConfig for which the SSLContext should be created- Throws:
Exception- If the SSLContext cannot be created for the given SSLHostConfig
-
getSslContext
Description copied from interface:SSLContext.SNICallBackThis callback is made during the TLS handshake when the client uses the SNI extension to request a specific TLS host.- Specified by:
getSslContextin interfaceSSLContext.SNICallBack- Parameters:
sniHostName- The host name requested by the client - must be in lower case- Returns:
- The Java representation of the pointer to the OpenSSL SSLContext to use for the given host or zero if no SSLContext could be identified
-
isAlpnSupported
public boolean isAlpnSupported()Description copied from class:AbstractEndpointIdentifies if the endpoint supports ALPN. Note that a return value oftrueimplies thatAbstractEndpoint.isSSLEnabled()will also returntrue.- Specified by:
isAlpnSupportedin classAbstractEndpoint<Long,Long> - Returns:
trueif the endpoint supports ALPN in its current configuration, otherwisefalse.
-
startInternal
Start the APR endpoint, creating acceptor, poller and sendfile threads.- Specified by:
startInternalin classAbstractEndpoint<Long,Long> - Throws:
Exception
-
stopInternal
public void stopInternal()Stop the endpoint. This will cause all processing threads to stop.- Specified by:
stopInternalin classAbstractEndpoint<Long,Long>
-
unbind
Deallocate APR memory pools, and close server socket.- Specified by:
unbindin classAbstractEndpoint<Long,Long> - Throws:
Exception
-
doCloseServerSocket
protected void doCloseServerSocket()Description copied from class:AbstractEndpointActually close the server socket but don't perform any other clean-up.- Specified by:
doCloseServerSocketin classAbstractEndpoint<Long,Long>
-
setSocketOptions
Process the specified connection.- Parameters:
socketWrapper- The socket wrapper- Returns:
trueif the socket was correctly configured and processing may continue,falseif the socket needs to be close immediately
-
allocatePoller
protected long allocatePoller(int size, long pool, int timeout) Allocate a new poller of the specified size.- Parameters:
size- The sizepool- The pool from which the poller will be allocatedtimeout- The timeout- Returns:
- the poller pointer
-
setSocketOptions
Process given socket. This is called when the socket has been accepted.- Specified by:
setSocketOptionsin classAbstractEndpoint<Long,Long> - Parameters:
socket- The socket- Returns:
trueif the socket was correctly configured and processing may continue,falseif the socket needs to be close immediately
-
serverSocketAccept
- Specified by:
serverSocketAcceptin classAbstractEndpoint<Long,Long> - Throws:
Exception
-
processSocket
Process the given socket. Typically keep alive or upgraded protocol.- Parameters:
socket- The socket to processevent- The event to process- Returns:
trueif the processing completed normally otherwisefalsewhich indicates an error occurred and that the socket should be closed
-
createSocketProcessor
protected SocketProcessorBase<Long> createSocketProcessor(SocketWrapperBase<Long> socketWrapper, SocketEvent event) - Specified by:
createSocketProcessorin classAbstractEndpoint<Long,Long>
-
destroySocket
Description copied from class:AbstractEndpointClose the socket. This is used when the connector is not in a state which allows processing the socket, or if there was an error which prevented the allocation of the socket wrapper.- Specified by:
destroySocketin classAbstractEndpoint<Long,Long> - Parameters:
socket- The newly accepted socket
-
getLog
- Specified by:
getLogin classAbstractEndpoint<Long,Long>
-