# Class AbstractEndpoint<S,U>

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

Type Parameters:
  `S` - The type used by the socket wrapper associated with this endpoint. Might be the same as U.
  `U` - The type of the underlying socket used by this endpoint. Might be the same as S.

Direct Known Subclasses:
  `AbstractJsseEndpoint`

public abstract class AbstractEndpoint<S,U> extends Object

Author:
  Mladen Turk, Remy Maucherat

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected static enum`
`AbstractEndpoint.BindState`
`static interface`
`AbstractEndpoint.Handler<S>`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Acceptor<U>`
`acceptor`
Thread used to accept new connections and pass them to worker threads.
`protected int`
`acceptorThreadPriority`
Priority of the acceptor threads.
`protected HashMap<String,Object>`
`attributes`
Attributes provide a way for configuration to be passed to subcomponents without the `ProtocolHandler` being aware of the properties available on those subcomponents.
`protected Map<U, SocketWrapperBase<S>>`
`connections`
Map holding all current connections keyed with the sockets.
`protected boolean`
`internalExecutor`
Are we using an internal executor
`protected final 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 final StringManager`
`sm`
`protected final SocketProperties`
`socketProperties`
Socket properties
`protected ConcurrentMap<String, SSLHostConfig>`
`sslHostConfigs`
`protected int`
`threadPriority`
Priority of the worker threads.

## Constructor Summary

Constructors
Constructor
Description
`AbstractEndpoint()`

## Method Summary

