Class AbstractConnector
- All Implemented Interfaces:
 Connector, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, Graceful, LifeCycle
- Direct Known Subclasses:
 AbstractNetworkConnector, LocalConnector, MemoryConnector, UnixDomainServerConnector
An abstract implementation of Connector that provides a ConnectionFactory mechanism
for creating Connection instances for various protocols (HTTP, SSL, etc).
Connector Services
The abstract connector manages the dependent services needed by all specific connector instances:- The 
Executorservice is used to run all active tasks needed by this connector such as accepting connections or handle HTTP requests. The default is to use theServer.getThreadPool()as an executor. - The 
Schedulerservice is used to monitor the idle timeouts of all connections and is also made available to the connections to time such things as asynchronous request timeouts. The default is to use a newScheduledExecutorSchedulerinstance. - The 
ByteBufferPoolservice is made available to all connections to be used to acquire and releaseRetainableByteBufferinstances from a pool. The default is to use a newArrayByteBufferPoolinstance. 
ContainerLifeCycle super class and
may either be managed or unmanaged beans.
Connection Factories
The connector keeps a collection ofConnectionFactory instances, each of which are known by their
protocol name.  The protocol name may be a real protocol (e.g. "http/1.1" or "h2") or it may be a private name
that represents a special connection factory. For example, the name "SSL-http/1.1" is used for
an SslConnectionFactory that has been instantiated with the HttpConnectionFactory as it's
next protocol.
Configuring Connection Factories
The collection of availableConnectionFactory may be constructor injected or modified with the
methods addConnectionFactory(ConnectionFactory), removeConnectionFactory(String) and
setConnectionFactories(Collection).  Only a single ConnectionFactory instance may be configured
per protocol name, so if two factories with the same ConnectionFactory.getProtocol() are set, then
the second will replace the first.
The protocol factory used for newly accepted connections is specified by
the method setDefaultProtocol(String) or defaults to the protocol of the first configured factory.
Each Connection factory type is responsible for the configuration of the protocols that it accepts. Thus to
configure the HTTP protocol, you pass a HttpConfiguration instance to the HttpConnectionFactory
(or other factories that can also provide HTTP Semantics).  Similarly the SslConnectionFactory is
configured by passing it a SslContextFactory and a next protocol name.
Connection Factory Operation
ConnectionFactorys may simply create a Connection instance to support a specific
protocol.  For example, the HttpConnectionFactory will create a HttpConnection instance
that can handle http/1.1, http/1.0 and http/0.9.
ConnectionFactorys may also create a chain of Connection instances, using other ConnectionFactory instances.
For example, the SslConnectionFactory is configured with a next protocol name, so that once it has accepted
a connection and created an SslConnection, it then used the next ConnectionFactory from the
connector using the getConnectionFactory(String) method, to create a Connection instance that
will handle the unencrypted bytes from the SslConnection.   If the next protocol is "http/1.1", then the
SslConnectionFactory will have a protocol name of "SSL-http/1.1" and lookup "http/1.1" for the protocol
to run over the SSL connection.
ConnectionFactorys may also create temporary Connection instances that will exchange bytes
over the connection to determine what is the next protocol to use.  For example the ALPN protocol is an extension
of SSL to allow a protocol to be specified during the SSL handshake. ALPN is used by the HTTP/2 protocol to
negotiate the protocol that the client and server will speak.  Thus to accept an HTTP/2 connection, the
connector will be configured with ConnectionFactorys for "SSL-ALPN", "h2", "http/1.1"
with the default protocol being "SSL-ALPN".  Thus a newly accepted connection uses "SSL-ALPN", which specifies a
SSLConnectionFactory with "ALPN" as the next protocol.  Thus an SSL connection instance is created chained to an ALPN
connection instance.  The ALPN connection then negotiates with the client to determined the next protocol, which
could be "h2" or the default of "http/1.1".  Once the next protocol is determined, the ALPN connection
calls getConnectionFactory(String) to create a connection instance that will replace the ALPN connection as
the connection chained to the SSL connection.
Acceptors
The connector will execute a number of acceptor tasks to theException service passed to the constructor.
The acceptor tasks run in a loop while the connector is running and repeatedly call the abstract accept(int) method.
The implementation of the accept method must:
- block waiting for new connections
 - accept the connection (eg socket accept)
 - perform any configuration of the connection (eg. socket configuration)
 - call the 
