Class AbstractProtocol<S>
java.lang.Object
org.apache.coyote.AbstractProtocol<S>
- All Implemented Interfaces:
MBeanRegistration, ProtocolHandler
- Direct Known Subclasses:
AbstractAjpProtocol, AbstractHttp11Protocol
public abstract class AbstractProtocol<S>
extends Object
implements ProtocolHandler, MBeanRegistration
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AdapterThe adapter provides the link between the ProtocolHandler and the connector.protected Stringprotected MBeanServerprotected ObjectNameprotected intThe maximum number of idle processors that will be retained in the cache and re-used with a subsequent request.protected ObjectNameName of MBean for the Global Request Processor. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractProtocol(AbstractEndpoint<S, ?> endpoint) Creates a new protocol handler. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddWaitingProcessor(Processor processor) Adds a processor to the waiting processors set.longawaitConnectionsClose(long waitMillis) Awaits for connections to close.voidCloses the server socket gracefully.protected abstract ProcessorCreate 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.intGets the accept count.intGets the acceptor thread priority.Gets the adapter.Gets the address.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.longGets the connection count.intGets the connection linger time.intGets the connection timeout.Gets the domain.protected AbstractEndpoint<S, ?> Gets the endpoint.Gets the executor for this protocol handler.Gets the MBean name for the Global Request Processor.Gets the handler.getId()Gets the protocol ID.intThe time Tomcat will wait for a subsequent request before closing the connection.intGets the local port.protected abstract LoggetLog()Concrete implementations need to provide access to their logger to be used by the abstract classes.intGets the maximum number of connections.intGets the maximum header count.intGets the maximum queue size.intGets the maximum number of threads.intGets the minimum number of spare threads.getName()Gets the name of this protocol instance.intGets the name index for this protocol.protected abstract StringObtain the prefix to be used when construction a name for this protocol handler.protected abstract UpgradeProtocolgetNegotiatedProtocol(String name) Find a suitable handler for the protocol negotiated at the network layer.Gets the object name.intgetPort()Gets the port.intGets the port offset.intGets the port with offset applied.intGets the processor cache size.getProperty(String name) Generic property getter used by the digester.protected abstract StringObtain the name of the protocol, (Http, Ajp, etc.).booleanGets whether TCP no-delay is enabled.intGets the thread priority.protected abstract UpgradeProtocolgetUpgradeProtocol(String name) Find a suitable handler for the protocol upgraded name specified.Get the utility executor that should be used by the protocol handler.intGets the count of waiting processors.voidinit()Initializes the protocol handler.booleanisPaused()Checks if the protocol handler is paused.booleanChecks if sendfile is supported.voidpause()Pauses the protocol handler.voidPost-deregisters this MBean.voidpostRegister(Boolean registrationDone) Post-registers this MBean.voidPre-deregisters this MBean.preRegister(MBeanServer server, 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.voidSets the address.voidSets 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(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(String name, 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(ScheduledExecutorService utilityExecutor) Set the utility executor that should be used by the protocol handler.voidstart()Starts the protocol handler.protected voidNote: 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 voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ProtocolHandler
addSslHostConfig, addSslHostConfig, addUpgradeProtocol, findSslHostConfigs, findUpgradeProtocols, getDesiredBufferSize
-
Field Details
-
rgOname
Name of MBean for the Global Request Processor. -
adapter
The adapter provides the link between the ProtocolHandler and the connector. -
processorCache
protected int processorCacheThe 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
-
oname
-
mserver
-
-
Constructor Details
-
AbstractProtocol
Creates a new protocol handler.- Parameters:
endpoint- The endpoint for low-level network I/O
-
-
Method Details
-
setProperty
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
-
getGlobalRequestProcessorMBeanName
Gets the MBean name for the Global Request Processor.- Returns:
- the MBean name
-
setAdapter
Sets the adapter.- Specified by:
setAdapterin interfaceProtocolHandler- Parameters:
adapter- The 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
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
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
Gets the protocol ID.- Specified by:
getIdin interfaceProtocolHandler- Returns:
- the protocol ID
-
getExecutor
Gets the executor for this protocol handler.- Specified by:
getExecutorin interfaceProtocolHandler- Returns:
- the executor
-
setExecutor
Sets the executor for this protocol handler.- Specified by:
setExecutorin interfaceProtocolHandler- Parameters:
executor- The executor
-
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
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
-
setAddress
-
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
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
Adds a processor to the waiting processors set.- Parameters:
processor- The processor
-
removeWaitingProcessor
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
-
getHandler
-
setHandler
Sets the handler.- Parameters:
handler- The handler
-
getLog
Concrete implementations need to provide access to their logger to be used by the abstract classes.- Returns:
- the logger
-
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
Obtain the name of the protocol, (Http, Ajp, etc.). Used with JMX.- Returns:
- the protocol name
-
getNegotiatedProtocol
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
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
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
-
getDomain
-
preRegister
Pre-registers this MBean.- Specified by:
preRegisterin interfaceMBeanRegistration- Parameters:
server- The MBean servername- The object name- Returns:
- the object name
- Throws:
Exception- if registration fails
-
postRegister
Post-registers this MBean.- Specified by:
postRegisterin interfaceMBeanRegistration- Parameters:
registrationDone- The registration status
-
preDeregister
Pre-deregisters this MBean.- Specified by:
preDeregisterin interfaceMBeanRegistration- Throws:
Exception- if deregistration fails
-
postDeregister
public void postDeregister()Post-deregisters this MBean.- Specified by:
postDeregisterin interfaceMBeanRegistration
-
init
Initializes the protocol handler.- Specified by:
initin interfaceProtocolHandler- Throws:
Exception- if initialization fails
-
start
Starts the protocol handler.- Specified by:
startin interfaceProtocolHandler- Throws:
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
Pauses the protocol handler.- Specified by:
pausein interfaceProtocolHandler- Throws:
Exception- if pause fails
-
isPaused
public boolean isPaused()Checks if the protocol handler is paused.- Returns:
trueif paused
-
resume
Resumes the protocol handler.- Specified by:
resumein interfaceProtocolHandler- Throws:
Exception- if resume fails
-
stop
Stops the protocol handler.- Specified by:
stopin interfaceProtocolHandler- Throws:
Exception- if stop fails
-
destroy
Destroys the protocol handler.- Specified by:
destroyin interfaceProtocolHandler- Throws:
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
-