Package org.apache.coyote
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 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 Stringdomainprotected MBeanServermserverprotected ObjectNameonameprotected intprocessorCacheThe maximum number of idle processors that will be retained in the cache and re-used with a subsequent request.protected ObjectNamergOnameName 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 Modifier and Type Method Description voidaddWaitingProcessor(Processor processor)longawaitConnectionsClose(long waitMillis)Wait for the client connections to the server to close gracefully.voidcloseServerSocketGraceful()Close the server socket (to prevent further connections) if the server socket was bound onProtocolHandler.start()(rather than onProtocolHandler.init()but do not perform any further shutdown.protected abstract ProcessorcreateProcessor()Create and configure a new Processor instance for the current protocol implementation.protected abstract ProcessorcreateUpgradeProcessor(SocketWrapperBase<?> socket, UpgradeToken upgradeToken)voiddestroy()Destroy the protocol (optional).intgetAcceptCount()intgetAcceptorThreadPriority()AdaptergetAdapter()Return the adapter associated with the protocol handler.InetAddressgetAddress()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()intgetConnectionLinger()intgetConnectionTimeout()StringgetDomain()protected AbstractEndpoint<S,?>getEndpoint()ExecutorgetExecutor()The executor, provide access to the underlying thread pool.ObjectNamegetGlobalRequestProcessorMBeanName()protected AbstractEndpoint.Handler<S>getHandler()StringgetId()The default behavior is to identify connectors uniquely with address and port.intgetKeepAliveTimeout()The time Tomcat will wait for a subsequent request before closing the connection.intgetLocalPort()protected abstract LoggetLog()Concrete implementations need to provide access to their logger to be used by the abstract classes.intgetMaxConnections()intgetMaxHeaderCount()intgetMaxThreads()intgetMinSpareThreads()StringgetName()The name will be prefix-address-port if address is non-null and prefix-port if the address is null.intgetNameIndex()protected abstract StringgetNamePrefix()Obtain 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.ObjectNamegetObjectName()intgetPort()intgetPortOffset()intgetPortWithOffset()intgetProcessorCache()StringgetProperty(String name)Generic property getter used by the digester.protected abstract StringgetProtocolName()Obtain the name of the protocol, (Http, Ajp, etc.).booleangetTcpNoDelay()intgetThreadPriority()protected abstract UpgradeProtocolgetUpgradeProtocol(String name)Find a suitable handler for the protocol upgraded name specified.ScheduledExecutorServicegetUtilityExecutor()Get the utility executor that should be used by the protocol handler.intgetWaitingProcessorCount()voidinit()Initialise the protocol.booleanisAprRequired()Requires APR/native librarybooleanisPaused()booleanisSendfileSupported()Does this ProtocolHandler support sendfile?voidpause()Pause the protocol (optional).voidpostDeregister()voidpostRegister(Boolean registrationDone)voidpreDeregister()ObjectNamepreRegister(MBeanServer server, ObjectName name)voidremoveWaitingProcessor(Processor processor)voidresume()Resume the protocol (optional).voidsetAcceptCount(int acceptCount)voidsetAcceptorThreadPriority(int threadPriority)voidsetAdapter(Adapter adapter)The adapter, used to call the connector.voidsetAddress(InetAddress ia)voidsetClientCertProvider(String s)voidsetConnectionLinger(int connectionLinger)voidsetConnectionTimeout(int timeout)voidsetExecutor(Executor executor)Set the optional executor that will be used by the connector.protected voidsetHandler(AbstractEndpoint.Handler<S> handler)voidsetKeepAliveTimeout(int keepAliveTimeout)voidsetMaxConnections(int maxConnections)voidsetMaxHeaderCount(int maxHeaderCount)voidsetMaxThreads(int maxThreads)voidsetMinSpareThreads(int minSpareThreads)voidsetPort(int port)voidsetPortOffset(int portOffset)voidsetProcessorCache(int processorCache)booleansetProperty(String name, String value)Generic property setter used by the digester.voidsetTcpNoDelay(boolean tcpNoDelay)voidsetThreadPriority(int threadPriority)voidsetUtilityExecutor(ScheduledExecutorService utilityExecutor)Set the utility executor that should be used by the protocol handler.voidstart()Start the protocol.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()Stop the protocol.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, addUpgradeProtocol, findSslHostConfigs, findUpgradeProtocols, getDesiredBufferSize
-
-
-
-
Field Detail
-
rgOname
protected 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 String domain
-
oname
protected ObjectName oname
-
mserver
protected MBeanServer mserver
-
-
Constructor Detail
-
AbstractProtocol
public AbstractProtocol(AbstractEndpoint<S,?> endpoint)
-
-
Method Detail
-
setProperty
public boolean setProperty(String name, 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 String getProperty(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 ObjectName getGlobalRequestProcessorMBeanName()
-
setAdapter
public void setAdapter(Adapter adapter)
Description copied from interface:ProtocolHandlerThe adapter, used to call the connector.- Specified by:
setAdapterin interfaceProtocolHandler- Parameters:
adapter- The adapter to associate
-
getAdapter
public Adapter getAdapter()
Description copied from interface:ProtocolHandlerReturn the adapter associated with the protocol handler.- Specified by:
getAdapterin interfaceProtocolHandler- Returns:
- the adapter
-
getProcessorCache
public int getProcessorCache()
-
setProcessorCache
public void setProcessorCache(int processorCache)
-
getClientCertProvider
public 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, the HTTP APR connector 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(String s)
-
getMaxHeaderCount
public int getMaxHeaderCount()
-
setMaxHeaderCount
public void setMaxHeaderCount(int maxHeaderCount)
-
isAprRequired
public boolean isAprRequired()
Description copied from interface:ProtocolHandlerRequires APR/native library- Specified by:
isAprRequiredin interfaceProtocolHandler- Returns:
trueif this Protocol Handler requires the APR/native library, otherwisefalse
-
isSendfileSupported
public boolean isSendfileSupported()
Description copied from interface:ProtocolHandlerDoes this ProtocolHandler support sendfile?- Specified by:
isSendfileSupportedin interfaceProtocolHandler- Returns:
trueif this Protocol Handler supports sendfile, otherwisefalse
-
getId
public String getId()
Description copied from interface:ProtocolHandlerThe 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:
getIdin interfaceProtocolHandler- Returns:
- the id
-
getExecutor
public Executor getExecutor()
Description copied from interface:ProtocolHandlerThe executor, provide access to the underlying thread pool.- Specified by:
getExecutorin interfaceProtocolHandler- Returns:
- The executor used to process requests
-
setExecutor
public void setExecutor(Executor executor)
Description copied from interface:ProtocolHandlerSet the optional executor that will be used by the connector.- Specified by:
setExecutorin interfaceProtocolHandler- Parameters:
executor- the executor
-
getUtilityExecutor
public 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(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()
-
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 isgetConnectionTimeout().- Returns:
- The timeout in milliseconds
-
setKeepAliveTimeout
public void setKeepAliveTimeout(int keepAliveTimeout)
-
getAddress
public InetAddress getAddress()
-
setAddress
public void setAddress(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()
-
setAcceptorThreadPriority
public void setAcceptorThreadPriority(int threadPriority)
-
getAcceptorThreadPriority
public int getAcceptorThreadPriority()
-
getNameIndex
public int getNameIndex()
-
getName
public 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 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 String getProtocolName()
Obtain the name of the protocol, (Http, Ajp, etc.). Used with JMX.- Returns:
- the protocol name
-
getNegotiatedProtocol
protected abstract UpgradeProtocol getNegotiatedProtocol(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(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 ObjectName getObjectName()
-
getDomain
public String getDomain()
-
preRegister
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
- Specified by:
preRegisterin interfaceMBeanRegistration- Throws:
Exception
-
postRegister
public void postRegister(Boolean registrationDone)
- Specified by:
postRegisterin interfaceMBeanRegistration
-
preDeregister
public void preDeregister() throws Exception- Specified by:
preDeregisterin interfaceMBeanRegistration- Throws:
Exception
-
postDeregister
public void postDeregister()
- Specified by:
postDeregisterin interfaceMBeanRegistration
-
init
public void init() throws ExceptionDescription copied from interface:ProtocolHandlerInitialise the protocol.- Specified by:
initin interfaceProtocolHandler- Throws:
Exception- If the protocol handler fails to initialise
-
start
public void start() throws ExceptionDescription copied from interface:ProtocolHandlerStart the protocol.- Specified by:
startin interfaceProtocolHandler- Throws:
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 ExceptionDescription copied from interface:ProtocolHandlerPause the protocol (optional).- Specified by:
pausein interfaceProtocolHandler- Throws:
Exception- If the protocol handler fails to pause
-
isPaused
public boolean isPaused()
-
resume
public void resume() throws ExceptionDescription copied from interface:ProtocolHandlerResume the protocol (optional).- Specified by:
resumein interfaceProtocolHandler- Throws:
Exception- If the protocol handler fails to resume
-
stop
public void stop() throws ExceptionDescription copied from interface:ProtocolHandlerStop the protocol.- Specified by:
stopin interfaceProtocolHandler- Throws:
Exception- If the protocol handler fails to stop
-
destroy
public void destroy() throws ExceptionDescription copied from interface:ProtocolHandlerDestroy the protocol (optional).- Specified by:
destroyin interfaceProtocolHandler- Throws:
Exception- If the protocol handler fails to destroy
-
closeServerSocketGraceful
public void closeServerSocketGraceful()
Description copied from interface:ProtocolHandlerClose the server socket (to prevent further connections) if the server socket was bound onProtocolHandler.start()(rather than onProtocolHandler.init()but do not perform any further shutdown.- Specified by:
closeServerSocketGracefulin interfaceProtocolHandler
-
awaitConnectionsClose
public long awaitConnectionsClose(long waitMillis)
Description copied from interface:ProtocolHandlerWait 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.- Specified by:
awaitConnectionsClosein interfaceProtocolHandler- 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
-
-