@ManagedObject(value="Abstract implementation of the Connector Interface") public abstract class AbstractConnector extends ContainerLifeCycle implements Connector, Dumpable
An abstract implementation of Connector
that provides a ConnectionFactory
mechanism
for creating Connection
instances for various protocols (HTTP, SSL, SPDY, etc).
Executor
service is used to run all active tasks needed by this connector such as accepting connections
or handle HTTP requests. The default is to use the Server.getThreadPool()
as an executor.
Scheduler
service 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 new
ScheduledExecutorScheduler
instance.
ByteBufferPool
service is made available to all connections to be used to acquire and release
ByteBuffer
instances from a pool. The default is to use a new ArrayByteBufferPool
instance.
ContainerLifeCycle
super class and
may either be managed or unmanaged beans.
ConnectionFactory
instances, each of which are known by their
protocol name. The protocol name may be a real protocol (eg http/1.1 or spdy/3) 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.
ConnectionFactory
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 the SPDY factories that can also provide HTTP Semantics). Similarly the SslConnectionFactory
is
configured by passing it a SslContextFactory
and a next protocol name.
ConnectionFactory
s 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.
ConnectionFactory
s 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 unecrypted 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.
ConnectionFactory
s 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 NPN protocol is an extension
of SSL to allow a protocol to be specified during the SSL handshake. NPN is used by the SPDY protocol to
negotiate the version of SPDY or HTTP that the client and server will speak. Thus to accept a SPDY connection, the
connector will be configured with ConnectionFactory
s for "SSL-NPN", "NPN", "spdy/3", "spdy/2", "http/1.1"
with the default protocol being "SSL-NPN". Thus a newly accepted connection uses "SSL-NPN", which specifies a
SSLConnectionFactory with "NPN" as the next protocol. Thus an SslConnection instance is created chained to an NPNConnection
instance. The NPN connection then negotiates with the client to determined the next protocol, which could be
"spdy/3", "spdy/2" or the default of "http/1.1". Once the next protocol is determined, the NPN connection
calls getConnectionFactory(String)
to create a connection instance that will replace the NPN connection as
the connection chained to the SSLConnection.
Exception
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:
getDefaultConnectionFactory()
ConnectionFactory.newConnection(Connector, org.eclipse.jetty.io.EndPoint)
method to create a new Connection instance.
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Constructor and Description |
---|
AbstractConnector(Server server,
Executor executor,
Scheduler scheduler,
ByteBufferPool pool,
int acceptors,
ConnectionFactory... factories) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
accept(int acceptorID) |
void |
addConnectionFactory(ConnectionFactory factory) |
void |
clearConnectionFactories() |
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
protected void |
doStop()
Stops the managed lifecycle beans in the reverse order they were added.
|
int |
getAcceptorPriorityDelta() |
int |
getAcceptors() |
ByteBufferPool |
getByteBufferPool() |
Collection<EndPoint> |
getConnectedEndPoints() |
Collection<ConnectionFactory> |
getConnectionFactories() |
<T> T |
getConnectionFactory(Class<T> factoryType) |
ConnectionFactory |
getConnectionFactory(String protocol) |
ConnectionFactory |
getDefaultConnectionFactory() |
String |
getDefaultProtocol() |
Executor |
getExecutor() |
long |
getIdleTimeout() |
String |
getName()
Get the connector name if set.
|
List<String> |
getProtocols() |
Scheduler |
getScheduler() |
Server |
getServer() |
protected void |
interruptAcceptors() |
protected boolean |
isAccepting() |
void |
join() |
void |
join(long timeout) |
protected void |
onEndPointClosed(EndPoint endp) |
protected void |
onEndPointOpened(EndPoint endp) |
ConnectionFactory |
removeConnectionFactory(String protocol) |
void |
setAcceptorPriorityDelta(int acceptorPriorityDelta)
Set the acceptor thread priority delta.
|
void |
setConnectionFactories(Collection<ConnectionFactory> factories) |
void |
setDefaultProtocol(String defaultProtocol) |
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. |
void |
setName(String name)
Set a connector name.
|
Future<Void> |
shutdown() |
String |
toString() |
addBean, addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getTransport
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
protected final Logger LOG
public AbstractConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, int acceptors, ConnectionFactory... factories)
server
- The server this connector will be added to. Must not be null.executor
- An executor for this connector or null to use the servers executorscheduler
- A scheduler for this connector or null to either a Scheduler
set as a server bean or if none set, then a new ScheduledExecutorScheduler
instance.pool
- A buffer pool for this connector or null to either a ByteBufferPool
set as a server bean or none set, the new ArrayByteBufferPool
instance.acceptors
- 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
- The Connection Factories to use.public Server getServer()
public Executor getExecutor()
getExecutor
in interface Connector
Executor
used to submit taskspublic ByteBufferPool getByteBufferPool()
getByteBufferPool
in interface Connector
ByteBufferPool
to acquire buffers from and release buffers to@ManagedAttribute(value="Idle timeout") public long getIdleTimeout()
getIdleTimeout
in interface Connector
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:
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.
idleTimeout
- the idle timeout@ManagedAttribute(value="number of acceptor threads") public int getAcceptors()
protected void doStart() throws Exception
ContainerLifeCycle
doStart
in class ContainerLifeCycle
Exception
protected void interruptAcceptors()
protected void doStop() throws Exception
ContainerLifeCycle
doStop
in class ContainerLifeCycle
Exception
public void join() throws InterruptedException
InterruptedException
public void join(long timeout) throws InterruptedException
InterruptedException
protected abstract void accept(int acceptorID) throws IOException, InterruptedException
IOException
InterruptedException
protected boolean isAccepting()
public ConnectionFactory getConnectionFactory(String protocol)
getConnectionFactory
in interface Connector
ConnectionFactory
associated with the protocol namepublic <T> T getConnectionFactory(Class<T> factoryType)
getConnectionFactory
in interface Connector
public void addConnectionFactory(ConnectionFactory factory)
public ConnectionFactory removeConnectionFactory(String protocol)
public Collection<ConnectionFactory> getConnectionFactories()
getConnectionFactories
in interface Connector
public void setConnectionFactories(Collection<ConnectionFactory> factories)
@ManagedAttribute(value="The priority delta to apply to acceptor threads") public int getAcceptorPriorityDelta()
public void setAcceptorPriorityDelta(int acceptorPriorityDelta)
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
acceptorPriorityDelta
- @ManagedAttribute(value="Protocols supported by this connector") public List<String> getProtocols()
getProtocols
in interface Connector
public void clearConnectionFactories()
@ManagedAttribute(value="This connector\'s default protocol") public String getDefaultProtocol()
public void setDefaultProtocol(String defaultProtocol)
public ConnectionFactory getDefaultConnectionFactory()
getDefaultConnectionFactory
in interface Connector
ConnectionFactory
associated with the default protocol namepublic Collection<EndPoint> getConnectedEndPoints()
getConnectedEndPoints
in interface Connector
protected void onEndPointOpened(EndPoint endp)
protected void onEndPointClosed(EndPoint endp)
public Scheduler getScheduler()
getScheduler
in interface Connector
Scheduler
used to schedule taskspublic String getName()
Connector
A ContextHandler
may be configured with
virtual hosts in the form "@connectorName" and will only serve
requests from the named connector.
public void setName(String name)
name
- A connector name.Copyright © 1995-2015 Webtide. All Rights Reserved.