Modifier and Type
Method
Description
`void`
`addNegotiatedProtocol(String negotiableProtocol)`
`void`
`addSslHostConfig(SSLHostConfig sslHostConfig)`
Add the given SSL Host configuration.
`void`
`addSslHostConfig(SSLHostConfig sslHostConfig, boolean replace)`
Add the given SSL Host configuration, optionally replacing the existing configuration for the given host.
`final long`
`awaitConnectionsClose(long waitMillis)`
Wait for the client connections to the server to close gracefully.
`abstract void`
`bind()`
`final void`
`closeServerSocketGraceful()`
Close the server socket (to prevent further connections) if the server socket was originally bound on `start()` (rather than on `init()`).
`protected void`
`closeSocket(U socket)`
Close the socket when the connection has to be immediately closed when an error occurs while configuring the accepted socket or trying to dispatch it for processing.
`protected long`
`countDownConnection()`
`protected void`
`countUpOrAwaitConnection()`
`void`
`createExecutor()`
`protected abstract SocketProcessorBase<S>`
`createSocketProcessor(SocketWrapperBase<S> socketWrapper, SocketEvent event)`
`protected abstract void`
`createSSLContext(SSLHostConfig sslHostConfig)`
Create the SSLContext for the given SSLHostConfig.
`final void`
`destroy()`
`protected abstract void`
`destroySocket(U socket)`
Close the socket.
`protected void`
`destroySsl()`
`protected abstract void`
`doCloseServerSocket()`
Actually close the server socket but don't perform any other clean-up.
`SSLHostConfig[]`
`findSslHostConfigs()`
`protected String`
`generateCertificateDebug(X509Certificate certificate)`
`int`
`getAcceptCount()`
`int`
`getAcceptorThreadPriority()`
`InetAddress`
`getAddress()`
`Object`
`getAttribute(String key)`
Used by subcomponents to retrieve configuration information.
`boolean`
`getBindOnInit()`
`protected AbstractEndpoint.BindState`
`getBindState()`
`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.
`Set<SocketWrapperBase<S>>`
`getConnections()`
Get a set with the current open connections.
`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 boolean`
`getDeferAccept()`
Deprecated.
This code will be removed in Tomcat 11 onwards
`String`
`getDomain()`
`Executor`
`getExecutor()`
`long`
`getExecutorTerminationTimeoutMillis()`
`AbstractEndpoint.Handler<S>`
`getHandler()`
`String`
`getId()`
The default behavior is to identify connectors uniquely with address and port.
`int`
`getKeepAliveTimeout()`
`protected abstract InetSocketAddress`
`getLocalAddress()`
Obtain the network address the server socket is bound to.
`final int`
`getLocalPort()`
`protected abstract Log`
`getLog()`
`protected Log`
`getLogCertificate()`
`int`
`getMaxConnections()`
`int`
`getMaxKeepAliveRequests()`
`int`
`getMaxQueueSize()`
`int`
`getMaxThreads()`
`int`
`getMinSpareThreads()`
`String`
`getName()`
`int`
`getPort()`
`int`
`getPortOffset()`
`int`
`getPortWithOffset()`
`String`
`getProperty(String name)`
`SocketProperties`
`getSocketProperties()`
`protected SSLHostConfig`
`getSSLHostConfig(String sniHostName)`
Look up the SSLHostConfig for the given host name.
`boolean`
`getTcpNoDelay()`
Socket TCP no delay.
`int`
`getThreadPriority()`
`int`
`getThreadsMaxIdleTime()`
`boolean`
`getUseAsyncIO()`
`boolean`
`getUseSendfile()`
`boolean`
`getUseVirtualThreads()`
`ScheduledExecutorService`
`getUtilityExecutor()`
`boolean`
`hasNegotiableProtocols()`
`final void`
`init()`
`protected LimitLatch`
`initializeConnectionLatch()`
`boolean`
`isPaused()`
`boolean`
`isRunning()`
`boolean`
`isSSLEnabled()`
`protected void`
`logCertificate(SSLHostConfigCertificate certificate)`
`void`
`pause()`
Pause the endpoint, which will stop it accepting new connections and unlock the acceptor.
`boolean`
`processSocket(SocketWrapperBase<S> socketWrapper, SocketEvent event, boolean dispatch)`
Process the given SocketWrapper with the given status.
`protected void`
`releaseSSLContext(SSLHostConfig sslHostConfig)`
Release the SSLContext, if any, associated with the SSLHostConfig.
`void`
`reloadSslHostConfig(String hostName)`
Re-read the configuration files for the SSL host and replace the existing SSL configuration with the updated settings.
`void`
`reloadSslHostConfigs()`
Re-read the configuration files for all SSL hosts and replace the existing SSL configuration with the updated settings.
`SSLHostConfig`
`removeSslHostConfig(String hostName)`
Removes the SSL host configuration for the given host name, if such a configuration exists.
`void`
`resume()`
Resume the endpoint, which will make it start accepting new connections again.
`protected abstract U`
`serverSocketAccept()`
`void`
`setAcceptCount(int acceptCount)`
`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 subcomponents.
`void`
`setBindOnInit(boolean b)`
`void`
`setConnectionLinger(int connectionLinger)`
`void`
`setConnectionTimeout(int soTimeout)`
`void`
`setDaemon(boolean b)`
`void`
`setDefaultSSLHostConfigName(String defaultSSLHostConfigName)`
`void`
`setDomain(String domain)`
`void`
`setExecutor(Executor executor)`
`void`
`setExecutorTerminationTimeoutMillis(long executorTerminationTimeoutMillis)`
`void`
`setHandler(AbstractEndpoint.Handler<S> handler)`
`void`
`setKeepAliveTimeout(int keepAliveTimeout)`
`void`
`setMaxConnections(int maxCon)`
`void`
`setMaxKeepAliveRequests(int maxKeepAliveRequests)`
`void`
`setMaxQueueSize(int maxQueueSize)`
`void`
`setMaxThreads(int maxThreads)`
`void`
`setMinSpareThreads(int minSpareThreads)`
`void`
`setName(String name)`
`void`
`setPort(int port)`
`void`
`setPortOffset(int portOffset)`
`boolean`
`setProperty(String name, String value)`
`protected abstract boolean`
`setSocketOptions(U socket)`
`void`
`setSSLEnabled(boolean SSLEnabled)`
`void`
`setTcpNoDelay(boolean tcpNoDelay)`
`void`
`setThreadPriority(int threadPriority)`
`void`
`setThreadsMaxIdleTime(int threadsMaxIdleTime)`
`void`
`setUseAsyncIO(boolean useAsyncIO)`
`void`
`setUseSendfile(boolean useSendfile)`
`void`
`setUseVirtualThreads(boolean useVirtualThreads)`
`void`
`setUtilityExecutor(ScheduledExecutorService utilityExecutor)`
`void`
`shutdownExecutor()`
`final void`
`start()`
`protected void`
`startAcceptorThread()`
`abstract void`
`startInternal()`
`final void`
`stop()`
`abstract void`
`stopInternal()`
`static long`
`toTimeout(long timeout)`
`abstract void`
`unbind()`
`protected void`
`unlockAccept()`
Unlock the server socket acceptor threads using bogus connections.

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

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

