Package org.apache.tomcat.util.net
Class NioEndpoint
- java.lang.Object
-
- org.apache.tomcat.util.net.AbstractEndpoint<S,U>
-
- org.apache.tomcat.util.net.AbstractJsseEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
- org.apache.tomcat.util.net.NioEndpoint
-
public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,java.nio.channels.SocketChannel>
NIO tailored thread pool, providing the following services:- Socket acceptor thread
- Socket poller thread
- Worker threads pool
- Author:
- Mladen Turk, Remy Maucherat
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NioEndpoint.NioSocketWrapper
class
NioEndpoint.Poller
Poller class.static class
NioEndpoint.PollerEvent
PollerEvent, cacheable object for poller events to avoid GCstatic class
NioEndpoint.SendfileData
SendfileData class.protected class
NioEndpoint.SocketProcessor
This 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
Fields Modifier and Type Field Description static int
OP_REGISTER
-
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 Constructor Description NioEndpoint()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind()
Initialize the endpoint.protected SocketProcessorBase<NioChannel>
createSocketProcessor(SocketWrapperBase<NioChannel> socketWrapper, SocketEvent event)
protected void
destroySocket(java.nio.channels.SocketChannel socket)
Close the socket.protected void
doCloseServerSocket()
Actually close the server socket but don't perform any other clean-up.java.lang.String
getId()
The default behavior is to identify connectors uniquely with address and port.int
getKeepAliveCount()
Number of keep-alive sockets.protected Log
getLog()
protected SynchronizedStack<NioChannel>
getNioChannels()
protected NioEndpoint.Poller
getPoller()
int
getPollerThreadPriority()
long
getSelectorTimeout()
protected java.nio.channels.NetworkChannel
getServerSocket()
protected java.util.concurrent.CountDownLatch
getStopLatch()
java.lang.String
getUnixDomainSocketPath()
java.lang.String
getUnixDomainSocketPathPermissions()
boolean
getUseInheritedChannel()
protected void
initServerSocket()
protected java.nio.channels.SocketChannel
serverSocketAccept()
void
setPollerThreadPriority(int pollerThreadPriority)
void
setSelectorTimeout(long timeout)
protected boolean
setSocketOptions(java.nio.channels.SocketChannel socket)
Process the specified connection.protected void
setStopLatch(java.util.concurrent.CountDownLatch stopLatch)
void
setUnixDomainSocketPath(java.lang.String unixDomainSocketPath)
void
setUnixDomainSocketPathPermissions(java.lang.String unixDomainSocketPathPermissions)
void
setUseInheritedChannel(boolean useInheritedChannel)
void
startInternal()
Start the NIO endpoint, creating acceptor, poller threads.void
stopInternal()
Stop the endpoint.void
unbind()
Deallocate NIO memory pools, and close server socket.protected void
unlockAccept()
Unlock the server socket acceptor threads using bogus connections.-
Methods inherited from class org.apache.tomcat.util.net.AbstractJsseEndpoint
createSSLContext, createSSLEngine, getLocalAddress, getSniParseLimit, getSslImplementation, getSslImplementationName, initialiseSsl, isAlpnSupported, setSniParseLimit, setSslImplementationName
-
Methods inherited from class org.apache.tomcat.util.net.AbstractEndpoint
addNegotiatedProtocol, addSslHostConfig, addSslHostConfig, awaitConnectionsClose, closeServerSocketGraceful, closeSocket, countDownConnection, countUpOrAwaitConnection, createExecutor, destroy, destroySsl, findSslHostConfigs, getAcceptCount, getAcceptorThreadPriority, getAddress, getAttribute, getBindOnInit, getBindState, getConnectionCount, getConnectionLinger, getConnections, getConnectionTimeout, getCurrentThreadCount, getCurrentThreadsBusy, getDaemon, getDefaultSSLHostConfigName, getDeferAccept, 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, setAcceptorThreadPriority, setAddress, setAttribute, setBindOnInit, setConnectionLinger, setConnectionTimeout, setDaemon, setDefaultSSLHostConfigName, setDomain, setExecutor, setExecutorTerminationTimeoutMillis, setHandler, setKeepAliveTimeout, setMaxConnections, setMaxKeepAliveRequests, setMaxThreads, setMinSpareThreads, setName, setPort, setPortOffset, setProperty, setSSLEnabled, setTcpNoDelay, setThreadPriority, setUseAsyncIO, setUseSendfile, setUtilityExecutor, shutdownExecutor, start, startAcceptorThread, stop, toTimeout
-
-
-
-
Field Detail
-
OP_REGISTER
public static final int OP_REGISTER
- See Also:
- Constant Field Values
-
-
Method Detail
-
setUseInheritedChannel
public void setUseInheritedChannel(boolean useInheritedChannel)
-
getUseInheritedChannel
public boolean getUseInheritedChannel()
-
getUnixDomainSocketPath
public java.lang.String getUnixDomainSocketPath()
-
setUnixDomainSocketPath
public void setUnixDomainSocketPath(java.lang.String unixDomainSocketPath)
-
getUnixDomainSocketPathPermissions
public java.lang.String getUnixDomainSocketPathPermissions()
-
setUnixDomainSocketPathPermissions
public void setUnixDomainSocketPathPermissions(java.lang.String unixDomainSocketPathPermissions)
-
setPollerThreadPriority
public void setPollerThreadPriority(int pollerThreadPriority)
-
getPollerThreadPriority
public int getPollerThreadPriority()
-
setSelectorTimeout
public void setSelectorTimeout(long timeout)
-
getSelectorTimeout
public long getSelectorTimeout()
-
getKeepAliveCount
public int getKeepAliveCount()
Number of keep-alive sockets.- Returns:
- The number of sockets currently in the keep-alive state waiting for the next request to be received on the socket
-
getId
public java.lang.String getId()
Description copied from class:AbstractEndpoint
The default behavior is to identify connectors uniquely with address and port. However, certain connectors are not using that and need some other identifier, which then can be used as a replacement.- Overrides:
getId
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
- Returns:
- the id
-
bind
public void bind() throws java.lang.Exception
Initialize the endpoint.- Specified by:
bind
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
- Throws:
java.lang.Exception
-
initServerSocket
protected void initServerSocket() throws java.lang.Exception
- Throws:
java.lang.Exception
-
startInternal
public void startInternal() throws java.lang.Exception
Start the NIO endpoint, creating acceptor, poller threads.- Specified by:
startInternal
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
- Throws:
java.lang.Exception
-
stopInternal
public void stopInternal()
Stop the endpoint. This will cause all processing threads to stop.- Specified by:
stopInternal
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
unbind
public void unbind() throws java.lang.Exception
Deallocate NIO memory pools, and close server socket.- Overrides:
unbind
in classAbstractJsseEndpoint<NioChannel,java.nio.channels.SocketChannel>
- Throws:
java.lang.Exception
-
doCloseServerSocket
protected void doCloseServerSocket() throws java.io.IOException
Description copied from class:AbstractEndpoint
Actually close the server socket but don't perform any other clean-up.- Specified by:
doCloseServerSocket
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
- Throws:
java.io.IOException
- If an error occurs closing the socket
-
unlockAccept
protected void unlockAccept()
Description copied from class:AbstractEndpoint
Unlock the server socket acceptor threads using bogus connections.- Overrides:
unlockAccept
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
getNioChannels
protected SynchronizedStack<NioChannel> getNioChannels()
-
getPoller
protected NioEndpoint.Poller getPoller()
-
getStopLatch
protected java.util.concurrent.CountDownLatch getStopLatch()
-
setStopLatch
protected void setStopLatch(java.util.concurrent.CountDownLatch stopLatch)
-
setSocketOptions
protected boolean setSocketOptions(java.nio.channels.SocketChannel socket)
Process the specified connection.- Specified by:
setSocketOptions
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
- Parameters:
socket
- The socket channel- Returns:
true
if the socket was correctly configured and processing may continue,false
if the socket needs to be close immediately
-
destroySocket
protected void destroySocket(java.nio.channels.SocketChannel socket)
Description copied from class:AbstractEndpoint
Close 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:
destroySocket
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
- Parameters:
socket
- The newly accepted socket
-
getServerSocket
protected java.nio.channels.NetworkChannel getServerSocket()
- Specified by:
getServerSocket
in classAbstractJsseEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
serverSocketAccept
protected java.nio.channels.SocketChannel serverSocketAccept() throws java.lang.Exception
- Specified by:
serverSocketAccept
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
- Throws:
java.lang.Exception
-
getLog
protected Log getLog()
- Specified by:
getLog
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
createSocketProcessor
protected SocketProcessorBase<NioChannel> createSocketProcessor(SocketWrapperBase<NioChannel> socketWrapper, SocketEvent event)
- Specified by:
createSocketProcessor
in classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
-