AbstractProtocol (Apache Tomcat 9.0.68 API Documentation)

Package org.apache.coyote

## Class AbstractProtocol<S>

- java.lang.Object
- - org.apache.coyote.AbstractProtocol<S>

- All Implemented Interfaces:
    `javax.management.MBeanRegistration`, `ProtocolHandler`
  Direct Known Subclasses:
    `AbstractAjpProtocol`, `AbstractHttp11Protocol`

      public abstract class AbstractProtocol<S>
      extends java.lang.Object
      implements ProtocolHandler, javax.management.MBeanRegistration

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `protected static class` | `AbstractProtocol.ConnectionHandler<S>` |
    `protected static class` | `AbstractProtocol.RecycledProcessors` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected Adapter` | `adapter` | The adapter provides the link between the ProtocolHandler and the connector.
    `protected java.lang.String` | `domain` |
    `protected javax.management.MBeanServer` | `mserver` |
    `protected javax.management.ObjectName` | `oname` |
    `protected int` | `processorCache` | The maximum number of idle processors that will be retained in the cache and re-used with a subsequent request.
    `protected javax.management.ObjectName` | `rgOname` | Name of MBean for the Global Request Processor.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `AbstractProtocol​(AbstractEndpoint<S,​?> endpoint)` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addWaitingProcessor​(Processor processor)` |
    `long` | `awaitConnectionsClose​(long waitMillis)` | Wait for the client connections to the server to close gracefully.
    `void` | `closeServerSocketGraceful()` | Close the server socket (to prevent further connections) if the server socket was bound on `ProtocolHandler.start()` (rather than on `ProtocolHandler.init()` but do not perform any further shutdown.
    `protected abstract Processor` | `createProcessor()` | Create and configure a new Processor instance for the current protocol implementation.
    `protected abstract Processor` | `createUpgradeProcessor​(SocketWrapperBase<?> socket, UpgradeToken upgradeToken)` |
    `void` | `destroy()` | Destroy the protocol (optional).
    `int` | `getAcceptCount()` |
    `int` | `getAcceptorThreadCount()` | Deprecated. Will be removed in Tomcat 10.
    `int` | `getAcceptorThreadPriority()` |
    `Adapter` | `getAdapter()` | Return the adapter associated with the protocol handler.
    `java.net.InetAddress` | `getAddress()` |
    `java.lang.String` | `getClientCertProvider()` | When client certificate information is presented in a form other than instances of `X509Certificate` it needs to be converted before it can be used and this property controls which JSSE provider is used to perform the conversion.
    `long` | `getConnectionCount()` |
    `int` | `getConnectionLinger()` |
    `int` | `getConnectionTimeout()` |
    `java.lang.String` | `getDomain()` |
    `protected AbstractEndpoint<S,​?>` | `getEndpoint()` |
    `java.util.concurrent.Executor` | `getExecutor()` | The executor, provide access to the underlying thread pool.
    `javax.management.ObjectName` | `getGlobalRequestProcessorMBeanName()` |
    `protected AbstractEndpoint.Handler<S>` | `getHandler()` |
    `java.lang.String` | `getId()` | The default behavior is to identify connectors uniquely with address and port.
    `int` | `getKeepAliveTimeout()` | The time Tomcat will wait for a subsequent request before closing the connection.
    `int` | `getLocalPort()` |
    `protected abstract Log` | `getLog()` | Concrete implementations need to provide access to their logger to be used by the abstract classes.
    `int` | `getMaxConnections()` |
    `int` | `getMaxHeaderCount()` |
    `int` | `getMaxThreads()` |
    `int` | `getMinSpareThreads()` |
    `java.lang.String` | `getName()` | The name will be prefix-address-port if address is non-null and prefix-port if the address is null.
    `int` | `getNameIndex()` |
    `protected abstract java.lang.String` | `getNamePrefix()` | Obtain the prefix to be used when construction a name for this protocol handler.
    `protected abstract UpgradeProtocol` | `getNegotiatedProtocol​(java.lang.String name)` | Find a suitable handler for the protocol negotiated at the network layer.
    `javax.management.ObjectName` | `getObjectName()` |
    `int` | `getPort()` |
    `int` | `getPortOffset()` |
    `int` | `getPortWithOffset()` |
    `int` | `getProcessorCache()` |
    `java.lang.String` | `getProperty​(java.lang.String name)` | Generic property getter used by the digester.
    `protected abstract java.lang.String` | `getProtocolName()` | Obtain the name of the protocol, (Http, Ajp, etc.).
    `boolean` | `getTcpNoDelay()` |
    `int` | `getThreadPriority()` |
    `protected abstract UpgradeProtocol` | `getUpgradeProtocol​(java.lang.String name)` | Find a suitable handler for the protocol upgraded name specified.
    `java.util.concurrent.ScheduledExecutorService` | `getUtilityExecutor()` | Get the utility executor that should be used by the protocol handler.
    `int` | `getWaitingProcessorCount()` |
    `void` | `init()` | Initialise the protocol.
    `boolean` | `isAprRequired()` | Requires APR/native library
    `boolean` | `isPaused()` |
    `boolean` | `isSendfileSupported()` | Does this ProtocolHandler support sendfile?
    `void` | `pause()` | Pause the protocol (optional).
    `void` | `postDeregister()` |
    `void` | `postRegister​(java.lang.Boolean registrationDone)` |
    `void` | `preDeregister()` |
    `javax.management.ObjectName` | `preRegister​(javax.management.MBeanServer server, javax.management.ObjectName name)` |
    `void` | `removeWaitingProcessor​(Processor processor)` |
    `void` | `resume()` | Resume the protocol (optional).
    `void` | `setAcceptCount​(int acceptCount)` |
    `void` | `setAcceptorThreadCount​(int threadCount)` | Deprecated. Will be removed in Tomcat 10.
    `void` | `setAcceptorThreadPriority​(int threadPriority)` |
    `void` | `setAdapter​(Adapter adapter)` | The adapter, used to call the connector.
    `void` | `setAddress​(java.net.InetAddress ia)` |
    `void` | `setClientCertProvider​(java.lang.String s)` |
    `void` | `setConnectionLinger​(int connectionLinger)` |
    `void` | `setConnectionTimeout​(int timeout)` |
    `void` | `setExecutor​(java.util.concurrent.Executor executor)` | Set the optional executor that will be used by the connector.
    `protected void` | `setHandler​(AbstractEndpoint.Handler<S> handler)` |
    `void` | `setKeepAliveTimeout​(int keepAliveTimeout)` |
    `void` | `setMaxConnections​(int maxConnections)` |
    `void` | `setMaxHeaderCount​(int maxHeaderCount)` |
    `void` | `setMaxThreads​(int maxThreads)` |
    `void` | `setMinSpareThreads​(int minSpareThreads)` |
    `void` | `setPort​(int port)` |
    `void` | `setPortOffset​(int portOffset)` |
    `void` | `setProcessorCache​(int processorCache)` |
    `boolean` | `setProperty​(java.lang.String name, java.lang.String value)` | Generic property setter used by the digester.
    `void` | `setTcpNoDelay​(boolean tcpNoDelay)` |
    `void` | `setThreadPriority​(int threadPriority)` |
    `void` | `setUtilityExecutor​(java.util.concurrent.ScheduledExecutorService utilityExecutor)` | Set the utility executor that should be used by the protocol handler.
    `void` | `start()` | Start the protocol.
    `protected void` | `startAsyncTimeout()` | Note: The name of this method originated with the Servlet 3.0 asynchronous processing but evolved over time to represent a timeout that is triggered independently of the socket read/write timeouts.
    `void` | `stop()` | Stop the protocol.
    `protected void` | `stopAsyncTimeout()` |

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

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

    - ### Methods inherited from interface org.apache.coyote.ProtocolHandler

      `addSslHostConfig, addUpgradeProtocol, findSslHostConfigs, findUpgradeProtocols, getDesiredBufferSize`

- - ### Field Detail

    - #### rgOname

          protected javax.management.ObjectName rgOname

      Name of MBean for the Global Request Processor.

    - #### adapter

          protected Adapter adapter

      The adapter provides the link between the ProtocolHandler and the connector.

    - #### processorCache

          protected int processorCache

      The maximum number of idle processors that will be retained in the cache and re-used with a subsequent request. The default is 200. A value of -1 means unlimited. In the unlimited case, the theoretical maximum number of cached Processor objects is `getMaxConnections()` although it will usually be closer to `getMaxThreads()`.

    - #### domain

          protected java.lang.String domain

    - #### oname

          protected javax.management.ObjectName oname

    - #### mserver

          protected javax.management.MBeanServer mserver

  - ### Constructor Detail

    - #### AbstractProtocol

          public AbstractProtocol​(AbstractEndpoint<S,​?> endpoint)

  - ### Method Detail

    - #### setProperty

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

      Generic property setter used by the digester. Other code should not need to use this. The digester will only use this method if it can't find a more specific setter. That means the property belongs to the Endpoint, the ServerSocketFactory or some other lower level component. This method ensures that it is visible to both.
      Parameters:
        `name` - The name of the property to set
        `value` - The value, in string form, to set for the property
      Returns:
        `true` if the property was set successfully, otherwise `false`

    - #### getProperty

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

      Generic property getter used by the digester. Other code should not need to use this.
      Parameters:
        `name` - The name of the property to get
      Returns:
        The value of the property converted to a string

    - #### getGlobalRequestProcessorMBeanName

          public javax.management.ObjectName getGlobalRequestProcessorMBeanName()

    - #### setAdapter

          public void setAdapter​(Adapter adapter)

      Description copied from interface: `ProtocolHandler`
      The adapter, used to call the connector.
      Specified by:
        `setAdapter` in interface `ProtocolHandler`
      Parameters:
        `adapter` - The adapter to associate

    - #### getAdapter

          public Adapter getAdapter()

      Description copied from interface: `ProtocolHandler`
      Return the adapter associated with the protocol handler.
      Specified by:
        `getAdapter` in interface `ProtocolHandler`
      Returns:
        the adapter

    - #### getProcessorCache

          public int getProcessorCache()

    - #### setProcessorCache

          public void setProcessorCache​(int processorCache)

    - #### getClientCertProvider

          public java.lang.String getClientCertProvider()

      When client certificate information is presented in a form other than instances of `X509Certificate` it needs to be converted before it can be used and this property controls which JSSE provider is used to perform the conversion. For example it is used with the AJP connectors, the HTTP APR connector and with the `SSLValve`. If not specified, the default provider will be used.
      Returns:
        The name of the JSSE provider to use

    - #### setClientCertProvider

          public void setClientCertProvider​(java.lang.String s)

    - #### getMaxHeaderCount

          public int getMaxHeaderCount()

    - #### setMaxHeaderCount

          public void setMaxHeaderCount​(int maxHeaderCount)

    - #### isAprRequired

          public boolean isAprRequired()

      Description copied from interface: `ProtocolHandler`
      Requires APR/native library
      Specified by:
        `isAprRequired` in interface `ProtocolHandler`
      Returns:
        `true` if this Protocol Handler requires the APR/native library, otherwise `false`

    - #### isSendfileSupported

          public boolean isSendfileSupported()

      Description copied from interface: `ProtocolHandler`
      Does this ProtocolHandler support sendfile?
      Specified by:
        `isSendfileSupported` in interface `ProtocolHandler`
      Returns:
        `true` if this Protocol Handler supports sendfile, otherwise `false`

    - #### getId

          public java.lang.String getId()

      Description copied from interface: `ProtocolHandler`
      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.
      Specified by:
        `getId` in interface `ProtocolHandler`
      Returns:
        the id

    - #### getExecutor

          public java.util.concurrent.Executor getExecutor()

      Description copied from interface: `ProtocolHandler`
      The executor, provide access to the underlying thread pool.
      Specified by:
        `getExecutor` in interface `ProtocolHandler`
      Returns:
        The executor used to process requests

    - #### setExecutor

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

      Description copied from interface: `ProtocolHandler`
      Set the optional executor that will be used by the connector.
      Specified by:
        `setExecutor` in interface `ProtocolHandler`
      Parameters:
        `executor` - the executor

    - #### getUtilityExecutor

          public java.util.concurrent.ScheduledExecutorService getUtilityExecutor()

      Description copied from interface: `ProtocolHandler`
      Get the utility executor that should be used by the protocol handler.
      Specified by:
        `getUtilityExecutor` in interface `ProtocolHandler`
      Returns:
        the executor

    - #### setUtilityExecutor

          public void setUtilityExecutor​(java.util.concurrent.ScheduledExecutorService utilityExecutor)

      Description copied from interface: `ProtocolHandler`
      Set the utility executor that should be used by the protocol handler.
      Specified by:
        `setUtilityExecutor` in interface `ProtocolHandler`
      Parameters:
        `utilityExecutor` - the executor

    - #### getMaxThreads

          public int getMaxThreads()

    - #### setMaxThreads

          public void setMaxThreads​(int maxThreads)

    - #### getMaxConnections

          public int getMaxConnections()

    - #### setMaxConnections

          public void setMaxConnections​(int maxConnections)

    - #### getMinSpareThreads

          public int getMinSpareThreads()

    - #### setMinSpareThreads

          public void setMinSpareThreads​(int minSpareThreads)

    - #### getThreadPriority

          public int getThreadPriority()

    - #### setThreadPriority

          public void setThreadPriority​(int threadPriority)

    - #### getAcceptCount

          public int getAcceptCount()

    - #### setAcceptCount

          public void setAcceptCount​(int acceptCount)

    - #### getTcpNoDelay

          public boolean getTcpNoDelay()

    - #### setTcpNoDelay

          public void setTcpNoDelay​(boolean tcpNoDelay)

    - #### getConnectionLinger

          public int getConnectionLinger()

    - #### setConnectionLinger

          public void setConnectionLinger​(int connectionLinger)

    - #### getKeepAliveTimeout

          public int getKeepAliveTimeout()

      The time Tomcat will wait for a subsequent request before closing the connection. The default is `getConnectionTimeout()`.
      Returns:
        The timeout in milliseconds

    - #### setKeepAliveTimeout

          public void setKeepAliveTimeout​(int keepAliveTimeout)

    - #### getAddress

          public java.net.InetAddress getAddress()

    - #### setAddress

          public void setAddress​(java.net.InetAddress ia)

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

    - #### getConnectionTimeout

          public int getConnectionTimeout()

    - #### setConnectionTimeout

          public void setConnectionTimeout​(int timeout)

    - #### getConnectionCount

          public long getConnectionCount()

    - #### setAcceptorThreadCount

          @Deprecated
          public void setAcceptorThreadCount​(int threadCount)

      Deprecated.
      Will be removed in Tomcat 10.
      NO-OP.
      Parameters:
        `threadCount` - Unused

    - #### getAcceptorThreadCount

          @Deprecated
          public int getAcceptorThreadCount()

      Deprecated.
      Will be removed in Tomcat 10.
      Always returns 1.
      Returns:
        Always 1.

    - #### setAcceptorThreadPriority

          public void setAcceptorThreadPriority​(int threadPriority)

    - #### getAcceptorThreadPriority

          public int getAcceptorThreadPriority()

    - #### getNameIndex

          public int getNameIndex()

    - #### getName

          public java.lang.String getName()

      The name will be prefix-address-port if address is non-null and prefix-port if the address is null.
      Returns:
        A name for this protocol instance that is appropriately quoted for use in an ObjectName.

    - #### addWaitingProcessor

          public void addWaitingProcessor​(Processor processor)

    - #### removeWaitingProcessor

          public void removeWaitingProcessor​(Processor processor)

    - #### getWaitingProcessorCount

          public int getWaitingProcessorCount()

    - #### getEndpoint

          protected AbstractEndpoint<S,​?> getEndpoint()

    - #### getHandler

          protected AbstractEndpoint.Handler<S> getHandler()

    - #### setHandler

          protected void setHandler​(AbstractEndpoint.Handler<S> handler)

    - #### getLog

          protected abstract Log getLog()

      Concrete implementations need to provide access to their logger to be used by the abstract classes.
      Returns:
        the logger

    - #### getNamePrefix

          protected abstract java.lang.String getNamePrefix()

      Obtain the prefix to be used when construction a name for this protocol handler. The name will be prefix-address-port.
      Returns:
        the prefix

    - #### getProtocolName

          protected abstract java.lang.String getProtocolName()

      Obtain the name of the protocol, (Http, Ajp, etc.). Used with JMX.
      Returns:
        the protocol name

    - #### getNegotiatedProtocol

          protected abstract UpgradeProtocol getNegotiatedProtocol​(java.lang.String name)

      Find a suitable handler for the protocol negotiated at the network layer.
      Parameters:
        `name` - The name of the requested negotiated protocol.
      Returns:
        The instance where `UpgradeProtocol.getAlpnName()` matches the requested protocol

    - #### getUpgradeProtocol

          protected abstract UpgradeProtocol getUpgradeProtocol​(java.lang.String name)

      Find a suitable handler for the protocol upgraded name specified. This is used for direct connection protocol selection.
      Parameters:
        `name` - The name of the requested negotiated protocol.
      Returns:
        The instance where `UpgradeProtocol.getAlpnName()` matches the requested protocol

    - #### createProcessor

          protected abstract Processor createProcessor()

      Create and configure a new Processor instance for the current protocol implementation.
      Returns:
        A fully configured Processor instance that is ready to use

    - #### createUpgradeProcessor

          protected abstract Processor createUpgradeProcessor​(SocketWrapperBase<?> socket,
                                                              UpgradeToken upgradeToken)

    - #### getObjectName

          public javax.management.ObjectName getObjectName()

    - #### getDomain

          public java.lang.String getDomain()

    - #### preRegister

          public javax.management.ObjectName preRegister​(javax.management.MBeanServer server,
                                                         javax.management.ObjectName name)
                                                  throws java.lang.Exception

      Specified by:
        `preRegister` in interface `javax.management.MBeanRegistration`
      Throws:
        `java.lang.Exception`

    - #### postRegister

          public void postRegister​(java.lang.Boolean registrationDone)

      Specified by:
        `postRegister` in interface `javax.management.MBeanRegistration`

    - #### preDeregister

          public void preDeregister()
                             throws java.lang.Exception

      Specified by:
        `preDeregister` in interface `javax.management.MBeanRegistration`
      Throws:
        `java.lang.Exception`

    - #### postDeregister

          public void postDeregister()

      Specified by:
        `postDeregister` in interface `javax.management.MBeanRegistration`

    - #### init

          public void init()
                    throws java.lang.Exception

      Description copied from interface: `ProtocolHandler`
      Initialise the protocol.
      Specified by:
        `init` in interface `ProtocolHandler`
      Throws:
        `java.lang.Exception` - If the protocol handler fails to initialise

    - #### start

          public void start()
                     throws java.lang.Exception

      Description copied from interface: `ProtocolHandler`
      Start the protocol.
      Specified by:
        `start` in interface `ProtocolHandler`
      Throws:
        `java.lang.Exception` - If the protocol handler fails to start

    - #### startAsyncTimeout

          protected void startAsyncTimeout()

      Note: The name of this method originated with the Servlet 3.0 asynchronous processing but evolved over time to represent a timeout that is triggered independently of the socket read/write timeouts.

    - #### stopAsyncTimeout

          protected void stopAsyncTimeout()

    - #### pause

          public void pause()
                     throws java.lang.Exception

      Description copied from interface: `ProtocolHandler`
      Pause the protocol (optional).
      Specified by:
        `pause` in interface `ProtocolHandler`
      Throws:
        `java.lang.Exception` - If the protocol handler fails to pause

    - #### isPaused

          public boolean isPaused()

    - #### resume

          public void resume()
                      throws java.lang.Exception

      Description copied from interface: `ProtocolHandler`
      Resume the protocol (optional).
      Specified by:
        `resume` in interface `ProtocolHandler`
      Throws:
        `java.lang.Exception` - If the protocol handler fails to resume

    - #### stop

          public void stop()
                    throws java.lang.Exception

      Description copied from interface: `ProtocolHandler`
      Stop the protocol.
      Specified by:
        `stop` in interface `ProtocolHandler`
      Throws:
        `java.lang.Exception` - If the protocol handler fails to stop

    - #### destroy

          public void destroy()
                       throws java.lang.Exception

      Description copied from interface: `ProtocolHandler`
      Destroy the protocol (optional).
      Specified by:
        `destroy` in interface `ProtocolHandler`
      Throws:
        `java.lang.Exception` - If the protocol handler fails to destroy

    - #### closeServerSocketGraceful

          public void closeServerSocketGraceful()

      Description copied from interface: `ProtocolHandler`
      Close the server socket (to prevent further connections) if the server socket was bound on `ProtocolHandler.start()` (rather than on `ProtocolHandler.init()` but do not perform any further shutdown.
      Specified by:
        `closeServerSocketGraceful` in interface `ProtocolHandler`

    - #### awaitConnectionsClose

          public long awaitConnectionsClose​(long waitMillis)

      Description copied from interface: `ProtocolHandler`
      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`.
      Specified by:
        `awaitConnectionsClose` in interface `ProtocolHandler`
      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