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 endpoint.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNioEndpoint.NioSocketWrapperNIO socket wrapper that wraps an NioChannel.classNioEndpoint.PollerPoller class.static classNioEndpoint.PollerEventPollerEvent, cacheable object for poller events to avoid GCstatic classNioEndpoint.SendfileDataSendfileData class.protected classNioEndpoint.SocketProcessorThis 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 intOP_REGISTERCustom operation for registering interest in a socket.-
Fields inherited from class org.apache.tomcat.util.net.AbstractEndpoint
acceptor, acceptorThreadPriority, attributes, connections, internalExecutor, negotiableProtocols, paused, processorCache, running, sm, socketProperties, sslHostConfigs, threadPriority
-
-
Constructor Summary
Constructors Constructor Description NioEndpoint()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind()Initialize the endpoint.protected SocketProcessorBase<NioChannel>createSocketProcessor(SocketWrapperBase<NioChannel> socketWrapper, SocketEvent event)Create a socket processor for the given socket wrapper.protected voiddestroySocket(java.nio.channels.SocketChannel socket)Close the socket.protected voiddoCloseServerSocket()Actually close the server socket but don't perform any other clean-up.java.lang.StringgetId()The default behavior is to identify connectors uniquely with address and port.intgetKeepAliveCount()Number of keep-alive sockets.protected LoggetLog()Get the logger for this endpoint.protected LoggetLogCertificate()Get the logger for certificate-related messages.protected SynchronizedStack<NioChannel>getNioChannels()Returns the NIO channel cache.protected NioEndpoint.PollergetPoller()Returns the poller instance.intgetPollerThreadPriority()Returns the poller thread priority.longgetSelectorTimeout()Returns the selector timeout.protected java.nio.channels.NetworkChannelgetServerSocket()protected java.util.concurrent.CountDownLatchgetStopLatch()Returns the stop latch.java.lang.StringgetUnixDomainSocketPath()Returns the Unix domain socket path.java.lang.StringgetUnixDomainSocketPathPermissions()Returns the Unix domain socket path permissions.booleangetUseInheritedChannel()Returns whether an inherited channel is used.protected voidinitServerSocket()Initializes the server socket channel.protected java.nio.channels.SocketChannelserverSocketAccept()Accept a connection from the server socket.voidsetPollerThreadPriority(int pollerThreadPriority)Sets the poller thread priority.voidsetSelectorTimeout(long timeout)Sets the selector timeout.protected booleansetSocketOptions(java.nio.channels.SocketChannel socket)Process the specified connection.protected voidsetStopLatch(java.util.concurrent.CountDownLatch stopLatch)Sets the stop latch.voidsetUnixDomainSocketPath(java.lang.String unixDomainSocketPath)Sets the Unix domain socket path.voidsetUnixDomainSocketPathPermissions(java.lang.String unixDomainSocketPathPermissions)Sets the Unix domain socket path permissions.voidsetUseInheritedChannel(boolean useInheritedChannel)Sets whether to use an inherited channel.voidstartInternal()Start the NIO endpoint, creating acceptor, poller threads.voidstopInternal()Stop the endpoint.voidunbind()Deallocate NIO memory pools, and close server socket.protected voidunlockAccept()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, setSniParseLimit, setSslImplementationName
-
Methods inherited from class org.apache.tomcat.util.net.AbstractEndpoint
addNegotiatedProtocol, addSslHostConfig, addSslHostConfig, awaitConnectionsClose, checkSni, closeServerSocketGraceful, closeSocket, countDownConnection, countUpOrAwaitConnection, createExecutor, destroy, destroySsl, findSslHostConfigs, generateCertificateDebug, getAcceptCount, getAcceptorThreadPriority, getAddress, getAttribute, getBindOnInit, getBindState, getConnectionCount, getConnectionLinger, getConnections, getConnectionTimeout, getCurrentThreadCount, getCurrentThreadsBusy, getDaemon, getDefaultSSLHostConfigName, getDeferAccept, getDomain, getExecutor, getExecutorTerminationTimeoutMillis, getHandler, getKeepAliveTimeout, getLocalPort, getMaxConnections, getMaxKeepAliveRequests, getMaxQueueSize, getMaxThreads, getMinSpareThreads, getName, getPort, getPortOffset, getPortWithOffset, getProperty, getSocketProperties, getSSLHostConfig, getStrictSni, getTcpNoDelay, getThreadPriority, getThreadsMaxIdleTime, getUseAsyncIO, getUseSendfile, getUseVirtualThreads, getUtilityExecutor, hasNegotiableProtocols, init, initializeConnectionLatch, isPaused, isRunning, isSSLEnabled, logCertificate, pause, processSocket, releaseSSLContext, reloadSslHostConfig, reloadSslHostConfigs, removeSslHostConfig, resume, setAcceptCount, setAcceptorThreadPriority, setAddress, setAttribute, setBindOnInit, setConnectionLinger, setConnectionTimeout, setDaemon, setDefaultSSLHostConfigName, setDomain, setExecutor, setExecutorTerminationTimeoutMillis, setHandler, setKeepAliveTimeout, setMaxConnections, setMaxKeepAliveRequests, setMaxQueueSize, setMaxThreads, setMinSpareThreads, setName, setPort, setPortOffset, setProperty, setSSLEnabled, setStrictSni, setTcpNoDelay, setThreadPriority, setThreadsMaxIdleTime, setUseAsyncIO, setUseSendfile, setUseVirtualThreads, setUtilityExecutor, shutdownExecutor, start, startAcceptorThread, stop, toTimeout
-
-
-
-
Field Detail
-
OP_REGISTER
public static final int OP_REGISTER
Custom operation for registering interest in a socket.- See Also:
- Constant Field Values
-
-
Method Detail
-
setUseInheritedChannel
public void setUseInheritedChannel(boolean useInheritedChannel)
Sets whether to use an inherited channel.- Parameters:
useInheritedChannel-trueto use System.inheritedChannel
-
getUseInheritedChannel
public boolean getUseInheritedChannel()
Returns whether an inherited channel is used.- Returns:
trueif System.inheritedChannel is used
-
getUnixDomainSocketPath
public java.lang.String getUnixDomainSocketPath()
Returns the Unix domain socket path.- Returns:
- the Unix domain socket path
-
setUnixDomainSocketPath
public void setUnixDomainSocketPath(java.lang.String unixDomainSocketPath)
Sets the Unix domain socket path.- Parameters:
unixDomainSocketPath- the path to the Unix domain socket
-
getUnixDomainSocketPathPermissions
public java.lang.String getUnixDomainSocketPathPermissions()
Returns the Unix domain socket path permissions.- Returns:
- the permissions string
-
setUnixDomainSocketPathPermissions
public void setUnixDomainSocketPathPermissions(java.lang.String unixDomainSocketPathPermissions)
Sets the Unix domain socket path permissions.- Parameters:
unixDomainSocketPathPermissions- the permissions string
-
setPollerThreadPriority
public void setPollerThreadPriority(int pollerThreadPriority)
Sets the poller thread priority.- Parameters:
pollerThreadPriority- the thread priority
-
getPollerThreadPriority
public int getPollerThreadPriority()
Returns the poller thread priority.- Returns:
- the thread priority
-
setSelectorTimeout
public void setSelectorTimeout(long timeout)
Sets the selector timeout.- Parameters:
timeout- The timeout in milliseconds
-
getSelectorTimeout
public long getSelectorTimeout()
Returns the selector timeout.- Returns:
- the timeout in milliseconds
-
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:AbstractEndpointThe 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:
getIdin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>- Returns:
- the id
-
bind
public void bind() throws java.lang.ExceptionInitialize the endpoint.- Specified by:
bindin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>- Throws:
java.lang.Exception- If an error occurs during binding
-
initServerSocket
protected void initServerSocket() throws java.lang.ExceptionInitializes the server socket channel.- Throws:
java.lang.Exception- If initialization fails
-
startInternal
public void startInternal() throws java.lang.ExceptionStart the NIO endpoint, creating acceptor, poller threads.- Specified by:
startInternalin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>- Throws:
java.lang.Exception- If an error occurs during startup
-
stopInternal
public void stopInternal()
Stop the endpoint. This will cause all processing threads to stop.- Specified by:
stopInternalin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
unbind
public void unbind() throws java.lang.ExceptionDeallocate NIO memory pools, and close server socket.- Overrides:
unbindin classAbstractJsseEndpoint<NioChannel,java.nio.channels.SocketChannel>- Throws:
java.lang.Exception
-
doCloseServerSocket
protected void doCloseServerSocket() throws java.io.IOExceptionDescription copied from class:AbstractEndpointActually close the server socket but don't perform any other clean-up.- Specified by:
doCloseServerSocketin 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:AbstractEndpointUnlock the server socket acceptor threads using bogus connections.- Overrides:
unlockAcceptin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
getNioChannels
protected SynchronizedStack<NioChannel> getNioChannels()
Returns the NIO channel cache.- Returns:
- the channel cache stack
-
getPoller
protected NioEndpoint.Poller getPoller()
Returns the poller instance.- Returns:
- the poller
-
getStopLatch
protected java.util.concurrent.CountDownLatch getStopLatch()
Returns the stop latch.- Returns:
- the stop latch
-
setStopLatch
protected void setStopLatch(java.util.concurrent.CountDownLatch stopLatch)
Sets the stop latch.- Parameters:
stopLatch- the stop latch
-
setSocketOptions
protected boolean setSocketOptions(java.nio.channels.SocketChannel socket)
Process the specified connection.- Specified by:
setSocketOptionsin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>- Parameters:
socket- The socket channel- Returns:
trueif the socket was correctly configured and processing may continue,falseif the socket needs to be close immediately
-
destroySocket
protected void destroySocket(java.nio.channels.SocketChannel socket)
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<NioChannel,java.nio.channels.SocketChannel>- Parameters:
socket- The newly accepted socket
-
getServerSocket
protected java.nio.channels.NetworkChannel getServerSocket()
- Specified by:
getServerSocketin classAbstractJsseEndpoint<NioChannel,java.nio.channels.SocketChannel>
-
serverSocketAccept
protected java.nio.channels.SocketChannel serverSocketAccept() throws java.lang.ExceptionDescription copied from class:AbstractEndpointAccept a connection from the server socket.- Specified by:
serverSocketAcceptin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>- Returns:
- The accepted socket
- Throws:
java.lang.Exception- If an error occurs during accept
-
getLog
protected Log getLog()
Description copied from class:AbstractEndpointGet the logger for this endpoint.- Specified by:
getLogin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>- Returns:
- The logger
-
getLogCertificate
protected Log getLogCertificate()
Description copied from class:AbstractEndpointGet the logger for certificate-related messages.- Overrides:
getLogCertificatein classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>- Returns:
- The logger (defaults to
AbstractEndpoint.getLog())
-
createSocketProcessor
protected SocketProcessorBase<NioChannel> createSocketProcessor(SocketWrapperBase<NioChannel> socketWrapper, SocketEvent event)
Description copied from class:AbstractEndpointCreate a socket processor for the given socket wrapper.- Specified by:
createSocketProcessorin classAbstractEndpoint<NioChannel,java.nio.channels.SocketChannel>- Parameters:
socketWrapper- The socket wrapper to processevent- The socket event- Returns:
- The socket processor
-
-