NioEndpoint (Apache Tomcat 9.0.121 API Documentation)
Description: declaration: package: org.apache.tomcat.util.net, class: NioEndpoint

# Class NioEndpoint

java.lang.Object
org.apache.tomcat.util.net.AbstractEndpoint<NioChannel, SocketChannel>
org.apache.tomcat.util.net.AbstractJsseEndpoint<NioChannel, SocketChannel>
org.apache.tomcat.util.net.NioEndpoint

public class NioEndpoint extends AbstractJsseEndpoint<NioChannel, SocketChannel>
NIO endpoint.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `NioEndpoint.NioSocketWrapper`
  NIO socket wrapper that wraps an NioChannel.
  `class`
  `NioEndpoint.Poller`
  Poller class.
  `static class`
  `NioEndpoint.PollerEvent`
  PollerEvent, cacheable object for poller events to avoid GC
  `static 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 AbstractEndpoint

  `AbstractEndpoint.BindState, AbstractEndpoint.Handler<S>`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `OP_REGISTER`
  Custom operation for registering interest in a socket.

  ### Fields inherited from class AbstractEndpoint

  `acceptor, acceptorThreadCount, acceptorThreadPriority, attributes, connections, internalExecutor, negotiableProtocols, paused, processorCache, running, sm, socketProperties, sslHostConfigs, threadPriority`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NioEndpoint()`
  Default constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `bind()`
  Initialize the endpoint.
  `protected SocketProcessorBase<NioChannel>`
  `createSocketProcessor(SocketWrapperBase<NioChannel> socketWrapper, SocketEvent event)`
  Create a socket processor for the given socket wrapper.
  `protected void`
  `destroySocket(SocketChannel socket)`
  Close the socket.
  `protected void`
  `doCloseServerSocket()`
  Actually close the server socket but don't perform any other clean-up.
  `boolean`
  `getDeferAccept()`
  Is deferAccept supported?
  `String`
  `getId()`
  The default behavior is to identify connectors uniquely with address and port.
  `int`
  `getKeepAliveCount()`
  Number of keep-alive sockets.
  `protected Log`
  `getLog()`
  Get the logger for this endpoint.
  `protected Log`
  `getLogCertificate()`
  Get the logger for certificate-related messages.
  `protected SynchronizedStack<NioChannel>`
  `getNioChannels()`
  Returns the NIO channel cache.
  `protected NioEndpoint.Poller`
  `getPoller()`
  Returns the poller instance.
  `int`
  `getPollerThreadCount()`
  Deprecated.
  Will be removed in Tomcat 10.
  `int`
  `getPollerThreadPriority()`
  Returns the poller thread priority.
  `long`
  `getSelectorTimeout()`
  Returns the selector timeout.
  `protected NetworkChannel`
  `getServerSocket()`
  `protected CountDownLatch`
  `getStopLatch()`
  Returns the stop latch.
  `String`
  `getUnixDomainSocketParentOwner()`
  Returns the expected name of the owner of the parent directory for the UDS if it already exists.
  `String`
  `getUnixDomainSocketParentPermissions()`
  Returns the permissions that will be checked for / set on the parent directory of the Unix Domain Socket path before the Unix Domain Socket is created.
  `String`
  `getUnixDomainSocketPath()`
  Returns the Unix domain socket path.
  `String`
  `getUnixDomainSocketPathPermissions()`
  Returns the Unix domain socket path permissions.
  `boolean`
  `getUseInheritedChannel()`
  Returns whether an inherited channel is used.
  `protected void`
  `initServerSocket()`
  Initializes the server socket channel.
  `protected SocketChannel`
  `serverSocketAccept()`
  Accept a connection from the server socket.
  `void`
  `setPollerThreadCount(int pollerThreadCount)`
  Deprecated.
  Will be removed in Tomcat 10.
  `void`
  `setPollerThreadPriority(int pollerThreadPriority)`
  Sets the poller thread priority.
  `void`
  `setSelectorTimeout(long timeout)`
  Sets the selector timeout.
  `protected boolean`
  `setSocketOptions(SocketChannel socket)`
  Process the specified connection.
  `protected void`
  `setStopLatch(CountDownLatch stopLatch)`
  Sets the stop latch.
  `void`
  `setUnixDomainSocketParentOwner(String unixDomainSocketParentOwner)`
  Sets the expected name of the owner of the parent directory for the UDS if it already exists.
  `void`
  `setUnixDomainSocketParentPermissions(String unixDomainSocketParentPermissions)`
  Sets the permissions that will be checked for / set on the parent directory of the Unix Domain Socket path before the Unix Domain Socket is created.
  `void`
  `setUnixDomainSocketPath(String unixDomainSocketPath)`
  Sets the Unix domain socket path.
  `void`
  `setUnixDomainSocketPathPermissions(String unixDomainSocketPathPermissions)`
  Sets the Unix domain socket path permissions.
  `void`
  `setUseInheritedChannel(boolean useInheritedChannel)`
  Sets whether to use an inherited channel.
  `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 AbstractJsseEndpoint

  `createSSLContext, createSSLEngine, getLocalAddress, getSniParseLimit, getSslImplementation, getSslImplementationName, initialiseSsl, isAlpnSupported, setDefaultSslHostConfig, setSniParseLimit, setSslImplementationName`

  ### Methods inherited from class AbstractEndpoint

  `addNegotiatedProtocol, addSslHostConfig, addSslHostConfig, awaitConnectionsClose, checkSni, closeServerSocketGraceful, closeSocket, countDownConnection, countUpOrAwaitConnection, createExecutor, destroy, destroySsl, findSslHostConfigs, generateCertificateDebug, getAcceptCount, getAcceptorThreadCount, getAcceptorThreadPriority, getAddress, getAttribute, getBindOnInit, getBindState, getConnectionCount, getConnectionLinger, getConnections, getConnectionTimeout, getCurrentThreadCount, getCurrentThreadsBusy, getDaemon, getDefaultSSLHostConfigName, 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, setAcceptorThreadCount, 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`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### OP_REGISTER

    public static final int OP_REGISTER
    Custom operation for registering interest in a socket.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### NioEndpoint

    public NioEndpoint()
    Default constructor.

- ## Method Details

  - ### setUseInheritedChannel

    public void setUseInheritedChannel(boolean useInheritedChannel)
    Sets whether to use an inherited channel.
    Parameters:
      `useInheritedChannel` - `true` to use System.inheritedChannel

  - ### getUseInheritedChannel

    public boolean getUseInheritedChannel()
    Returns whether an inherited channel is used.
    Returns:
      `true` if System.inheritedChannel is used

  - ### getUnixDomainSocketPath

    public String getUnixDomainSocketPath()
    Returns the Unix domain socket path.
    Returns:
      the Unix domain socket path

  - ### setUnixDomainSocketPath

    public void setUnixDomainSocketPath(String unixDomainSocketPath)
    Sets the Unix domain socket path.
    Parameters:
      `unixDomainSocketPath` - the path to the Unix domain socket

  - ### getUnixDomainSocketPathPermissions

    public String getUnixDomainSocketPathPermissions()
    Returns the Unix domain socket path permissions.
    Returns:
      the permissions string

  - ### setUnixDomainSocketPathPermissions

    public void setUnixDomainSocketPathPermissions(String unixDomainSocketPathPermissions)
    Sets the Unix domain socket path permissions.
    Parameters:
      `unixDomainSocketPathPermissions` - the permissions string

  - ### setUnixDomainSocketParentPermissions

    public void setUnixDomainSocketParentPermissions(String unixDomainSocketParentPermissions)
    Sets the permissions that will be checked for / set on the parent directory of the Unix Domain Socket path before the Unix Domain Socket is created.
    Parameters:
      `unixDomainSocketParentPermissions` - the permissions string

  - ### getUnixDomainSocketParentPermissions

    public String getUnixDomainSocketParentPermissions()
    Returns the permissions that will be checked for / set on the parent directory of the Unix Domain Socket path before the Unix Domain Socket is created.
    Returns:
      the permissions string

  - ### getUnixDomainSocketParentOwner

    public String getUnixDomainSocketParentOwner()
    Returns the expected name of the owner of the parent directory for the UDS if it already exists.
    Returns:
      the owner name

  - ### setUnixDomainSocketParentOwner

    public void setUnixDomainSocketParentOwner(String unixDomainSocketParentOwner)
    Sets the expected name of the owner of the parent directory for the UDS if it already exists.
    Parameters:
      `unixDomainSocketParentOwner` - the expected owner name

  - ### 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

  - ### setPollerThreadCount

    @Deprecated public void setPollerThreadCount(int pollerThreadCount)
    Deprecated.
    Will be removed in Tomcat 10.
    NO-OP.
    Parameters:
      `pollerThreadCount` - Unused

  - ### getPollerThreadCount

    @Deprecated public int getPollerThreadCount()
    Deprecated.
    Will be removed in Tomcat 10.
    Always returns 1.
    Returns:
      Always 1.

  - ### 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

  - ### getDeferAccept

    public boolean getDeferAccept()
    Is deferAccept supported?
    Specified by:
      `getDeferAccept` in class `AbstractEndpoint<NioChannel, SocketChannel>`

  - ### 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 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 class `AbstractEndpoint<NioChannel, SocketChannel>`
    Returns:
      the id

  - ### bind

    public void bind() throws Exception
    Initialize the endpoint.
    Specified by:
      `bind` in class `AbstractEndpoint<NioChannel, SocketChannel>`
    Throws:
      `Exception` - If an error occurs during binding

  - ### initServerSocket

    protected void initServerSocket() throws Exception
    Initializes the server socket channel.
    Throws:
      `Exception` - If initialization fails

  - ### startInternal

    public void startInternal() throws Exception
    Start the NIO endpoint, creating acceptor, poller threads.
    Specified by:
      `startInternal` in class `AbstractEndpoint<NioChannel, SocketChannel>`
    Throws:
      `Exception` - If an error occurs during startup

  - ### stopInternal

    public void stopInternal()
    Stop the endpoint. This will cause all processing threads to stop.
    Specified by:
      `stopInternal` in class `AbstractEndpoint<NioChannel, SocketChannel>`

  - ### unbind

    public void unbind() throws Exception
    Deallocate NIO memory pools, and close server socket.
    Overrides:
      `unbind` in class `AbstractJsseEndpoint<NioChannel, SocketChannel>`
    Throws:
      `Exception`

  - ### doCloseServerSocket

    protected void doCloseServerSocket() throws IOException
    Description copied from class: `AbstractEndpoint`
    Actually close the server socket but don't perform any other clean-up.
    Specified by:
      `doCloseServerSocket` in class `AbstractEndpoint<NioChannel, SocketChannel>`
    Throws:
      `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 class `AbstractEndpoint<NioChannel, 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 CountDownLatch getStopLatch()
    Returns the stop latch.
    Returns:
      the stop latch

  - ### setStopLatch

    protected void setStopLatch(CountDownLatch stopLatch)
    Sets the stop latch.
    Parameters:
      `stopLatch` - the stop latch

  - ### setSocketOptions

    protected boolean setSocketOptions(SocketChannel socket)
    Process the specified connection.
    Specified by:
      `setSocketOptions` in class `AbstractEndpoint<NioChannel, 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(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 class `AbstractEndpoint<NioChannel, SocketChannel>`
    Parameters:
      `socket` - The newly accepted socket

  - ### getServerSocket

    protected NetworkChannel getServerSocket()
    Specified by:
      `getServerSocket` in class `AbstractJsseEndpoint<NioChannel, SocketChannel>`

  - ### serverSocketAccept

    protected SocketChannel serverSocketAccept() throws Exception
    Description copied from class: `AbstractEndpoint`
    Accept a connection from the server socket.
    Specified by:
      `serverSocketAccept` in class `AbstractEndpoint<NioChannel, SocketChannel>`
    Returns:
      The accepted socket
    Throws:
      `Exception` - If an error occurs during accept

  - ### getLog

    protected Log getLog()
    Description copied from class: `AbstractEndpoint`
    Get the logger for this endpoint.
    Specified by:
      `getLog` in class `AbstractEndpoint<NioChannel, SocketChannel>`
    Returns:
      The logger

  - ### getLogCertificate

    protected Log getLogCertificate()
    Description copied from class: `AbstractEndpoint`
    Get the logger for certificate-related messages.
    Overrides:
      `getLogCertificate` in class `AbstractEndpoint<NioChannel, SocketChannel>`
    Returns:
      The logger (defaults to `AbstractEndpoint.getLog()`)

  - ### createSocketProcessor

    protected SocketProcessorBase<NioChannel> createSocketProcessor(SocketWrapperBase<NioChannel> socketWrapper, SocketEvent event)
    Description copied from class: `AbstractEndpoint`
    Create a socket processor for the given socket wrapper.
    Specified by:
      `createSocketProcessor` in class `AbstractEndpoint<NioChannel, SocketChannel>`
    Parameters:
      `socketWrapper` - The socket wrapper to process
      `event` - The socket event
    Returns:
      The socket processor