## Field Details

### 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 final SocketProperties socketProperties
Socket properties

### acceptor

protected Acceptor<U> acceptor
Thread used to accept new connections and pass them to worker threads.

### processorCache

protected SynchronizedStack<SocketProcessorBase<S>> processorCache
Cache for SocketProcessor objects

### connections

protected Map<U, SocketWrapperBase<S>> connections
Map holding all current connections keyed with the sockets.

### sslHostConfigs

protected ConcurrentMap<String, SSLHostConfig> sslHostConfigs

### 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 subcomponents without the `ProtocolHandler` being aware of the properties available on those subcomponents.

## Constructor Details

### AbstractEndpoint

public AbstractEndpoint()

## Method Details

### toTimeout

public static long toTimeout(long timeout)

### getSocketProperties

public SocketProperties getSocketProperties()

### getConnections

public Set<SocketWrapperBase<S>> getConnections()
Get a set with the current open connections.

Returns:
  A set with the open socket wrappers

### getDefaultSSLHostConfigName

public String getDefaultSSLHostConfigName()

Returns:
  The host name for the default SSL configuration for this endpoint - always in lower case.

### setDefaultSSLHostConfigName

public void setDefaultSSLHostConfigName(String defaultSSLHostConfigName)

### addSslHostConfig

public void addSslHostConfig(SSLHostConfig sslHostConfig) throws IllegalArgumentException
Add the given SSL Host configuration.

Parameters:
  `sslHostConfig` - The configuration to add
Throws:
  `IllegalArgumentException` - If the host name is not valid or if a configuration has already been provided for that host

### addSslHostConfig

public void addSslHostConfig(SSLHostConfig sslHostConfig, boolean replace) throws IllegalArgumentException
Add the given SSL Host configuration, optionally replacing the existing configuration for the given host.

Parameters:
  `sslHostConfig` - The configuration to add
  `replace` - If `true` replacement of an existing configuration is permitted, otherwise any such attempted replacement will trigger an exception
Throws:
  `IllegalArgumentException` - If the host name is not valid or if a configuration has already been provided for that host and replacement is not allowed

### removeSslHostConfig

public SSLHostConfig removeSslHostConfig(String hostName)
Removes the SSL host configuration for the given host name, if such a configuration exists.

Parameters:
  `hostName` - The host name associated with the SSL host configuration to remove
Returns:
  The SSL host configuration that was removed, if any

### reloadSslHostConfig

public void reloadSslHostConfig(String hostName)
Re-read the configuration files for the SSL host and replace the existing SSL configuration with the updated settings. Note this replacement will happen even if the settings remain unchanged.

Parameters:
  `hostName` - The SSL host for which the configuration should be reloaded. This must match a current SSL host

### reloadSslHostConfigs

public void reloadSslHostConfigs()
Re-read the configuration files for all SSL hosts and replace the existing SSL configuration with the updated settings. Note this replacement will happen even if the settings remain unchanged.

### findSslHostConfigs

public SSLHostConfig[] findSslHostConfigs()

### createSSLContext

protected abstract void createSSLContext(SSLHostConfig sslHostConfig) throws Exception
Create the SSLContext for 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

### logCertificate

protected void logCertificate(SSLHostConfigCertificate certificate)

### generateCertificateDebug

protected String generateCertificateDebug(X509Certificate certificate)

### destroySsl

protected void destroySsl() throws Exception

Throws:
  `Exception`

### releaseSSLContext

protected 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)
Look up the SSLHostConfig for the given host name. Lookup order is:

1. exact match
2. wild card match
3. default SSLHostConfig

Parameters:
  `sniHostName` - Host name - must be in lower case
Returns:
  The SSLHostConfig for the given host name.

### getUseSendfile

public boolean getUseSendfile()

### setUseSendfile

public void setUseSendfile(boolean useSendfile)

### getExecutorTerminationTimeoutMillis

public long getExecutorTerminationTimeoutMillis()

### setExecutorTerminationTimeoutMillis

public void setExecutorTerminationTimeoutMillis(long executorTerminationTimeoutMillis)

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

### setUseVirtualThreads

public void setUseVirtualThreads(boolean useVirtualThreads)

### getUseVirtualThreads

public boolean getUseVirtualThreads()

### setUtilityExecutor

public void setUtilityExecutor(ScheduledExecutorService utilityExecutor)

### getUtilityExecutor