getDefaultConnectionFactory()ConnectionFactory.newConnection(Connector, EndPoint)method to create a new Connection instance. 
- 
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendableNested classes/interfaces inherited from interface Graceful
Graceful.Shutdown, Graceful.ThrowingRunnableNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener - 
Field Summary
Fields - 
Constructor Summary
ConstructorsConstructorDescriptionAbstractConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, int acceptors, ConnectionFactory... factories)  - 
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidaccept(int acceptorID) voidaddConnectionFactory(ConnectionFactory factory) voidvoidvoidprotected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.intintGet theByteBufferPoolto acquire buffers from and release buffers to.<T> TgetConnectionFactory(Class<T> factoryType) getConnectionFactory(String protocol) Get the defaultConnectionFactoryassociated with the default protocol name.Get theExecutorused to submit tasks.longgetName()Get the connector name if set.Get theSchedulerused to schedule tasks.longprotected booleanprotected voidbooleanbooleanvoidjoin()voidjoin(long timeout) protected voidonEndPointClosed(EndPoint endp) protected voidonEndPointOpened(EndPoint endp) removeConnectionFactory(String protocol) voidsetAccepting(boolean accepting) voidsetAcceptorPriorityDelta(int acceptorPriorityDelta) Set the acceptor thread priority delta.voidsetConnectionFactories(Collection<ConnectionFactory> factories) voidsetDefaultProtocol(String defaultProtocol) voidsetIdleTimeout(long idleTimeout) Sets the maximum Idle time for a connection, which roughly translates to theSocket.setSoTimeout(int)call, although with NIO implementations other mechanisms may be used to implement the timeout.voidSet a connector name.voidsetShutdownIdleTimeout(long idle) Sets an idle timeout to be used whenshutdown()is called.shutdown()Shutdown the component.toString()Methods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Connector
getTransportMethods inherited from interface Container
addBean, addBean, addEventListener, getBean, getBeans, getBeans, getCachedBeans, getContainedBeans, getEventListeners, isManaged, manage, removeBean, removeEventListener, unmanageMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop 
- 
Field Details
- 
LOG
protected static final org.slf4j.Logger LOG 
 - 
 - 
Constructor Details
- 
AbstractConnector
public AbstractConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, int acceptors, ConnectionFactory... factories) - Parameters:
 server- TheServerthis connector will be added to, must not be nullexecutor- AnExecutorfor this connector or null to use the Server's Executorscheduler- ASchedulerfor this connector or null to use the Server's SchedulerbufferPool- AByteBufferPoolfor this connector or null to use the Server's ByteBufferPoolacceptors- the number of acceptor threads to use, or -1 for a default value. If 0, then no acceptor threads will be launched and some other mechanism will need to be used to accept new connections.factories- TheConnectionFactoryinstances to use
 
 - 
 - 
Method Details
- 
getServer
 - 
getExecutor
 - 
getByteBufferPool
Description copied from interface:ConnectorGet theByteBufferPoolto acquire buffers from and release buffers to.- Specified by:
 getByteBufferPoolin interfaceConnector- Returns:
 - the 
ByteBufferPoolto acquire buffers from and release buffers to 
 - 
getIdleTimeout
- Specified by:
 getIdleTimeoutin interfaceConnector- Returns:
 - the max idle timeout for connections in milliseconds
 
 - 
setIdleTimeout
public void setIdleTimeout(long idleTimeout) Sets the maximum Idle time for a connection, which roughly translates to the
Socket.setSoTimeout(int)call, although with NIO implementations other mechanisms may be used to implement the timeout.The max idle time is applied:
- When waiting for a new message to be received on a connection
 - When waiting for a new message to be sent on a connection
 
