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. May be the same as U.
- U- The type of the underlying socket used by this endpoint. May be the same as S.
- Direct Known Subclasses:
- AbstractJsseEndpoint
- Author:
- Mladen Turk, Remy Maucherat
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static enumstatic interface
- 
Field SummaryFieldsModifier and TypeFieldDescriptionThread used to accept new connections and pass them to worker threads.protected intPriority of the acceptor threads.Attributes provide a way for configuration to be passed to sub-components without theProtocolHandlerbeing aware of the properties available on those sub-components.protected Map<U,SocketWrapperBase<S>> Map holding all current connections keyed with the sockets.protected booleanAre we using an internal executorprotected booleanWill be set to true whenever the endpoint is paused.protected SynchronizedStack<SocketProcessorBase<S>>Cache for SocketProcessor objectsprotected booleanRunning state of the endpoint.protected static final StringManagerprotected final SocketPropertiesSocket propertiesprotected ConcurrentMap<String,SSLHostConfig> protected intPriority of the worker threads.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddNegotiatedProtocol(String negotiableProtocol) 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.final longawaitConnectionsClose(long waitMillis) Wait for the client connections to the server to close gracefully.abstract voidbind()final voidprotected 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 longprotected voidvoidprotected abstract SocketProcessorBase<S>createSocketProcessor(SocketWrapperBase<S> socketWrapper, SocketEvent event) protected abstract voidcreateSSLContext(SSLHostConfig sslHostConfig) Create the SSLContext for the given SSLHostConfig.final voiddestroy()protected abstract voiddestroySocket(U socket) Close the socket.protected voidprotected abstract voidActually close the server socket but don't perform any other clean-up.protected StringgenerateCertificateDebug(X509Certificate certificate) intintgetAttribute(String key) Used by sub-components to retrieve configuration information.booleanprotected AbstractEndpoint.BindStatelongReturn 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.intSocket linger.Get a set with the current open connections.intSocket timeout.intReturn the amount of threads that are managed by the pool.intReturn the amount of threads that are in usebooleanprotected booleanDeprecated.This code will be removed in Tomcat 11 onwardslonggetId()The default behavior is to identify connectors uniquely with address and port.intprotected abstract InetSocketAddressObtain the network address the server socket is bound to.final intprotected abstract LoggetLog()protected LogintintintintgetName()intgetPort()intintgetProperty(String name) protected SSLHostConfiggetSSLHostConfig(String sniHostName) Look up the SSLHostConfig for the given host name.booleanSocket TCP no delay.intintbooleanbooleanbooleanbooleanfinal voidinit()protected LimitLatchbooleanisPaused()booleanbooleanprotected voidlogCertificate(SSLHostConfigCertificate 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(String hostName) Re-read the configuration files for the SSL host and replace the existing SSL configuration with the updated settings.voidRe-read the configuration files for all SSL hosts and replace the existing SSL configuration with the updated settings.removeSslHostConfig(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 UvoidsetAcceptCount(int acceptCount) voidsetAcceptorThreadPriority(int acceptorThreadPriority) voidsetAddress(InetAddress address) voidsetAttribute(String name, Object value) Generic property setter called when a property for which a specific setter already exists within theProtocolHandlerneeds to be made available to sub-components.voidsetBindOnInit(boolean b) voidsetConnectionLinger(int connectionLinger) voidsetConnectionTimeout(int soTimeout) voidsetDaemon(boolean b) voidsetDefaultSSLHostConfigName(String defaultSSLHostConfigName) voidvoidsetExecutor(Executor executor) voidsetExecutorTerminationTimeoutMillis(long executorTerminationTimeoutMillis) voidsetHandler(AbstractEndpoint.Handler<S> handler) voidsetKeepAliveTimeout(int keepAliveTimeout) voidsetMaxConnections(int maxCon) voidsetMaxKeepAliveRequests(int maxKeepAliveRequests) voidsetMaxThreads(int maxThreads) voidsetMinSpareThreads(int minSpareThreads) voidvoidsetPort(int port) voidsetPortOffset(int portOffset) booleansetProperty(String name, String value) protected abstract booleansetSocketOptions(U socket) voidsetSSLEnabled(boolean SSLEnabled) voidsetTcpNoDelay(boolean tcpNoDelay) voidsetThreadPriority(int threadPriority) voidsetThreadsMaxIdleTime(int threadsMaxIdleTime) voidsetUseAsyncIO(boolean useAsyncIO) voidsetUseSendfile(boolean useSendfile) voidsetUseVirtualThreads(boolean useVirtualThreads) voidsetUtilityExecutor(ScheduledExecutorService utilityExecutor) voidfinal voidstart()protected voidabstract voidfinal voidstop()abstract voidstatic longtoTimeout(long timeout) abstract voidunbind()protected voidUnlock the server socket acceptor threads using bogus connections.
- 
Field Details- 
sm
- 
runningprotected volatile boolean runningRunning state of the endpoint.
- 
pausedprotected volatile boolean pausedWill be set to true whenever the endpoint is paused.
- 
internalExecutorprotected volatile boolean internalExecutorAre we using an internal executor
- 
socketPropertiesSocket properties
- 
acceptorThread used to accept new connections and pass them to worker threads.
- 
processorCacheCache for SocketProcessor objects
- 
connectionsMap holding all current connections keyed with the sockets.
- 
sslHostConfigs
- 
acceptorThreadPriorityprotected int acceptorThreadPriorityPriority of the acceptor threads.
- 
threadPriorityprotected int threadPriorityPriority of the worker threads.
- 
negotiableProtocols
- 
attributesAttributes provide a way for configuration to be passed to sub-components without theProtocolHandlerbeing aware of the properties available on those sub-components.
 
