Class 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, AprEndpoint

    public abstract class AbstractEndpoint<S,​U>
    extends java.lang.Object
    Mladen Turk, Remy Maucherat
    • Field Detail

      • 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.
      • 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
      • acceptorThreadCount

        protected int acceptorThreadCount
        This attribute is hard-coded to 1 and is no longer configurable. It will be removed in Tomcat 10.1.
      • 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
      • attributes

        protected java.util.HashMap<java.lang.String,​java.lang.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

      • toTimeout

        public static long toTimeout​(long timeout)
      • getConnections

        public java.util.Set<SocketWrapperBase<S>> getConnections()
        Get a set with the current open connections.
        A set with the open socket wrappers
      • getDefaultSSLHostConfigName

        public java.lang.String getDefaultSSLHostConfigName()
        The host name for the default SSL configuration for this endpoint - always in lower case.
      • setDefaultSSLHostConfigName

        public void setDefaultSSLHostConfigName​(java.lang.String defaultSSLHostConfigName)
      • addSslHostConfig

        public void addSslHostConfig​(SSLHostConfig sslHostConfig)
                              throws java.lang.IllegalArgumentException
        Add the given SSL Host configuration.
        sslHostConfig - The configuration to add
        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.
        sslHostConfig - The configuration to add
        replace - If true replacement of an existing configuration is permitted, otherwise any such attempted replacement will trigger an exception
        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.
        hostName - The host name associated with the SSL host configuration to remove
        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.
        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 java.lang.Exception
        Create the SSLContext for the given SSLHostConfig.
        sslHostConfig - The SSLHostConfig for which the SSLContext should be created
        java.lang.Exception - If the SSLContext cannot be created for the given SSLHostConfig
      • generateCertificateDebug

        protected java.lang.String generateCertificateDebug​( certificate)
      • destroySsl

        protected void destroySsl()
                           throws java.lang.Exception
      • releaseSSLContext

        protected void releaseSSLContext​(SSLHostConfig sslHostConfig)
        Release the SSLContext, if any, associated with the SSLHostConfig.
        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:
        1. exact match
        2. wild card match
        3. default SSLHostConfig
        sniHostName - Host name - must be in lower case
        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)
      • setAcceptorThreadCount

        public void setAcceptorThreadCount​(int acceptorThreadCount)
        This attribute is hard-coded to 1 and is no longer configurable. This setter will be removed in Tomcat 10.
        acceptorThreadCount - Ignored
      • getAcceptorThreadCount

        public int getAcceptorThreadCount()
        This attribute is hard-coded to 1 and is no longer configurable. This getter will be removed in Tomcat 10.
        Always returns 1
      • 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.

        The count
      • setExecutor

        public void setExecutor​(java.util.concurrent.Executor executor)
      • getExecutor

        public java.util.concurrent.Executor getExecutor()
      • setUseVirtualThreads

        public void setUseVirtualThreads​(boolean useVirtualThreads)
      • getUseVirtualThreads

        public boolean getUseVirtualThreads()
      • 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 getAddress()
      • setAddress

        public void setAddress​( address)
      • getLocalAddress

        protected abstract getLocalAddress()
        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.
        The network address that the server socket is listening on or null if the server socket is not currently bound.
        Throws: - If there is a problem determining the currently bound socket
      • setAcceptCount

        public void setAcceptCount​(int acceptCount)
      • getAcceptCount

        public int getAcceptCount()
      • setBacklog

        public void setBacklog​(int backlog)
      • getBacklog

        public int getBacklog()
      • 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.
        The current TCP no delay setting for sockets created by this endpoint
      • setTcpNoDelay

        public void setTcpNoDelay​(boolean tcpNoDelay)
      • getConnectionLinger

        public int getConnectionLinger()
        Socket linger.
        The current socket linger time for sockets created by this endpoint
      • setConnectionLinger

        public void setConnectionLinger​(int connectionLinger)
      • getSoLinger

        public int getSoLinger()
      • setSoLinger

        public void setSoLinger​(int soLinger)
      • getConnectionTimeout

        public int getConnectionTimeout()
        Socket timeout.
        The current socket timeout for sockets created by this endpoint
      • setConnectionTimeout

        public void setConnectionTimeout​(int soTimeout)
      • getSoTimeout

        public int getSoTimeout()
      • setSoTimeout

        public void setSoTimeout​(int soTimeout)
      • 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.
        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​(java.lang.String name)
      • getName

        public java.lang.String getName()
      • setDomain

        public void setDomain​(java.lang.String domain)
      • getDomain

        public java.lang.String getDomain()
      • setDaemon

        public void setDaemon​(boolean b)
      • getDaemon

        public boolean getDaemon()
      • setUseAsyncIO

        public void setUseAsyncIO​(boolean useAsyncIO)
      • getUseAsyncIO

        public boolean getUseAsyncIO()
      • getDeferAccept

        protected abstract boolean getDeferAccept()
      • addNegotiatedProtocol

        public void addNegotiatedProtocol​(java.lang.String negotiableProtocol)
      • hasNegotiableProtocols

        public boolean hasNegotiableProtocols()
      • 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 the ProtocolHandler needs to be made available to sub-components. The specific setter will call this method to populate the attributes.
        name - Name of property to set
        value - The value to set the property to
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String key)
        Used by sub-components to retrieve configuration information.
        key - The name of the property for which the value should be retrieved
        The value of the specified property
      • setProperty

        public boolean setProperty​(java.lang.String name,
                                   java.lang.String value)
      • getProperty

        public java.lang.String getProperty​(java.lang.String name)
      • getCurrentThreadCount

        public int getCurrentThreadCount()
        Return the amount of threads that are managed by the pool.
        the amount of threads that are managed by the pool
      • getCurrentThreadsBusy

        public int getCurrentThreadsBusy()
        Return the amount of threads that are in use
        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.
        socketWrapper - The socket wrapper to process
        event - The socket event to be processed
        dispatch - Should the processing be performed on a new container thread
        if processing was triggered successfully
      • bind

        public abstract void bind()
                           throws java.lang.Exception
      • unbind

        public abstract void unbind()
                             throws java.lang.Exception
      • startInternal

        public abstract void startInternal()
                                    throws java.lang.Exception
      • stopInternal

        public abstract void stopInternal()
                                   throws java.lang.Exception
      • init

        public void init()
                  throws java.lang.Exception
      • start

        public final void start()
                         throws java.lang.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 java.lang.Exception
      • destroy

        public final void destroy()
                           throws java.lang.Exception
      • getLog

        protected abstract Log getLog()
      • getLogCertificate

        protected Log getLogCertificate()
      • initializeConnectionLatch

        protected LimitLatch initializeConnectionLatch()
      • releaseConnectionLatch

        protected void releaseConnectionLatch()
      • countUpOrAwaitConnection

        protected void countUpOrAwaitConnection()
                                         throws java.lang.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:
      • 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.
        waitMillis - The maximum time to wait in milliseconds for the client connections to close.
        The wait time, if any remaining when the method returned
      • doCloseServerSocket

        protected abstract void doCloseServerSocket()
        Actually close the server socket but don't perform any other clean-up.
        Throws: - If an error occurs closing the socket
      • serverSocketAccept

        protected abstract U serverSocketAccept()
                                         throws java.lang.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.
        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.
        socket - The newly accepted socket