This value is interpreted as the maximum time between some progress being made on the connection. So if a single byte is read or written, then the timeout is reset.
- Parameters:
 idleTimeout- the idle timeout
 - 
setShutdownIdleTimeout
public void setShutdownIdleTimeout(long idle) Sets an idle timeout to be used whenshutdown()is called. This will replace the existing idle timeouts on all the connected endpoints. This mechanism can be disabled by setting the shutdown idle timeout to a negative value. - 
getShutdownIdleTimeout
public long getShutdownIdleTimeout() - 
getAcceptors
- Returns:
 - Returns the number of acceptor threads.
 
 - 
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
 doStartin classContainerLifeCycle- Throws:
 Exception- If there was a problem starting. Will cause a transition to FAILED state
 - 
interruptAcceptors
protected void interruptAcceptors() - 
shutdown
Description copied from interface:GracefulShutdown the component. When this method returns, the component should not accept any new load. - 
isShutdown
public boolean isShutdown()- Specified by:
 isShutdownin interfaceGraceful- Returns:
 - True if 
Graceful.shutdown()has been called. 
 - 
doStop
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
 doStopin classContainerLifeCycle- Throws:
 Exception- If there was a problem stopping. Will cause a transition to FAILED state
 - 
join
- Throws:
 InterruptedException
 - 
join
- Throws:
 InterruptedException
 - 
accept
- Throws:
 IOExceptionInterruptedException
 - 
isAccepting
public boolean isAccepting()- Returns:
 - Is the connector accepting new connections
 
 - 
setAccepting
public void setAccepting(boolean accepting)  - 
getConnectionFactory
- Specified by:
 getConnectionFactoryin interfaceConnector- Parameters:
 protocol- the next protocol- Returns:
 - the 
ConnectionFactoryassociated with the protocol name 
 - 
getConnectionFactory
- Specified by:
 getConnectionFactoryin interfaceConnector
 - 
addConnectionFactory
 - 
addFirstConnectionFactory
 - 
addIfAbsentConnectionFactory
 - 
removeConnectionFactory
 - 
getConnectionFactories
- Specified by:
 getConnectionFactoriesin interfaceConnector
 - 
setConnectionFactories
 - 
clearConnectionFactories
public void clearConnectionFactories() - 
getAcceptorPriorityDelta
@ManagedAttribute("The priority delta to apply to acceptor threads") public int getAcceptorPriorityDelta() - 
setAcceptorPriorityDelta
public void setAcceptorPriorityDelta(int acceptorPriorityDelta) Set the acceptor thread priority delta.This allows the acceptor thread to run at a different priority. Typically this would be used to lower the priority to give preference to handling previously accepted connections rather than accepting new connections
- Parameters:
 acceptorPriorityDelta- the acceptor priority delta
 - 
getProtocols
- Specified by:
 getProtocolsin interfaceConnector
 - 
getDefaultProtocol
 - 
setDefaultProtocol
 - 
getDefaultConnectionFactory
Description copied from interface:ConnectorGet the defaultConnectionFactoryassociated with the default protocol name.- Specified by:
 getDefaultConnectionFactoryin interfaceConnector- Returns:
 - the default 
ConnectionFactoryassociated with the default protocol name 
 - 
handleAcceptFailure
 - 
getConnectedEndPoints
- Specified by:
 getConnectedEndPointsin interfaceConnector- Returns:
 - immutable collection of connected endpoints
 
 - 
onEndPointOpened
 - 
onEndPointClosed
 - 
getScheduler
 - 
getName
Description copied from interface:ConnectorGet the connector name if set.A
ContextHandlermay be configured with virtual hosts in the form "@connectorName" and will only serve requests from the named connector. - 
setName
Set a connector name. A context may be configured with virtual hosts in the form "@contextname" and will only serve requests from the named connector,- Parameters:
 name- A connector name.
 - 
toString
- Overrides:
 toStringin classAbstractLifeCycle
 
 -