- 
- 
Constructor Details- 
AbstractEndpointpublic AbstractEndpoint()
 
- 
- 
Method Details- 
toTimeoutpublic static long toTimeout(long timeout) 
- 
getSocketProperties
- 
getConnectionsGet a set with the current open connections.- Returns:
- A set with the open socket wrappers
 
- 
getDefaultSSLHostConfigName- Returns:
- The host name for the default SSL configuration for this endpoint - always in lower case.
 
- 
setDefaultSSLHostConfigName
- 
addSslHostConfigAdd 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
 
- 
addSslHostConfigpublic 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- truereplacement 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
 
- 
removeSslHostConfigRemoves 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
 
- 
reloadSslHostConfigRe-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
 
- 
reloadSslHostConfigspublic 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
- 
createSSLContextCreate 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
- 
generateCertificateDebug
- 
destroySsl- Throws:
- Exception
 
- 
releaseSSLContextRelease the SSLContext, if any, associated with the SSLHostConfig.- Parameters:
- sslHostConfig- The SSLHostConfig for which the SSLContext should be released
 
- 
getSSLHostConfigLook 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.
 
- 
getUseSendfilepublic boolean getUseSendfile()
- 
setUseSendfilepublic void setUseSendfile(boolean useSendfile) 
- 
getExecutorTerminationTimeoutMillispublic long getExecutorTerminationTimeoutMillis()
- 
setExecutorTerminationTimeoutMillispublic void setExecutorTerminationTimeoutMillis(long executorTerminationTimeoutMillis) 
- 
setAcceptorThreadPrioritypublic void setAcceptorThreadPriority(int acceptorThreadPriority) 
- 
getAcceptorThreadPrioritypublic int getAcceptorThreadPriority()
- 
setMaxConnectionspublic void setMaxConnections(int maxCon) 
- 
getMaxConnectionspublic int getMaxConnections()
- 
getConnectionCountpublic 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
- 
getExecutor
- 
setUseVirtualThreadspublic void setUseVirtualThreads(boolean useVirtualThreads) 
- 
getUseVirtualThreadspublic boolean getUseVirtualThreads()
- 
setUtilityExecutor
- 
getUtilityExecutor
- 
getPortpublic int getPort()
- 
setPortpublic void setPort(int port) 
- 
getPortOffsetpublic int getPortOffset()
- 
setPortOffsetpublic void setPortOffset(int portOffset) 
- 
getPortWithOffsetpublic int getPortWithOffset()
- 
getLocalPortpublic final int getLocalPort()
- 
getAddress
- 
setAddress
- 
getLocalAddressObtain 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
 
- 
setAcceptCountpublic void setAcceptCount(int acceptCount) 
- 
getAcceptCountpublic int getAcceptCount()
- 
getBindOnInitpublic boolean getBindOnInit()
- 
setBindOnInitpublic void setBindOnInit(boolean b) 
- 
getBindState
- 
getKeepAliveTimeoutpublic int getKeepAliveTimeout()
- 
setKeepAliveTimeoutpublic void setKeepAliveTimeout(int keepAliveTimeout) 
- 
getTcpNoDelaypublic boolean getTcpNoDelay()Socket TCP no delay.- Returns:
- The current TCP no delay setting for sockets created by this endpoint
 
- 
setTcpNoDelaypublic void setTcpNoDelay(boolean tcpNoDelay) 
- 
getConnectionLingerpublic int getConnectionLinger()Socket linger.- Returns:
- The current socket linger time for sockets created by this endpoint
 
