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 classAbstractProtocol.ConnectionHandler<S>protected static classAbstractProtocol.RecycledProcessors
-
Field Summary
Fields Modifier and Type Field Description protected AdapteradapterThe adapter provides the link between the ProtocolHandler and the connector.protected java.lang.Stringdomainprotected javax.management.MBeanServermserverprotected javax.management.ObjectNameonameprotected intprocessorCacheThe maximum number of idle processors that will be retained in the cache and re-used with a subsequent request.protected javax.management.ObjectNamergOnameName of MBean for the Global Request Processor.
-
Constructor Summary
Constructors Constructor Description AbstractProtocol(AbstractEndpoint<S,?> endpoint)Creates a new protocol handler.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddWaitingProcessor(Processor processor)Adds a processor to the waiting processors set.longawaitConnectionsClose(long waitMillis)Awaits for connections to close.voidcloseServerSocketGraceful()Closes the server socket gracefully.protected abstract ProcessorcreateProcessor()Create and configure a new Processor instance for the current protocol implementation.protected abstract ProcessorcreateUpgradeProcessor(SocketWrapperBase<?> socket, UpgradeToken upgradeToken)Create and configure a new Processor instance for upgrade connections.voiddestroy()Destroys the protocol handler.intgetAcceptCount()Gets the accept count.intgetAcceptorThreadPriority()Gets the acceptor thread priority.AdaptergetAdapter()Gets the adapter.java.net.InetAddressgetAddress()Gets the address.java.lang.StringgetClientCertProvider()When client certificate information is presented in a form other than instances ofX509Certificateit needs to be converted before it can be used and this property controls which JSSE provider is used to perform the conversion.longgetConnectionCount()Gets the connection count.intgetConnectionLinger()Gets the connection linger time.intgetConnectionTimeout()Gets the connection timeout.java.lang.StringgetDomain()Gets the domain.protected AbstractEndpoint<S,?>getEndpoint()Gets the endpoint.java.util.concurrent.ExecutorgetExecutor()Gets the executor for this protocol handler.javax.management.ObjectNamegetGlobalRequestProcessorMBeanName()Gets the MBean name for the Global Request Processor.AbstractEndpoint.Handler<S>getHandler()Gets the handler.java.lang.StringgetId()Gets the protocol ID.intgetKeepAliveTimeout()The time Tomcat will wait for a subsequent request before closing the connection.intgetLocalPort()Gets the local port.protected abstract LoggetLog()Concrete implementations need to provide access to their logger to be used by the abstract classes.intgetMaxConnections()Gets the maximum number of connections.intgetMaxHeaderCount()Gets the maximum header count.intgetMaxQueueSize()Gets the maximum queue size.intgetMaxThreads()Gets the maximum number of threads.intgetMinSpareThreads()Gets the minimum number of spare threads.java.lang.StringgetName()Gets the name of this protocol instance.intgetNameIndex()Gets the name index for this protocol.protected abstract java.lang.StringgetNamePrefix()Obtain the prefix to be used when construction a name for this protocol handler.protected abstract UpgradeProtocolgetNegotiatedProtocol(java.lang.String name)Find a suitable handler for the protocol negotiated at the network layer.javax.management.ObjectNamegetObjectName()Gets the object name.intgetPort()Gets the port.intgetPortOffset()Gets the port offset.intgetPortWithOffset()Gets the port with offset applied.intgetProcessorCache()Gets the processor cache size.java.lang.StringgetProperty(java.lang.String name)Generic property getter used by the digester.protected abstract java.lang.StringgetProtocolName()Obtain the name of the protocol, (Http, Ajp, etc.).booleangetTcpNoDelay()Gets whether TCP no-delay is enabled.intgetThreadPriority()Gets the thread priority.protected abstract UpgradeProtocolgetUpgradeProtocol(java.lang.String name)Find a suitable handler for the protocol upgraded name specified.java.util.concurrent.ScheduledExecutorServicegetUtilityExecutor()Get the utility executor that should be used by the protocol handler.intgetWaitingProcessorCount()Gets the count of waiting processors.voidinit()Initializes the protocol handler.booleanisPaused()Checks if the protocol handler is paused.booleanisSendfileSupported()Checks if sendfile is supported.voidpause()Pauses the protocol handler.voidpostDeregister()Post-deregisters this MBean.voidpostRegister(java.lang.Boolean registrationDone)Post-registers this MBean.voidpreDeregister()Pre-deregisters this MBean.javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)Pre-registers this MBean.voidremoveWaitingProcessor(Processor processor)Removes a processor from the waiting processors set.voidresume()Resumes the protocol handler.voidsetAcceptCount(int acceptCount)Sets the accept count.voidsetAcceptorThreadPriority(int threadPriority)Sets the acceptor thread priority.voidsetAdapter(Adapter adapter)Sets the adapter.voidsetAddress(java.net.InetAddress ia)Sets the address.voidsetClientCertProvider(java.lang.String s)Sets the JSSE provider to use for client certificate conversion.voidsetConnectionLinger(int connectionLinger)Sets the connection linger time.voidsetConnectionTimeout(int timeout)Sets the connection timeout.voidsetExecutor(java.util.concurrent.Executor executor)Sets the executor for this protocol handler.protected voidsetHandler(AbstractEndpoint.Handler<S> handler)Sets the handler.voidsetKeepAliveTimeout(int keepAliveTimeout)Sets the keep-alive timeout.voidsetMaxConnections(int maxConnections)Sets the maximum number of connections.voidsetMaxHeaderCount(int maxHeaderCount)Sets the maximum header count.voidsetMaxQueueSize(int maxQueueSize)Sets the maximum queue size.voidsetMaxThreads(int maxThreads)Sets the maximum number of threads.voidsetMinSpareThreads(int minSpareThreads)Sets the minimum number of spare threads.voidsetPort(int port)Sets the port.voidsetPortOffset(int portOffset)Sets the port offset.voidsetProcessorCache(int processorCache)Sets the maximum number of idle processors to cache.booleansetProperty(java.lang.String name, java.lang.String value)Generic property setter used by the digester.voidsetTcpNoDelay(boolean tcpNoDelay)Sets whether TCP no-delay is enabled.voidsetThreadPriority(int threadPriority)Sets the thread priority.voidsetUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor)Set the utility executor that should be used by the protocol handler.voidstart()Starts the protocol handler.protected voidstartAsyncTimeout()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.voidstop()Stops the protocol handler.protected voidstopAsyncTimeout()-
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, 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 isgetMaxConnections()although it will usually be closer togetMaxThreads().
-
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)
Creates a new protocol handler.- Parameters:
endpoint- The endpoint for low-level network I/O
-
-
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 setvalue- The value, in string form, to set for the property- Returns:
trueif the property was set successfully, otherwisefalse
-
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()
Gets the MBean name for the Global Request Processor.- Returns:
- the MBean name
-
setAdapter
public void setAdapter(Adapter adapter)
Sets the adapter.- Specified by:
setAdapterin interfaceProtocolHandler- Parameters:
adapter- The adapter
-
getAdapter
public Adapter getAdapter()
Gets the adapter.- Specified by:
getAdapterin interfaceProtocolHandler- Returns:
- the adapter
-
getProcessorCache
public int getProcessorCache()
Gets the processor cache size.- Returns:
- the processor cache size
-
setProcessorCache
public void setProcessorCache(int processorCache)
Sets the maximum number of idle processors to cache.- Parameters:
processorCache- The processor cache size (-1 for unlimited)
-
getClientCertProvider
public java.lang.String getClientCertProvider()
When client certificate information is presented in a form other than instances ofX509Certificateit 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 and with theSSLValve. 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)
Sets the JSSE provider to use for client certificate conversion.- Parameters:
s- The provider name
-
getMaxHeaderCount
public int getMaxHeaderCount()
Gets the maximum header count.- Returns:
- the maximum header count
-
setMaxHeaderCount
public void setMaxHeaderCount(int maxHeaderCount)
Sets the maximum header count.- Parameters:
maxHeaderCount- The maximum header count
-
isSendfileSupported
public boolean isSendfileSupported()
Checks if sendfile is supported.- Specified by:
isSendfileSupportedin interfaceProtocolHandler- Returns:
trueif sendfile is supported
-
getId
public java.lang.String getId()
Gets the protocol ID.- Specified by:
getIdin interfaceProtocolHandler- Returns:
- the protocol ID
-
getExecutor
public java.util.concurrent.Executor getExecutor()
Gets the executor for this protocol handler.- Specified by:
getExecutorin interfaceProtocolHandler- Returns:
- the executor
-
setExecutor
public void setExecutor(java.util.concurrent.Executor executor)
Sets the executor for this protocol handler.- Specified by:
setExecutorin interfaceProtocolHandler- Parameters:
executor- The executor
-
getUtilityExecutor
public java.util.concurrent.ScheduledExecutorService getUtilityExecutor()
Description copied from interface:ProtocolHandlerGet the utility executor that should be used by the protocol handler.- Specified by:
getUtilityExecutorin interfaceProtocolHandler- Returns:
- the executor
-
setUtilityExecutor
public void setUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor)
Description copied from interface:ProtocolHandlerSet the utility executor that should be used by the protocol handler.- Specified by:
setUtilityExecutorin interfaceProtocolHandler- Parameters:
utilityExecutor- the executor
-
getMaxThreads
public int getMaxThreads()
Gets the maximum number of threads.- Returns:
- the maximum number of threads
-
setMaxThreads
public void setMaxThreads(int maxThreads)
Sets the maximum number of threads.- Parameters:
maxThreads- The maximum number of threads
-
getMaxConnections
public int getMaxConnections()
Gets the maximum number of connections.- Returns:
- the maximum number of connections
-
setMaxConnections
public void setMaxConnections(int maxConnections)
Sets the maximum number of connections.- Parameters:
maxConnections- The maximum number of connections
-
getMinSpareThreads
public int getMinSpareThreads()
Gets the minimum number of spare threads.- Returns:
- the minimum spare threads
-
setMinSpareThreads
public void setMinSpareThreads(int minSpareThreads)
Sets the minimum number of spare threads.- Parameters:
minSpareThreads- The minimum spare threads
-
getThreadPriority
public int getThreadPriority()
Gets the thread priority.- Returns:
- the thread priority
-
setThreadPriority
public void setThreadPriority(int threadPriority)
Sets the thread priority.- Parameters:
threadPriority- The thread priority
-
getMaxQueueSize
public int getMaxQueueSize()
Gets the maximum queue size.- Returns:
- the maximum queue size
-
setMaxQueueSize
public void setMaxQueueSize(int maxQueueSize)
Sets the maximum queue size.- Parameters:
maxQueueSize- The maximum queue size
-
getAcceptCount
public int getAcceptCount()
Gets the accept count.- Returns:
- the accept count
-
setAcceptCount
public void setAcceptCount(int acceptCount)
Sets the accept count.- Parameters:
acceptCount- The accept count
-
getTcpNoDelay
public boolean getTcpNoDelay()
Gets whether TCP no-delay is enabled.- Returns:
trueif TCP no-delay is enabled
-
setTcpNoDelay
public void setTcpNoDelay(boolean tcpNoDelay)
Sets whether TCP no-delay is enabled.- Parameters:
tcpNoDelay-trueto enable TCP no-delay
-
getConnectionLinger
public int getConnectionLinger()
Gets the connection linger time.- Returns:
- the connection linger time
-
setConnectionLinger
public void setConnectionLinger(int connectionLinger)
Sets the connection linger time.- Parameters:
connectionLinger- The connection linger time
-
getKeepAliveTimeout
public int getKeepAliveTimeout()
The time Tomcat will wait for a subsequent request before closing the connection. The default isgetConnectionTimeout().- Returns:
- The timeout in milliseconds
-
setKeepAliveTimeout
public void setKeepAliveTimeout(int keepAliveTimeout)
Sets the keep-alive timeout.- Parameters:
keepAliveTimeout- The keep-alive timeout in milliseconds
-
getAddress
public java.net.InetAddress getAddress()
Gets the address.- Returns:
- the address
-
setAddress
public void setAddress(java.net.InetAddress ia)
Sets the address.- Parameters:
ia- The address
-
getPort
public int getPort()
Gets the port.- Returns:
- the port
-
setPort
public void setPort(int port)
Sets the port.- Parameters:
port- The port
-
getPortOffset
public int getPortOffset()
Gets the port offset.- Returns:
- the port offset
-
setPortOffset
public void setPortOffset(int portOffset)
Sets the port offset.- Parameters:
portOffset- The port offset
-
getPortWithOffset
public int getPortWithOffset()
Gets the port with offset applied.- Returns:
- the port with offset
-
getLocalPort
public int getLocalPort()
Gets the local port.- Returns:
- the local port
-
getConnectionTimeout
public int getConnectionTimeout()
Gets the connection timeout. When Tomcat expects data from the client, this is the time Tomcat will wait for that data to arrive before closing the connection.- Returns:
- the connection timeout
-
setConnectionTimeout
public void setConnectionTimeout(int timeout)
Sets the connection timeout.- Parameters:
timeout- The connection timeout in milliseconds
-
getConnectionCount
public long getConnectionCount()
Gets the connection count.- Returns:
- the connection count
-
setAcceptorThreadPriority
public void setAcceptorThreadPriority(int threadPriority)
Sets the acceptor thread priority.- Parameters:
threadPriority- The thread priority
-
getAcceptorThreadPriority
public int getAcceptorThreadPriority()
Gets the acceptor thread priority.- Returns:
- the acceptor thread priority
-
getNameIndex
public int getNameIndex()
Gets the name index for this protocol.- Returns:
- the name index
-
getName
public java.lang.String getName()
Gets the name of this protocol instance. 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)
Adds a processor to the waiting processors set.- Parameters:
processor- The processor
-
removeWaitingProcessor
public void removeWaitingProcessor(Processor processor)
Removes a processor from the waiting processors set.- Parameters:
processor- The processor
-
getWaitingProcessorCount
public int getWaitingProcessorCount()
Gets the count of waiting processors.- Returns:
- the waiting processor count
-
getEndpoint
protected AbstractEndpoint<S,?> getEndpoint()
Gets the endpoint.- Returns:
- the endpoint
-
getHandler
public AbstractEndpoint.Handler<S> getHandler()
Gets the handler.- Returns:
- the handler
-
setHandler
protected void setHandler(AbstractEndpoint.Handler<S> handler)
Sets the handler.- Parameters:
handler- The 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)
Create and configure a new Processor instance for upgrade connections.- Parameters:
socket- The socket for the upgrade connectionupgradeToken- The upgrade token containing upgrade information- Returns:
- A fully configured Processor instance that is ready to use
-
getObjectName
public javax.management.ObjectName getObjectName()
Gets the object name.- Returns:
- the object name
-
getDomain
public java.lang.String getDomain()
Gets the domain.- Returns:
- the domain
-
preRegister
public javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name) throws java.lang.ExceptionPre-registers this MBean.- Specified by:
preRegisterin interfacejavax.management.MBeanRegistration- Parameters:
server- The MBean servername- The object name- Returns:
- the object name
- Throws:
java.lang.Exception- if registration fails
-
postRegister
public void postRegister(java.lang.Boolean registrationDone)
Post-registers this MBean.- Specified by:
postRegisterin interfacejavax.management.MBeanRegistration- Parameters:
registrationDone- The registration status
-
preDeregister
public void preDeregister() throws java.lang.ExceptionPre-deregisters this MBean.- Specified by:
preDeregisterin interfacejavax.management.MBeanRegistration- Throws:
java.lang.Exception- if deregistration fails
-
postDeregister
public void postDeregister()
Post-deregisters this MBean.- Specified by:
postDeregisterin interfacejavax.management.MBeanRegistration
-
init
public void init() throws java.lang.ExceptionInitializes the protocol handler.- Specified by:
initin interfaceProtocolHandler- Throws:
java.lang.Exception- if initialization fails
-
start
public void start() throws java.lang.ExceptionStarts the protocol handler.- Specified by:
startin interfaceProtocolHandler- Throws:
java.lang.Exception- if start fails
-
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.ExceptionPauses the protocol handler.- Specified by:
pausein interfaceProtocolHandler- Throws:
java.lang.Exception- if pause fails
-
isPaused
public boolean isPaused()
Checks if the protocol handler is paused.- Returns:
trueif paused
-
resume
public void resume() throws java.lang.ExceptionResumes the protocol handler.- Specified by:
resumein interfaceProtocolHandler- Throws:
java.lang.Exception- if resume fails
-
stop
public void stop() throws java.lang.ExceptionStops the protocol handler.- Specified by:
stopin interfaceProtocolHandler- Throws:
java.lang.Exception- if stop fails
-
destroy
public void destroy() throws java.lang.ExceptionDestroys the protocol handler.- Specified by:
destroyin interfaceProtocolHandler- Throws:
java.lang.Exception- if destroy fails
-
closeServerSocketGraceful
public void closeServerSocketGraceful()
Closes the server socket gracefully.- Specified by:
closeServerSocketGracefulin interfaceProtocolHandler
-
awaitConnectionsClose
public long awaitConnectionsClose(long waitMillis)
Awaits for connections to close.- Specified by:
awaitConnectionsClosein interfaceProtocolHandler- Parameters:
waitMillis- The maximum time to wait in milliseconds- Returns:
- the number of connections remaining after the wait
-
-