org.apache.tomcat.util.net

## Class AbstractEndpoint<S>

- java.lang.Object
- - org.apache.tomcat.util.net.AbstractEndpoint<S>

- Type Parameters:
    `S` - The type for the sockets managed by this endpoint.
  Direct Known Subclasses:
    AbstractJsseEndpoint, AprEndpoint

      public abstract class AbstractEndpoint<S>
      extends Object

  Author:
    Mladen Turk, Remy Maucherat

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AbstractEndpoint.Acceptor`
    `protected static class` | `AbstractEndpoint.BindState`
    `static interface` | `AbstractEndpoint.Handler<S>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected AbstractEndpoint.Acceptor[]` | `acceptors` Threads used to accept new connections and pass them to worker threads.
    `protected int` | `acceptorThreadCount` Acceptor thread count.
    `protected int` | `acceptorThreadPriority` Priority of the acceptor threads.
    `protected HashMap<String,Object>` | `attributes` Attributes provide a way for configuration to be passed to sub-components without the `ProtocolHandler` being aware of the properties available on those sub-components.
    `protected boolean` | `internalExecutor` Are we using an internal executor
    `protected List<String>` | `negotiableProtocols`
    `protected boolean` | `paused` Will be set to true whenever the endpoint is paused.
    `protected SynchronizedStack<SocketProcessorBase<S>>` | `processorCache` Cache for SocketProcessor objects
    `protected boolean` | `running` Running state of the endpoint.
    `protected static StringManager` | `sm`
    `protected SocketProperties` | `socketProperties` Socket properties
    `protected ConcurrentMap<String,SSLHostConfig>` | `sslHostConfigs`
    `protected int` | `threadPriority` Priority of the worker threads.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractEndpoint()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addNegotiatedProtocol(String negotiableProtocol)`
    `void` | `addSslHostConfig(SSLHostConfig sslHostConfig)`
    `abstract void` | `bind()`
    `protected long` | `countDownConnection()`
    `protected void` | `countUpOrAwaitConnection()`
    `protected abstract AbstractEndpoint.Acceptor` | `createAcceptor()` Hook to allow Endpoints to provide a specific Acceptor implementation.
    `void` | `createExecutor()`
    `protected abstract SocketProcessorBase<S>` | `createSocketProcessor(SocketWrapperBase<S> socketWrapper, SocketEvent event)`
    `protected abstract void` | `createSSLContext(SSLHostConfig sslHostConfig)` Create the SSLContextfor the the given SSLHostConfig.
    `void` | `destroy()`
    `SSLHostConfig[]` | `findSslHostConfigs()`
    `int` | `getAcceptCount()`
    `int` | `getAcceptorThreadCount()`
    `int` | `getAcceptorThreadPriority()`
    `InetAddress` | `getAddress()`
    `Object` | `getAttribute(String key)` Used by sub-components to retrieve configuration information.
    `int` | `getBacklog()` Deprecated.
    `boolean` | `getBindOnInit()`
    `long` | `getConnectionCount()` Return the current count of connections handled by this endpoint, if the connections are counted (which happens when the maximum count of connections is limited), or `-1` if they are not.
    `int` | `getConnectionLinger()` Socket linger.
    `int` | `getConnectionTimeout()` Socket timeout.
    `int` | `getCurrentThreadCount()` Return the amount of threads that are managed by the pool.
    `int` | `getCurrentThreadsBusy()` Return the amount of threads that are in use
    `boolean` | `getDaemon()`
    `String` | `getDefaultSSLHostConfigName()`
    `protected abstract boolean` | `getDeferAccept()`
    `Executor` | `getExecutor()`
    `long` | `getExecutorTerminationTimeoutMillis()`
    `AbstractEndpoint.Handler<S>` | `getHandler()`
    `int` | `getKeepAliveTimeout()`
    `protected abstract InetSocketAddress` | `getLocalAddress()` Obtain the network address the server socket is bound to.
    `int` | `getLocalPort()`
    `protected abstract Log` | `getLog()`
    `int` | `getMaxConnections()`
    `int` | `getMaxHeaderCount()`
    `int` | `getMaxKeepAliveRequests()`
    `int` | `getMaxThreads()`
    `int` | `getMinSpareThreads()`
    `String` | `getName()`
    `int` | `getPort()`
    `String` | `getProperty(String name)`
    `SocketProperties` | `getSocketProperties()`
    `int` | `getSoLinger()` Deprecated.
    `int` | `getSoTimeout()` Deprecated.
    `protected abstract SSLHostConfig.Type` | `getSslConfigType()`
    `protected SSLHostConfig` | `getSSLHostConfig(String sniHostName)`
    `boolean` | `getTcpNoDelay()` Socket TCP no delay.
    `int` | `getThreadPriority()`
    `boolean` | `getUseSendfile()`
    `protected int` | `handleExceptionWithDelay(int currentErrorDelay)` Provides a common approach for sub-classes to handle exceptions where a delay is required to prevent a Thread from entering a tight loop which will consume CPU and may also trigger large amounts of logging.
    `boolean` | `hasNegotiableProtocols()`
    `void` | `init()`
    `protected LimitLatch` | `initializeConnectionLatch()`
    `abstract boolean` | `isAlpnSupported()` Identifies if the endpoint supports ALPN.
    `boolean` | `isPaused()`
    `boolean` | `isRunning()`
    `boolean` | `isSSLEnabled()`
    `void` | `pause()` Pause the endpoint, which will stop it accepting new connections.
    `boolean` | `processSocket(SocketWrapperBase<S> socketWrapper, SocketEvent event, boolean dispatch)` Process the given SocketWrapper with the given status.
    `protected void` | `releaseConnectionLatch()`
    `protected abstract void` | `releaseSSLContext(SSLHostConfig sslHostConfig)` Release the SSLContext, if any, associated with the SSLHostConfig.
    `void` | `resume()` Resume the endpoint, which will make it start accepting new connections again.
    `void` | `setAcceptCount(int acceptCount)`
    `void` | `setAcceptorThreadCount(int acceptorThreadCount)`
    `void` | `setAcceptorThreadPriority(int acceptorThreadPriority)`
    `void` | `setAddress(InetAddress address)`
    `void` | `setAttribute(String name, Object value)` Generic property setter called when a property for which a specific setter already exists within the `ProtocolHandler` needs to be made available to sub-components.
    `void` | `setBacklog(int backlog)` Deprecated.
    `void` | `setBindOnInit(boolean b)`
    `void` | `setConnectionLinger(int connectionLinger)`
    `void` | `setConnectionTimeout(int soTimeout)`
    `void` | `setDaemon(boolean b)`
    `void` | `setDefaultSSLHostConfigName(String defaultSSLHostConfigName)`
    `void` | `setExecutor(Executor executor)`
    `void` | `setExecutorTerminationTimeoutMillis(long executorTerminationTimeoutMillis)`
    `void` | `setHandler(AbstractEndpoint.Handler<S> handler)`
    `void` | `setKeepAliveTimeout(int keepAliveTimeout)`
    `void` | `setMaxConnections(int maxCon)`
    `void` | `setMaxHeaderCount(int maxHeaderCount)`
    `void` | `setMaxKeepAliveRequests(int maxKeepAliveRequests)`
    `void` | `setMaxThreads(int maxThreads)`
    `void` | `setMinSpareThreads(int minSpareThreads)`
    `void` | `setName(String name)`
    `void` | `setPort(int port)`
    `boolean` | `setProperty(String name, String value)`
    `void` | `setSoLinger(int soLinger)` Deprecated.
    `void` | `setSoTimeout(int soTimeout)` Deprecated.
    `void` | `setSSLEnabled(boolean SSLEnabled)`
    `void` | `setTcpNoDelay(boolean tcpNoDelay)`
    `void` | `setThreadPriority(int threadPriority)`
    `void` | `setUseSendfile(boolean useSendfile)`
    `void` | `shutdownExecutor()`
    `void` | `start()`
    `protected void` | `startAcceptorThreads()`
    `abstract void` | `startInternal()`
    `void` | `stop()`
    `abstract void` | `stopInternal()`
    `abstract void` | `unbind()`
    `protected void` | `unlockAccept()` Unlock the server socket accept using a bogus connection.

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### sm

          protected static final StringManager sm

    - #### running

          protected volatile boolean running

      Running state of the endpoint.

    - #### paused

          protected volatile boolean paused

      Will be set to true whenever the endpoint is paused.

    - #### internalExecutor

          protected volatile boolean internalExecutor

      Are we using an internal executor

    - #### socketProperties

          protected SocketProperties socketProperties

      Socket properties

    - #### acceptors

          protected AbstractEndpoint.Acceptor[] acceptors

      Threads used to accept new connections and pass them to worker threads.

    - #### processorCache

          protected SynchronizedStack<SocketProcessorBase<S>> processorCache

      Cache for SocketProcessor objects

    - #### sslHostConfigs

          protected ConcurrentMap<String,SSLHostConfig> sslHostConfigs

    - #### acceptorThreadCount

          protected int acceptorThreadCount

      Acceptor thread count.

    - #### acceptorThreadPriority

          protected int acceptorThreadPriority

      Priority of the acceptor threads.

    - #### threadPriority

          protected int threadPriority

      Priority of the worker threads.

    - #### negotiableProtocols

          protected final List<String> negotiableProtocols

    - #### attributes

          protected HashMap<String,Object> attributes

      Attributes provide a way for configuration to be passed to sub-components without the `ProtocolHandler` being aware of the properties available on those sub-components.

  - ### Constructor Detail

    - #### AbstractEndpoint

          public AbstractEndpoint()

  - ### Method Detail

    - #### getSocketProperties

          public SocketProperties getSocketProperties()

    - #### getDefaultSSLHostConfigName

          public String getDefaultSSLHostConfigName()

    - #### setDefaultSSLHostConfigName

          public void setDefaultSSLHostConfigName(String defaultSSLHostConfigName)

    - #### addSslHostConfig

          public void addSslHostConfig(SSLHostConfig sslHostConfig)
                                throws IllegalArgumentException

      Throws:
        `IllegalArgumentException`

    - #### findSslHostConfigs

          public SSLHostConfig[] findSslHostConfigs()

    - #### getSslConfigType

          protected abstract SSLHostConfig.Type getSslConfigType()

    - #### createSSLContext

          protected abstract void createSSLContext(SSLHostConfig sslHostConfig)
                                            throws Exception

      Create the SSLContextfor the the given SSLHostConfig.
      Parameters:
        `sslHostConfig` - The SSLHostConfig for which the SSLContext should be created
      Throws:
        `Exception` - If the SSLContext cannot be created for the given SSLHostConfig

    - #### releaseSSLContext

          protected abstract void releaseSSLContext(SSLHostConfig sslHostConfig)

      Release the SSLContext, if any, associated with the SSLHostConfig.
      Parameters:
        `sslHostConfig` - The SSLHostConfig for which the SSLContext should be released

    - #### getSSLHostConfig

          protected SSLHostConfig getSSLHostConfig(String sniHostName)

    - #### getUseSendfile

          public boolean getUseSendfile()

    - #### setUseSendfile

          public void setUseSendfile(boolean useSendfile)

    - #### getExecutorTerminationTimeoutMillis

          public long getExecutorTerminationTimeoutMillis()

    - #### setExecutorTerminationTimeoutMillis

          public void setExecutorTerminationTimeoutMillis(long executorTerminationTimeoutMillis)

    - #### setAcceptorThreadCount

          public void setAcceptorThreadCount(int acceptorThreadCount)

    - #### getAcceptorThreadCount

          public int getAcceptorThreadCount()

    - #### setAcceptorThreadPriority

          public void setAcceptorThreadPriority(int acceptorThreadPriority)

    - #### getAcceptorThreadPriority

          public int getAcceptorThreadPriority()

    - #### setMaxConnections

          public void setMaxConnections(int maxCon)

    - #### getMaxConnections

          public int getMaxConnections()

    - #### getConnectionCount

          public long getConnectionCount()

      Return the current count of connections handled by this endpoint, if the connections are counted (which happens when the maximum count of connections is limited), or `-1` if they are not. This property is added here so that this value can be inspected through JMX. It is visible on "ThreadPool" MBean.

      The count is incremented by the Acceptor before it tries to accept a new connection. Until the limit is reached and thus the count cannot be incremented, this value is more by 1 (the count of acceptors) than the actual count of connections that are being served.

      Returns:
        The count

    - #### setExecutor

          public void setExecutor(Executor executor)

    - #### getExecutor

          public Executor getExecutor()

    - #### getPort

          public int getPort()

    - #### setPort

          public void setPort(int port)

    - #### getLocalPort

          public final int getLocalPort()

    - #### getAddress

          public InetAddress getAddress()

    - #### setAddress

          public void setAddress(InetAddress address)

    - #### getLocalAddress

          protected abstract InetSocketAddress getLocalAddress()
                                                        throws IOException

      Obtain 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.
      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

    - #### setAcceptCount

          public void setAcceptCount(int acceptCount)

    - #### getAcceptCount

          public int getAcceptCount()

    - #### setBacklog

          @Deprecated
          public void setBacklog(int backlog)

      Deprecated.

    - #### getBacklog

          @Deprecated
          public int getBacklog()

      Deprecated.

    - #### getBindOnInit

          public boolean getBindOnInit()

    - #### setBindOnInit

          public void setBindOnInit(boolean b)

    - #### getKeepAliveTimeout

          public int getKeepAliveTimeout()

    - #### setKeepAliveTimeout

          public void setKeepAliveTimeout(int keepAliveTimeout)

    - #### getTcpNoDelay

          public boolean getTcpNoDelay()

      Socket TCP no delay.
      Returns:
        The current TCP no delay setting for sockets created by this endpoint

    - #### setTcpNoDelay

          public void setTcpNoDelay(boolean tcpNoDelay)

    - #### getConnectionLinger

          public int getConnectionLinger()

      Socket linger.
      Returns:
        The current socket linger time for sockets created by this endpoint

    - #### setConnectionLinger

          public void setConnectionLinger(int connectionLinger)

    - #### getSoLinger

          @Deprecated
          public int getSoLinger()

      Deprecated.

    - #### setSoLinger

          @Deprecated
          public void setSoLinger(int soLinger)

      Deprecated.

    - #### getConnectionTimeout

          public int getConnectionTimeout()

      Socket timeout.
      Returns:
        The current socket timeout for sockets created by this endpoint

    - #### setConnectionTimeout

          public void setConnectionTimeout(int soTimeout)

    - #### getSoTimeout

          @Deprecated
          public int getSoTimeout()

      Deprecated.

    - #### setSoTimeout

          @Deprecated
          public void setSoTimeout(int soTimeout)

      Deprecated.

    - #### isSSLEnabled

          public boolean isSSLEnabled()

    - #### setSSLEnabled

          public void setSSLEnabled(boolean SSLEnabled)

    - #### isAlpnSupported

          public abstract boolean isAlpnSupported()

      Identifies if the endpoint supports ALPN. Note that a return value of `true` implies that `isSSLEnabled()` will also return `true`.
      Returns:
        `true` if the endpoint supports ALPN in its current configuration, otherwise `false`.

    - #### setMinSpareThreads

          public void setMinSpareThreads(int minSpareThreads)

    - #### getMinSpareThreads

          public int getMinSpareThreads()

    - #### setMaxThreads

          public void setMaxThreads(int maxThreads)

    - #### getMaxThreads

          public int getMaxThreads()

    - #### setThreadPriority

          public void setThreadPriority(int threadPriority)

    - #### getThreadPriority

          public int getThreadPriority()

    - #### getMaxKeepAliveRequests

          public int getMaxKeepAliveRequests()

    - #### setMaxKeepAliveRequests

          public void setMaxKeepAliveRequests(int maxKeepAliveRequests)

    - #### getMaxHeaderCount

          public int getMaxHeaderCount()

    - #### setMaxHeaderCount

          public void setMaxHeaderCount(int maxHeaderCount)

    - #### setName

          public void setName(String name)

    - #### getName

          public String getName()

    - #### setDaemon

          public void setDaemon(boolean b)

    - #### getDaemon

          public boolean getDaemon()

    - #### getDeferAccept

          protected abstract boolean getDeferAccept()

    - #### addNegotiatedProtocol

          public void addNegotiatedProtocol(String negotiableProtocol)

    - #### hasNegotiableProtocols

          public boolean hasNegotiableProtocols()

    - #### setHandler

          public void setHandler(AbstractEndpoint.Handler<S> handler)

    - #### getHandler

          public AbstractEndpoint.Handler<S> getHandler()

    - #### setAttribute

          public void setAttribute(String name,
                          Object value)

      Generic property setter called when a property for which a specific setter already exists within the `ProtocolHandler` needs to be made available to sub-components. The specific setter will call this method to populate the attributes.
      Parameters:
        `name` - Name of property to set
        `value` - The value to set the property to

    - #### getAttribute

          public Object getAttribute(String key)

      Used by sub-components to retrieve configuration information.
      Parameters:
        `key` - The name of the property for which the value should be retrieved
      Returns:
        The value of the specified property

    - #### setProperty

          public boolean setProperty(String name,
                            String value)

    - #### getProperty

          public String getProperty(String name)

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

    - #### isRunning

          public boolean isRunning()

    - #### isPaused

          public boolean isPaused()

    - #### createExecutor

          public void createExecutor()

    - #### shutdownExecutor

          public void shutdownExecutor()

    - #### unlockAccept

          protected void unlockAccept()

      Unlock the server socket accept using a bogus connection.

    - #### processSocket

          public boolean processSocket(SocketWrapperBase<S> socketWrapper,
                              SocketEvent event,
                              boolean dispatch)

      Process the given SocketWrapper with the given status. Used to trigger processing as if the Poller (for those endpoints that have one) selected the socket.
      Parameters:
        `socketWrapper` - The socket wrapper to process
        `event` - The socket event to be processed
        `dispatch` - Should the processing be performed on a new container thread
      Returns:
        if processing was triggered successfully

    - #### createSocketProcessor

          protected abstract SocketProcessorBase<S> createSocketProcessor(SocketWrapperBase<S> socketWrapper,
                                                     SocketEvent event)

    - #### bind

          public abstract void bind()
                             throws Exception

      Throws:
        `Exception`

    - #### unbind

          public abstract void unbind()
                               throws Exception

      Throws:
        `Exception`

    - #### startInternal

          public abstract void startInternal()
                                      throws Exception

      Throws:
        `Exception`

    - #### stopInternal

          public abstract void stopInternal()
                                     throws Exception

      Throws:
        `Exception`

    - #### init

          public void init()
                    throws Exception

      Throws:
        `Exception`

    - #### start

          public final void start()
                           throws Exception

      Throws:
        `Exception`

    - #### startAcceptorThreads

          protected final void startAcceptorThreads()

    - #### createAcceptor

          protected abstract AbstractEndpoint.Acceptor createAcceptor()

      Hook to allow Endpoints to provide a specific Acceptor implementation.
      Returns:
        the acceptor

    - #### pause

          public void pause()

      Pause the endpoint, which will stop it accepting new connections.

    - #### resume

          public void resume()

      Resume the endpoint, which will make it start accepting new connections again.

    - #### stop

          public final void stop()
                          throws Exception

      Throws:
        `Exception`

    - #### destroy

          public final void destroy()
                             throws Exception

      Throws:
        `Exception`

    - #### getLog

          protected abstract Log getLog()

    - #### initializeConnectionLatch

          protected LimitLatch initializeConnectionLatch()

    - #### releaseConnectionLatch

          protected void releaseConnectionLatch()

    - #### countUpOrAwaitConnection

          protected void countUpOrAwaitConnection()
                                           throws InterruptedException

      Throws:
        `InterruptedException`

    - #### countDownConnection

          protected long countDownConnection()

    - #### handleExceptionWithDelay

          protected int handleExceptionWithDelay(int currentErrorDelay)

      Provides a common approach for sub-classes to handle exceptions where a delay is required to prevent a Thread from entering a tight loop which will consume CPU and may also trigger large amounts of logging. For example, this can happen with the Acceptor thread if the ulimit for open files is reached.
      Parameters:
        `currentErrorDelay` - The current delay being applied on failure
      Returns:
        The delay to apply on the next failure

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.