- 
setConnectionLingerpublic void setConnectionLinger(int connectionLinger) 
- 
getConnectionTimeoutpublic int getConnectionTimeout()Socket timeout.- Returns:
- The current socket timeout for sockets created by this endpoint
 
- 
setConnectionTimeoutpublic void setConnectionTimeout(int soTimeout) 
- 
isSSLEnabledpublic boolean isSSLEnabled()
- 
setSSLEnabledpublic void setSSLEnabled(boolean SSLEnabled) 
- 
setMinSpareThreadspublic void setMinSpareThreads(int minSpareThreads) 
- 
getMinSpareThreadspublic int getMinSpareThreads()
- 
setMaxThreadspublic void setMaxThreads(int maxThreads) 
- 
getMaxThreadspublic int getMaxThreads()
- 
setThreadsMaxIdleTimepublic void setThreadsMaxIdleTime(int threadsMaxIdleTime) 
- 
getThreadsMaxIdleTimepublic int getThreadsMaxIdleTime()
- 
setThreadPrioritypublic void setThreadPriority(int threadPriority) 
- 
getThreadPrioritypublic int getThreadPriority()
- 
getMaxKeepAliveRequestspublic int getMaxKeepAliveRequests()
- 
setMaxKeepAliveRequestspublic void setMaxKeepAliveRequests(int maxKeepAliveRequests) 
- 
setName
- 
getName
- 
setDomain
- 
getDomain
- 
setDaemonpublic void setDaemon(boolean b) 
- 
getDaemonpublic boolean getDaemon()
- 
setUseAsyncIOpublic void setUseAsyncIO(boolean useAsyncIO) 
- 
getUseAsyncIOpublic boolean getUseAsyncIO()
- 
getDeferAcceptDeprecated.This code will be removed in Tomcat 11 onwardsAlways returnsfalse.- Returns:
- Always false
 
- 
getIdThe 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
- 
hasNegotiableProtocolspublic boolean hasNegotiableProtocols()
- 
setHandler
- 
getHandler
- 
setAttributeGeneric property setter called when a property for which a specific setter already exists within theProtocolHandlerneeds 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
 
- 
getAttributeUsed 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
- 
getProperty
- 
getCurrentThreadCountpublic int getCurrentThreadCount()Return the amount of threads that are managed by the pool.- Returns:
- the amount of threads that are managed by the pool
 
- 
getCurrentThreadsBusypublic int getCurrentThreadsBusy()Return the amount of threads that are in use- Returns:
- the amount of threads that are in use
 
- 
isRunningpublic boolean isRunning()
- 
isPausedpublic boolean isPaused()
- 
createExecutorpublic void createExecutor()
- 
shutdownExecutorpublic void shutdownExecutor()
- 
unlockAcceptprotected void unlockAccept()Unlock the server socket acceptor threads using bogus connections.
- 
processSocketpublic 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
 
- 
createSocketProcessorprotected abstract SocketProcessorBase<S> createSocketProcessor(SocketWrapperBase<S> socketWrapper, SocketEvent event) 
- 
bind- Throws:
- Exception
 
- 
unbind- Throws:
- Exception
 
- 
startInternal- Throws:
- Exception
 
- 
stopInternal- Throws:
- Exception
 
- 
init- Throws:
- Exception
 
- 
start- Throws:
- Exception
 
- 
startAcceptorThreadprotected void startAcceptorThread()
- 
pausepublic void pause()Pause the endpoint, which will stop it accepting new connections and unlock the acceptor.
- 
resumepublic void resume()Resume the endpoint, which will make it start accepting new connections again.
- 
stop- Throws:
- Exception
 
- 
destroy- Throws:
- Exception
 
- 
getLog
- 
getLogCertificate
- 
initializeConnectionLatch
- 
countUpOrAwaitConnection- Throws:
- InterruptedException
 
- 
countDownConnectionprotected long countDownConnection()
- 
closeServerSocketGracefulpublic final void closeServerSocketGraceful()Close the server socket (to prevent further connections) if the server socket was originally bound onstart()(rather than oninit()).- See Also:
 
- 
awaitConnectionsClosepublic 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
 
- 
doCloseServerSocketActually close the server socket but don't perform any other clean-up.- Throws:
- IOException- If an error occurs closing the socket
 
- 
serverSocketAccept- Throws:
- Exception
 
- 
setSocketOptions
- 
closeSocketClose 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
 
- 
destroySocketClose 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
 
 
-