Package org.apache.tomcat.util.net
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 java.lang.ObjectAbstract endpoint implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractEndpoint.BindStateEnum representing the possible states of the bind operation.static interfaceAbstractEndpoint.Handler<S>Interface for handlers used by an endpoint.
-
Field Summary
Fields Modifier and Type Field Description protected Acceptor<U>acceptorThread used to accept new connections and pass them to worker threads.protected intacceptorThreadPriorityPriority of the acceptor threads.protected java.util.HashMap<java.lang.String,java.lang.Object>attributesAttributes provide a way for configuration to be passed to subcomponents without theProtocolHandlerbeing aware of the properties available on those subcomponents.protected java.util.Map<U,SocketWrapperBase<S>>connectionsMap holding all current connections keyed with the sockets.protected booleaninternalExecutorAre we using an internal executorprotected java.util.List<java.lang.String>negotiableProtocolsList of protocols that can be negotiated (e.g.protected booleanpausedWill be set to true whenever the endpoint is paused.protected SynchronizedStack<SocketProcessorBase<S>>processorCacheCache for SocketProcessor objectsprotected booleanrunningRunning state of the endpoint.protected static StringManagersmString manager for this package.protected SocketPropertiessocketPropertiesSocket propertiesprotected java.util.concurrent.ConcurrentMap<java.lang.String,SSLHostConfig>sslHostConfigsMap of SSL host configurations keyed by host name.protected intthreadPriorityPriority of the worker threads.
-
Constructor Summary
Constructors Constructor Description AbstractEndpoint()Construct and return an endpoint.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddNegotiatedProtocol(java.lang.String negotiableProtocol)Add a protocol that can be negotiated (e.g.voidaddSslHostConfig(SSLHostConfig sslHostConfig)Add the given SSL Host configuration.voidaddSslHostConfig(SSLHostConfig sslHostConfig, boolean replace)Add the given SSL Host configuration, optionally replacing the existing configuration for the given host.longawaitConnectionsClose(long waitMillis)Wait for the client connections to the server to close gracefully.abstract voidbind()Bind the endpoint to its port and address.booleancheckSni(java.lang.String sniHostName, java.lang.String protocolHostName)Check if two host names share the same SSLHostConfig.voidcloseServerSocketGraceful()protected voidcloseSocket(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 longcountDownConnection()Count down a connection.protected voidcountUpOrAwaitConnection()Count up or await a connection slot.voidcreateExecutor()Create the internal executor.protected abstract SocketProcessorBase<S>createSocketProcessor(SocketWrapperBase<S> socketWrapper, SocketEvent event)Create a socket processor for the given socket wrapper.protected abstract voidcreateSSLContext(SSLHostConfig sslHostConfig)Create the SSLContext for the given SSLHostConfig.voiddestroy()Destroy the endpoint and release all resources.protected abstract voiddestroySocket(U socket)Close the socket.protected voiddestroySsl()Destroy the SSL configuration.protected abstract voiddoCloseServerSocket()Actually close the server socket but don't perform any other clean-up.SSLHostConfig[]findSslHostConfigs()Find all SSL host configurations.protected java.lang.StringgenerateCertificateDebug(java.security.cert.X509Certificate certificate)Generate debug information about a certificate.intgetAcceptCount()Get the accept count.intgetAcceptorThreadPriority()Get the acceptor thread priority.java.net.InetAddressgetAddress()Get the bind address.java.lang.ObjectgetAttribute(java.lang.String key)Used by subcomponents to retrieve configuration information.booleangetBindOnInit()Get the bind on init flag.protected AbstractEndpoint.BindStategetBindState()Get the current bind state.longgetConnectionCount()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-1if they are not.intgetConnectionLinger()Socket linger.java.util.Set<SocketWrapperBase<S>>getConnections()Get a set with the current open connections.intgetConnectionTimeout()Socket timeout.intgetCurrentThreadCount()Return the amount of threads that are managed by the pool.intgetCurrentThreadsBusy()Return the amount of threads that are in usebooleangetDaemon()Check if the threads are daemon threads.java.lang.StringgetDefaultSSLHostConfigName()Get the host name for the default SSL configuration for this endpoint - always in lower case.booleangetDeferAccept()Deprecated.This code will be removed in Tomcat 11 onwardsjava.lang.StringgetDomain()Get the JMX domain.java.util.concurrent.ExecutorgetExecutor()Get the external executor.longgetExecutorTerminationTimeoutMillis()Get the executor termination timeout.AbstractEndpoint.Handler<S>getHandler()Get the handler.java.lang.StringgetId()The default behavior is to identify connectors uniquely with address and port.intgetKeepAliveTimeout()Get the keepalive timeout.protected abstract java.net.InetSocketAddressgetLocalAddress()Obtain the network address the server socket is bound to.intgetLocalPort()Get the local port the server socket is bound to.protected abstract LoggetLog()Get the logger for this endpoint.protected LoggetLogCertificate()Get the logger for certificate-related messages.intgetMaxConnections()Get the maximum number of connections.intgetMaxKeepAliveRequests()Get the maximum number of keep alive requests.intgetMaxQueueSize()Get the maximum queue size.intgetMaxThreads()Get the maximum number of worker threads.intgetMinSpareThreads()Get the minimum number of spare threads.java.lang.StringgetName()Get the name of the thread pool.intgetPort()Get the server socket port.intgetPortOffset()Get the port offset.intgetPortWithOffset()Get the port with offset applied.java.lang.StringgetProperty(java.lang.String name)Get the value of the specified property.SocketPropertiesgetSocketProperties()Get the socket properties.protected SSLHostConfiggetSSLHostConfig(java.lang.String sniHostName)Look up the SSLHostConfig for the given host name.booleangetStrictSni()Get the strict SNI check flag.booleangetTcpNoDelay()Socket TCP no delay.intgetThreadPriority()Get the priority of the worker threads.intgetThreadsMaxIdleTime()Get the maximum idle time for threads in the internal thread pool.booleangetUseAsyncIO()Check if asynchronous IO is enabled.booleangetUseSendfile()Get the sendfile flag.booleangetUseVirtualThreads()Get whether virtual threads are enabled.java.util.concurrent.ScheduledExecutorServicegetUtilityExecutor()Get the utility executor.booleanhasNegotiableProtocols()Check if there are any negotiable protocols configured.voidinit()Initialize the endpoint.protected LimitLatchinitializeConnectionLatch()Initialize the connection latch if it has not already been created.booleanisPaused()Check if the endpoint is paused.booleanisRunning()Check if the endpoint is running.booleanisSSLEnabled()Check if SSL is enabled.protected voidlogCertificate(SSLHostConfigCertificate certificate)Log information about the given certificate.voidpause()Pause the endpoint, which will stop it accepting new connections and unlock the acceptor.booleanprocessSocket(SocketWrapperBase<S> socketWrapper, SocketEvent event, boolean dispatch)Process the given SocketWrapper with the given status.protected voidreleaseSSLContext(SSLHostConfig sslHostConfig)Release the SSLContext, if any, associated with the SSLHostConfig.voidreloadSslHostConfig(java.lang.String hostName)Re-read the configuration files for the SSL host and replace the existing SSL configuration with the updated settings.voidreloadSslHostConfigs()Re-read the configuration files for all SSL hosts and replace the existing SSL configuration with the updated settings.SSLHostConfigremoveSslHostConfig(java.lang.String hostName)Removes the SSL host configuration for the given host name, if such a configuration exists.voidresume()Resume the endpoint, which will make it start accepting new connections again.protected abstract UserverSocketAccept()Accept a connection from the server socket.voidsetAcceptCount(int acceptCount)Set the accept count.voidsetAcceptorThreadPriority(int acceptorThreadPriority)Set the acceptor thread priority.voidsetAddress(java.net.InetAddress address)Set the bind address.voidsetAttribute(java.lang.String name, java.lang.Object value)Generic property setter called when a property for which a specific setter already exists within theProtocolHandlerneeds to be made available to subcomponents.voidsetBindOnInit(boolean b)Set the bind on init flag.voidsetConnectionLinger(int connectionLinger)Set the connection linger time.voidsetConnectionTimeout(int soTimeout)Set the connection timeout.voidsetDaemon(boolean b)Set whether the threads should be daemon threads.voidsetDefaultSSLHostConfigName(java.lang.String defaultSSLHostConfigName)Set the host name for the default SSL configuration.voidsetDomain(java.lang.String domain)Set the domain for JMX registration.voidsetExecutor(java.util.concurrent.Executor executor)Set the external executor.voidsetExecutorTerminationTimeoutMillis(long executorTerminationTimeoutMillis)Set the executor termination timeout.voidsetHandler(AbstractEndpoint.Handler<S> handler)Set the handler for this endpoint.voidsetKeepAliveTimeout(int keepAliveTimeout)Set the keepalive timeout.voidsetMaxConnections(int maxCon)Set the maximum number of connections.voidsetMaxKeepAliveRequests(int maxKeepAliveRequests)Set the maximum number of keep alive requests.voidsetMaxQueueSize(int maxQueueSize)Set the maximum task queue size.voidsetMaxThreads(int maxThreads)Set the maximum number of worker threads.voidsetMinSpareThreads(int minSpareThreads)Set the minimum number of spare threads.voidsetName(java.lang.String name)Set the name of the thread pool.voidsetPort(int port)Set the server socket port.voidsetPortOffset(int portOffset)Set the port offset.booleansetProperty(java.lang.String name, java.lang.String value)Set the specified property.protected abstract booleansetSocketOptions(U socket)Set the socket options for the given accepted socket.voidsetSSLEnabled(boolean SSLEnabled)Set the SSL enabled flag.voidsetStrictSni(boolean strictSni)Set the strict SNI check flag.voidsetTcpNoDelay(boolean tcpNoDelay)Set the TCP no delay flag.voidsetThreadPriority(int threadPriority)Set the priority of the worker threads.voidsetThreadsMaxIdleTime(int threadsMaxIdleTime)Set the maximum idle time for threads in the internal thread pool.voidsetUseAsyncIO(boolean useAsyncIO)Set whether asynchronous IO is enabled.voidsetUseSendfile(boolean useSendfile)Set the sendfile flag.voidsetUseVirtualThreads(boolean useVirtualThreads)Set whether virtual threads should be used.voidsetUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor)Set the utility executor.voidshutdownExecutor()Shutdown the internal executor.voidstart()Start the endpoint.protected voidstartAcceptorThread()Start the acceptor thread.abstract voidstartInternal()Start the endpoint internal components.voidstop()Stop the endpoint.abstract voidstopInternal()Stop the endpoint internal components.static longtoTimeout(long timeout)Convert a timeout value to a positive timeout suitable for use with socket operations.abstract voidunbind()protected voidunlockAccept()Unlock the server socket acceptor threads using bogus connections.
-
-
-
Field Detail
-
sm
protected static final StringManager sm
String manager for this package.
-
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 java.util.Map<U,SocketWrapperBase<S>> connections
Map holding all current connections keyed with the sockets.
-
sslHostConfigs
protected java.util.concurrent.ConcurrentMap<java.lang.String,SSLHostConfig> sslHostConfigs
Map of SSL host configurations keyed by host name.
-
acceptorThreadPriority
protected int acceptorThreadPriority
Priority of the acceptor threads.
-
threadPriority
protected int threadPriority
Priority of the worker threads.
-
negotiableProtocols
protected final java.util.List<java.lang.String> negotiableProtocols
List of protocols that can be negotiated (e.g. ALPN).
-
attributes
protected java.util.HashMap<java.lang.String,java.lang.Object> attributes
Attributes provide a way for configuration to be passed to subcomponents without theProtocolHandlerbeing aware of the properties available on those subcomponents.
-
-
Method Detail
-
toTimeout
public static long toTimeout(long timeout)
Convert a timeout value to a positive timeout suitable for use with socket operations.- Parameters:
timeout- The timeout value in milliseconds. If less than or equal to 0, returnsLong.MAX_VALUE.- Returns:
- The timeout value, or
Long.MAX_VALUEif the input is less than or equal to 0
-
getSocketProperties
public SocketProperties getSocketProperties()
Get the socket properties.- Returns:
- The socket properties
-
getConnections
public java.util.Set<SocketWrapperBase<S>> getConnections()
Get a set with the current open connections.- Returns:
- A set with the open socket wrappers
-
getStrictSni
public boolean getStrictSni()
Get the strict SNI check flag.- Returns:
- True if strict SNI checking is enabled
-
setStrictSni
public void setStrictSni(boolean strictSni)
Set the strict SNI check flag.- Parameters:
strictSni- True to enable strict SNI checking
-
getDefaultSSLHostConfigName
public java.lang.String getDefaultSSLHostConfigName()
Get the host name for the default SSL configuration for this endpoint - always in lower case.- Returns:
- The host name for the default SSL configuration for this endpoint - always in lower case.
-
setDefaultSSLHostConfigName
public void setDefaultSSLHostConfigName(java.lang.String defaultSSLHostConfigName)
Set the host name for the default SSL configuration.- Parameters:
defaultSSLHostConfigName- The default SSL host configuration name
-
addSslHostConfig
public void addSslHostConfig(SSLHostConfig sslHostConfig) throws java.lang.IllegalArgumentException
Add the given SSL Host configuration.- Parameters:
sslHostConfig- The configuration to add- Throws:
java.lang.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 java.lang.IllegalArgumentException
Add the given SSL Host configuration, optionally replacing the existing configuration for the given host.- Parameters:
sslHostConfig- The configuration to addreplace- Iftruereplacement of an existing configuration is permitted, otherwise any such attempted replacement will trigger an exception- Throws:
java.lang.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(java.lang.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(java.lang.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()
Find all SSL host configurations.- Returns:
- An array of all SSL host configurations
-
createSSLContext
protected abstract void createSSLContext(SSLHostConfig sslHostConfig) throws java.lang.Exception
Create the SSLContext for the given SSLHostConfig.- Parameters:
sslHostConfig- The SSLHostConfig for which the SSLContext should be created- Throws:
java.lang.Exception- If the SSLContext cannot be created for the given SSLHostConfig
-
logCertificate
protected void logCertificate(SSLHostConfigCertificate certificate)
Log information about the given certificate.- Parameters:
certificate- The certificate to log information about
-
generateCertificateDebug
protected java.lang.String generateCertificateDebug(java.security.cert.X509Certificate certificate)
Generate debug information about a certificate.- Parameters:
certificate- The certificate to generate debug info for- Returns:
- A string containing certificate debug information
-
destroySsl
protected void destroySsl() throws java.lang.ExceptionDestroy the SSL configuration.- Throws:
java.lang.Exception- If an error occurs while destroying SSL
-
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(java.lang.String sniHostName)
Look up the SSLHostConfig for the given host name. Lookup order is:- exact match
- wild card match
- default SSLHostConfig
- Parameters:
sniHostName- Host name - must be in lower case- Returns:
- The SSLHostConfig for the given host name.
-
checkSni
public boolean checkSni(java.lang.String sniHostName, java.lang.String protocolHostName)Check if two host names share the same SSLHostConfig.- Parameters:
sniHostName- the host name from SNI, null if SNI is not in useprotocolHostName- the host name from the protocol- Returns:
- true if SNI is not checked, if the SNI host name matches the protocol host name, if both host names use the same SSLHostConfig configuration, if there is no SNI and the protocol host name uses the default SSLHostConfig configuration, and false otherwise
-
getUseSendfile
public boolean getUseSendfile()
Get the sendfile flag.- Returns:
- True if sendfile is enabled
-
setUseSendfile
public void setUseSendfile(boolean useSendfile)
Set the sendfile flag.- Parameters:
useSendfile- True to enable sendfile
-
getExecutorTerminationTimeoutMillis
public long getExecutorTerminationTimeoutMillis()
Get the executor termination timeout.- Returns:
- The executor termination timeout in milliseconds
-
setExecutorTerminationTimeoutMillis
public void setExecutorTerminationTimeoutMillis(long executorTerminationTimeoutMillis)
Set the executor termination timeout.- Parameters:
executorTerminationTimeoutMillis- The timeout in milliseconds
-
setAcceptorThreadPriority
public void setAcceptorThreadPriority(int acceptorThreadPriority)
Set the acceptor thread priority.- Parameters:
acceptorThreadPriority- The thread priority
-
getAcceptorThreadPriority
public int getAcceptorThreadPriority()
Get the acceptor thread priority.- Returns:
- The acceptor thread priority
-
setMaxConnections
public void setMaxConnections(int maxCon)
Set the maximum number of connections.- Parameters:
maxCon- The maximum number of connections (-1 for unlimited)
-
getMaxConnections
public int getMaxConnections()
Get the maximum number of connections.- Returns:
- The maximum number of connections
-
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-1if 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(java.util.concurrent.Executor executor)
Set the external executor.- Parameters:
executor- The external executor (null to use internal executor)
-
getExecutor
public java.util.concurrent.Executor getExecutor()
Get the external executor.- Returns:
- The external executor, or null if none is configured
-
setUseVirtualThreads
public void setUseVirtualThreads(boolean useVirtualThreads)
Set whether virtual threads should be used.- Parameters:
useVirtualThreads- True to use virtual threads
-
getUseVirtualThreads
public boolean getUseVirtualThreads()
Get whether virtual threads are enabled.- Returns:
- True if virtual threads are enabled
-
setUtilityExecutor
public void setUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor)
Set the utility executor.- Parameters:
utilityExecutor- The utility executor
-
getUtilityExecutor
public java.util.concurrent.ScheduledExecutorService getUtilityExecutor()
Get the utility executor.- Returns:
- The utility executor
-
getPort
public int getPort()
Get the server socket port.- Returns:
- The server socket port
-
setPort
public void setPort(int port)
Set the server socket port.- Parameters:
port- The server socket port
-
getPortOffset
public int getPortOffset()
Get the port offset.- Returns:
- The port offset
-
setPortOffset
public void setPortOffset(int portOffset)
Set the port offset.- Parameters:
portOffset- The port offset (must be >= 0)
-
getPortWithOffset
public int getPortWithOffset()
Get the port with offset applied.- Returns:
- The port with offset, or the port if port <= 0
-
getLocalPort
public final int getLocalPort()
Get the local port the server socket is bound to.- Returns:
- The local port or -1 if not bound
-
getAddress
public java.net.InetAddress getAddress()
Get the bind address.- Returns:
- The bind address
-
setAddress
public void setAddress(java.net.InetAddress address)
Set the bind address.- Parameters:
address- The bind address
-
getLocalAddress
protected abstract java.net.InetSocketAddress getLocalAddress() throws java.io.IOExceptionObtain 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:
java.io.IOException- If there is a problem determining the currently bound socket
-
setAcceptCount
public void setAcceptCount(int acceptCount)
Set the accept count.- Parameters:
acceptCount- The accept count (must be > 0)
-
getAcceptCount
public int getAcceptCount()
Get the accept count.- Returns:
- The accept count
-
getBindOnInit
public boolean getBindOnInit()
Get the bind on init flag.- Returns:
- True if the endpoint binds on init, false if it binds on start
-
setBindOnInit
public void setBindOnInit(boolean b)
Set the bind on init flag.- Parameters:
b- True to bind on init, false to bind on start
-
getBindState
protected AbstractEndpoint.BindState getBindState()
Get the current bind state.- Returns:
- The current bind state
-
getKeepAliveTimeout
public int getKeepAliveTimeout()
Get the keepalive timeout.- Returns:
- The keepalive timeout in milliseconds
-
setKeepAliveTimeout
public void setKeepAliveTimeout(int keepAliveTimeout)
Set the keepalive timeout.- Parameters:
keepAliveTimeout- The keepalive timeout in milliseconds
-
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)
Set the TCP no delay flag.- Parameters:
tcpNoDelay- True to enable TCP no delay
-
getConnectionLinger
public int getConnectionLinger()
Socket linger.- Returns:
- The current socket linger time for sockets created by this endpoint
-
setConnectionLinger
public void setConnectionLinger(int connectionLinger)
Set the connection linger time.- Parameters:
connectionLinger- The socket linger time in seconds
-
getConnectionTimeout
public int getConnectionTimeout()
Socket timeout.- Returns:
- The current socket timeout for sockets created by this endpoint
-
setConnectionTimeout
public void setConnectionTimeout(int soTimeout)
Set the connection timeout.- Parameters:
soTimeout- The socket timeout in milliseconds
-
isSSLEnabled
public boolean isSSLEnabled()
Check if SSL is enabled.- Returns:
- True if SSL is enabled
-
setSSLEnabled
public void setSSLEnabled(boolean SSLEnabled)
Set the SSL enabled flag.- Parameters:
SSLEnabled- True to enable SSL
-
setMinSpareThreads
public void setMinSpareThreads(int minSpareThreads)
Set the minimum number of spare threads.- Parameters:
minSpareThreads- The minimum number of spare threads
-
getMinSpareThreads
public int getMinSpareThreads()
Get the minimum number of spare threads.- Returns:
- The minimum number of spare threads
-
setMaxThreads
public void setMaxThreads(int maxThreads)
Set the maximum number of worker threads.- Parameters:
maxThreads- The maximum number of worker threads
-
getMaxThreads
public int getMaxThreads()
Get the maximum number of worker threads.- Returns:
- The maximum number of worker threads, or -1 if no internal executor is used
-
setMaxQueueSize
public void setMaxQueueSize(int maxQueueSize)
Set the maximum task queue size.- Parameters:
maxQueueSize- The maximum queue size
-
getMaxQueueSize
public int getMaxQueueSize()
Get the maximum queue size.- Returns:
- The maximum queue size
-
setThreadsMaxIdleTime
public void setThreadsMaxIdleTime(int threadsMaxIdleTime)
Set the maximum idle time for threads in the internal thread pool.- Parameters:
threadsMaxIdleTime- The maximum idle time in milliseconds
-
getThreadsMaxIdleTime
public int getThreadsMaxIdleTime()
Get the maximum idle time for threads in the internal thread pool.- Returns:
- The maximum idle time in milliseconds, or -1 if no internal executor is used
-
setThreadPriority
public void setThreadPriority(int threadPriority)
Set the priority of the worker threads.- Parameters:
threadPriority- The thread priority
-
getThreadPriority
public int getThreadPriority()
Get the priority of the worker threads.- Returns:
- The thread priority, or -1 if no internal executor is used
-
getMaxKeepAliveRequests
public int getMaxKeepAliveRequests()
Get the maximum number of keep alive requests.- Returns:
- The maximum number of keep alive requests
-
setMaxKeepAliveRequests
public void setMaxKeepAliveRequests(int maxKeepAliveRequests)
Set the maximum number of keep alive requests.- Parameters:
maxKeepAliveRequests- The maximum number of keep alive requests
-
setName
public void setName(java.lang.String name)
Set the name of the thread pool.- Parameters:
name- The name of the thread pool
-
getName
public java.lang.String getName()
Get the name of the thread pool.- Returns:
- The name of the thread pool
-
setDomain
public void setDomain(java.lang.String domain)
Set the domain for JMX registration.- Parameters:
domain- The JMX domain
-
getDomain
public java.lang.String getDomain()
Get the JMX domain.- Returns:
- The JMX domain, or null if not set
-
setDaemon
public void setDaemon(boolean b)
Set whether the threads should be daemon threads.- Parameters:
b- True to use daemon threads
-
getDaemon
public boolean getDaemon()
Check if the threads are daemon threads.- Returns:
- True if the threads are daemon threads
-
setUseAsyncIO
public void setUseAsyncIO(boolean useAsyncIO)
Set whether asynchronous IO is enabled.- Parameters:
useAsyncIO- True to enable asynchronous IO
-
getUseAsyncIO
public boolean getUseAsyncIO()
Check if asynchronous IO is enabled.- Returns:
- True if asynchronous IO is enabled
-
getDeferAccept
@Deprecated public boolean getDeferAccept()
Deprecated.This code will be removed in Tomcat 11 onwardsAlways returnsfalse.- Returns:
- Always
false
-
getId
public java.lang.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(java.lang.String negotiableProtocol)
Add a protocol that can be negotiated (e.g. ALPN).- Parameters:
negotiableProtocol- The protocol to add
-
hasNegotiableProtocols
public boolean hasNegotiableProtocols()
Check if there are any negotiable protocols configured.- Returns:
- True if there are negotiable protocols
-
setHandler
public void setHandler(AbstractEndpoint.Handler<S> handler)
Set the handler for this endpoint.- Parameters:
handler- The handler to set
-
getHandler
public AbstractEndpoint.Handler<S> getHandler()
Get the handler.- Returns:
- The handler
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)Generic property setter called when a property for which a specific setter already exists within theProtocolHandlerneeds to be made available to subcomponents. The specific setter will call this method to populate the attributes.- Parameters:
name- Name of property to setvalue- The value to set the property to
-
getAttribute
public java.lang.Object getAttribute(java.lang.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(java.lang.String name, java.lang.String value)Set the specified property.- Parameters:
name- The name of the propertyvalue- The value of the property- Returns:
- True if the property was set successfully
-
getProperty
public java.lang.String getProperty(java.lang.String name)
Get the value of the specified property.- Parameters:
name- The name of the property- Returns:
- The value of the property, or null if not found
-
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()
Check if the endpoint is running.- Returns:
- True if the endpoint is running
-
isPaused
public boolean isPaused()
Check if the endpoint is paused.- Returns:
- True if the endpoint is paused
-
createExecutor
public void createExecutor()
Create the internal executor.
-
shutdownExecutor
public void shutdownExecutor()
Shutdown the internal executor.
-
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 processevent- The socket event to be processeddispatch- 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)
Create a socket processor for the given socket wrapper.- Parameters:
socketWrapper- The socket wrapper to processevent- The socket event- Returns:
- The socket processor
-
bind
public abstract void bind() throws java.lang.ExceptionBind the endpoint to its port and address.- Throws:
java.lang.Exception- If an error occurs during binding
-
unbind
public abstract void unbind() throws java.lang.Exception- Throws:
java.lang.Exception
-
startInternal
public abstract void startInternal() throws java.lang.ExceptionStart the endpoint internal components.- Throws:
java.lang.Exception- If an error occurs during startup
-
stopInternal
public abstract void stopInternal() throws java.lang.ExceptionStop the endpoint internal components.- Throws:
java.lang.Exception- If an error occurs during shutdown
-
init
public final void init() throws java.lang.ExceptionInitialize the endpoint.- Throws:
java.lang.Exception- If an error occurs during initialization
-
start
public final void start() throws java.lang.ExceptionStart the endpoint.- Throws:
java.lang.Exception- If an error occurs during startup
-
startAcceptorThread
protected void startAcceptorThread()
Start the acceptor thread.
-
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 java.lang.ExceptionStop the endpoint.- Throws:
java.lang.Exception- If an error occurs during shutdown
-
destroy
public final void destroy() throws java.lang.ExceptionDestroy the endpoint and release all resources.- Throws:
java.lang.Exception- If an error occurs while destroying the endpoint
-
getLog
protected abstract Log getLog()
Get the logger for this endpoint.- Returns:
- The logger
-
getLogCertificate
protected Log getLogCertificate()
Get the logger for certificate-related messages.- Returns:
- The logger (defaults to
getLog())
-
initializeConnectionLatch
protected LimitLatch initializeConnectionLatch()
Initialize the connection latch if it has not already been created.- Returns:
- The connection latch, or null if connection counting is disabled
-
countUpOrAwaitConnection
protected void countUpOrAwaitConnection() throws java.lang.InterruptedExceptionCount up or await a connection slot.- Throws:
java.lang.InterruptedException- If thrown during thread interruption
-
countDownConnection
protected long countDownConnection()
Count down a connection.- Returns:
- The number of connections remaining, or -1 if connection counting is disabled
-
closeServerSocketGraceful
public final void closeServerSocketGraceful()
Close the server socket (to prevent further connections) if the server socket was originally bound onstart()(rather than oninit()).- 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 forwaitTimeMillis.- 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 java.io.IOExceptionActually close the server socket but don't perform any other clean-up.- Throws:
java.io.IOException- If an error occurs closing the socket
-
serverSocketAccept
protected abstract U serverSocketAccept() throws java.lang.Exception
Accept a connection from the server socket.- Returns:
- The accepted socket
- Throws:
java.lang.Exception- If an error occurs during accept
-
setSocketOptions
protected abstract boolean setSocketOptions(U socket)
Set the socket options for the given accepted socket.- Parameters:
socket- The accepted socket- Returns:
- True if the socket options were set successfully
-
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
-
-