public ScheduledExecutorService getUtilityExecutor()

### getPort

public int getPort()

### setPort

public void setPort(int port)

### getPortOffset

public int getPortOffset()

### setPortOffset

public void setPortOffset(int portOffset)

### getPortWithOffset

public int getPortWithOffset()

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

### getBindOnInit

public boolean getBindOnInit()

### setBindOnInit

public void setBindOnInit(boolean b)

### getBindState

protected AbstractEndpoint.BindState getBindState()

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

### getConnectionTimeout

public int getConnectionTimeout()
Socket timeout.

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

### setConnectionTimeout

public void setConnectionTimeout(int soTimeout)

### isSSLEnabled

public boolean isSSLEnabled()

### setSSLEnabled

public void setSSLEnabled(boolean SSLEnabled)

### setMinSpareThreads

public void setMinSpareThreads(int minSpareThreads)

### getMinSpareThreads

public int getMinSpareThreads()

### setMaxThreads

public void setMaxThreads(int maxThreads)

### getMaxThreads

public int getMaxThreads()

### setMaxQueueSize

public void setMaxQueueSize(int maxQueueSize)

### getMaxQueueSize

public int getMaxQueueSize()

### setThreadsMaxIdleTime

public void setThreadsMaxIdleTime(int threadsMaxIdleTime)

### getThreadsMaxIdleTime

public int getThreadsMaxIdleTime()

### setThreadPriority

public void setThreadPriority(int threadPriority)

### getThreadPriority

public int getThreadPriority()

### getMaxKeepAliveRequests

public int getMaxKeepAliveRequests()

### setMaxKeepAliveRequests

public void setMaxKeepAliveRequests(int maxKeepAliveRequests)

### setName

public void setName(String name)

### getName

public String getName()

### setDomain

public void setDomain(String domain)

### getDomain

public String getDomain()

### setDaemon

public void setDaemon(boolean b)

### getDaemon

public boolean getDaemon()

### setUseAsyncIO

public void setUseAsyncIO(boolean useAsyncIO)

### getUseAsyncIO

public boolean getUseAsyncIO()

### getDeferAccept

@Deprecated protected boolean getDeferAccept()
Deprecated.
This code will be removed in Tomcat 11 onwards
Always returns `false`.

Returns:
  Always `false`

### getId

public String getId()
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.

Returns:
  the id

### 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 subcomponents. 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 subcomponents 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 acceptor threads using bogus connections.

### 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 final void init() throws Exception

Throws:
  `Exception`

### start

public final void start() throws Exception

Throws:
  `Exception`

### startAcceptorThread

protected void startAcceptorThread()

### pause

public void pause()
Pause the endpoint, which will stop it accepting new connections and unlock the acceptor.

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

### getLogCertificate

protected Log getLogCertificate()

### initializeConnectionLatch

protected LimitLatch initializeConnectionLatch()

### countUpOrAwaitConnection

protected void countUpOrAwaitConnection() throws InterruptedException

Throws:
  `InterruptedException`

### countDownConnection

protected long countDownConnection()

### closeServerSocketGraceful

public final void closeServerSocketGraceful()
Close the server socket (to prevent further connections) if the server socket was originally bound on `start()` (rather than on `init()`).

See Also:
  - `getBindOnInit()`

### awaitConnectionsClose

public final long awaitConnectionsClose(long waitMillis)
Wait for the client connections to the server to close gracefully. The method will return when all of the client connections have closed or the method has been waiting for `waitTimeMillis`.

Parameters:
  `waitMillis` - The maximum time to wait in milliseconds for the client connections to close.
Returns:
  The wait time, if any remaining when the method returned

### doCloseServerSocket

protected abstract void doCloseServerSocket() throws IOException
Actually close the server socket but don't perform any other clean-up.

Throws:
  `IOException` - If an error occurs closing the socket

### serverSocketAccept

protected abstract U serverSocketAccept() throws Exception

Throws:
  `Exception`

### setSocketOptions

protected abstract boolean setSocketOptions(U socket)

### closeSocket

protected void closeSocket(U socket)
Close the socket when the connection has to be immediately closed when an error occurs while configuring the accepted socket or trying to dispatch it for processing. The wrapper associated with the socket will be used for the close.

Parameters:
  `socket` - The newly accepted socket

### destroySocket

protected abstract void destroySocket(U socket)
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.

Parameters:
  `socket` - The newly accepted socket