Top Description Inners Fields Constructors Methods
org.eclipse.jetty.server

public abstract Class AbstractConnector

extends ContainerLifeCycle
implements Connector, Dumpable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.server.Connector, org.eclipse.jetty.util.component.Graceful, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.LifeCycle
Known Direct Subclasses
org.eclipse.jetty.server.AbstractNetworkConnector, org.eclipse.jetty.server.LocalConnector
Annotations
@ManagedObject:Abstract implementation of the Connector Interface
Imports
java.io.IOException, java.net.Socket, java.nio.channels.ClosedByInterruptException, java.util.ArrayList, .Collection, .Collections, .HashSet, .LinkedHashMap, .List, .Map, .Objects, .Set, java.util.concurrent.CompletableFuture, .ConcurrentHashMap, .Executor, java.util.concurrent.locks.Condition, java.util.stream.Collectors, org.eclipse.jetty.http.ComplianceViolation, org.eclipse.jetty.io.ArrayByteBufferPool, .ByteBufferPool, .EndPoint, .RetainableByteBuffer, org.eclipse.jetty.io.ssl.SslConnection, org.eclipse.jetty.server.internal.HttpConnection, org.eclipse.jetty.util.ProcessorUtils, .StringUtil, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.component.ContainerLifeCycle, .Dumpable, org.eclipse.jetty.util.ssl.SslContextFactory, org.eclipse.jetty.util.thread.AutoLock, .ScheduledExecutorScheduler, .Scheduler, .ThreadPoolBudget, org.slf4j.Logger, .LoggerFactory

An abstract implementation of Connector that provides a ConnectionFactory mechanism for creating org.eclipse.jetty.io.Connection instances for various protocols (HTTP, SSL, etc).

Connector Services

The abstract connector manages the dependent services needed by all specific connector instances: These services are managed as aggregate beans by the ContainerLifeCycle super class and may either be managed or unmanaged beans.

Connection Factories

The connector keeps a collection of ConnectionFactory 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 available 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 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 org.eclipse.jetty.io.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 org.eclipse.jetty.io.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 org.eclipse.jetty.io.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 org.eclipse.jetty.io.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 the 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:
  1. block waiting for new connections
  2. accept the connection (eg socket accept)
  3. perform any configuration of the connection (eg. socket configuration)
  4. call the getDefaultConnectionFactory() ConnectionFactory#newConnection(Connector, EndPoint) method to create a new Connection instance.
The default number of acceptor tasks is the minimum of 1 and the number of available CPUs divided by 8. Having more acceptors may reduce the latency for servers that see a high rate of new connections (eg HTTP/1.0 without keep-alive). Typically the default is sufficient for modern persistent protocols (HTTP/1.1, HTTP/2 etc.)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private boolean
private int
private final Thread[]
private final ByteBufferPool
private ConnectionFactory
private String
private final Set<EndPoint>
private final Executor
private final Map<String, ConnectionFactory>
private long
private final Set<EndPoint>
private ThreadPoolBudget.Lease
private final AutoLock
private String
private final Scheduler
private final Server
private final Condition
private Graceful.Shutdown
private long
protected static final Logger

Constructor Summary

AccessConstructor and Description
public
AbstractConnector(Server
The Server this connector will be added to, must not be null
server
,
Executor
An Executor for this connector or null to use the Server's Executor
executor
,
Scheduler
A Scheduler for this connector or null to use the Server's Scheduler
scheduler
,
ByteBufferPool
A ByteBufferPool for this connector or null to use the Server's ByteBufferPool
bufferPool
,
int
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.
acceptors
,
ConnectionFactory...
The ConnectionFactory instances to use
factories
)

Method Summary

Modifier and TypeMethod and Description
protected abstract void
accept(int acceptorID)

public void
public void
public void
public void
protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.
protected void
doStop()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.
public int
public int

Returns:

Returns the number of acceptor threads.
getAcceptors
()

public ByteBufferPool
getByteBufferPool()

Implements org.eclipse.jetty.server.Connector.getByteBufferPool.

Get the ByteBufferPool to acquire buffers from and release buffers to.
public Collection<EndPoint>
public Collection<ConnectionFactory>
public ConnectionFactory
public <T> T
public ConnectionFactory
getDefaultConnectionFactory()

Implements org.eclipse.jetty.server.Connector.getDefaultConnectionFactory.

Get the default ConnectionFactory associated with the default protocol name.
public String
public Executor
getExecutor()

Implements org.eclipse.jetty.server.Connector.getExecutor.

Get the Executor used to submit tasks.
public long
public String
getName()

Implements org.eclipse.jetty.server.Connector.getName.

Get the connector name if set.
public List<String>
public Scheduler
getScheduler()

Implements org.eclipse.jetty.server.Connector.getScheduler.

Get the Scheduler used to schedule tasks.
public Server
getServer()

Implements org.eclipse.jetty.server.Connector.getServer.

Get the Server instance associated with this Connector.
public long
protected boolean
protected void
public boolean

Returns:

Is the connector accepting new connections
isAccepting
()

public boolean
public void
join()

public void
join(long timeout)

protected void
protected void
public ConnectionFactory
public void
setAccepting(boolean accepting)

public void
setAcceptorPriorityDelta(int
the acceptor priority delta
acceptorPriorityDelta
)

Set the acceptor thread priority delta.

public void
public void
setDefaultProtocol(String defaultProtocol)

public void
setIdleTimeout(long
the idle timeout
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.

public void
setName(String
A connector name.
name
)

Set a connector name.

public void
public CompletableFuture<Void>
shutdown()

Implements org.eclipse.jetty.util.component.Graceful.shutdown.

Shutdown the component.
public String
toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Returns a string representation of the object.
Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydumpdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans

Field Detail

_acceptingback to summary
private boolean _accepting
_acceptorPriorityDeltaback to summary
private int _acceptorPriorityDelta
_acceptorsback to summary
private final Thread[] _acceptors
_bufferPoolback to summary
private final ByteBufferPool _bufferPool
_defaultConnectionFactoryback to summary
private ConnectionFactory _defaultConnectionFactory
_defaultProtocolback to summary
private String _defaultProtocol
_endpointsback to summary
private final Set<EndPoint> _endpoints
_executorback to summary
private final Executor _executor
_factoriesback to summary
private final Map<String, ConnectionFactory> _factories
_idleTimeoutback to summary
private long _idleTimeout
_immutableEndPointsback to summary
private final Set<EndPoint> _immutableEndPoints
_leaseback to summary
private ThreadPoolBudget.Lease _lease
_lockback to summary
private final AutoLock _lock

Hides org.eclipse.jetty.util.component.AbstractLifeCycle._lock.

_nameback to summary
private String _name
_schedulerback to summary
private final Scheduler _scheduler
_serverback to summary
private final Server _server
_setAcceptingback to summary
private final Condition _setAccepting
_shutdownback to summary
private Graceful.Shutdown _shutdown
_shutdownIdleTimeoutback to summary
private long _shutdownIdleTimeout
LOGback to summary
protected static final Logger LOG

Hides org.eclipse.jetty.util.component.ContainerLifeCycle.LOG.

Constructor Detail

AbstractConnectorback to summary
public AbstractConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, int acceptors, ConnectionFactory... factories)
Parameters
server:Server

The Server this connector will be added to, must not be null

executor:Executor

An Executor for this connector or null to use the Server's Executor

scheduler:Scheduler

A Scheduler for this connector or null to use the Server's Scheduler

bufferPool:ByteBufferPool

A ByteBufferPool for this connector or null to use the Server's ByteBufferPool

acceptors:int

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:ConnectionFactory[]

The ConnectionFactory instances to use

Method Detail

acceptback to summary
protected abstract void accept(int acceptorID) throws IOException, InterruptedException
addConnectionFactoryback to summary
public void addConnectionFactory(ConnectionFactory factory)
addFirstConnectionFactoryback to summary
public void addFirstConnectionFactory(ConnectionFactory factory)
addIfAbsentConnectionFactoryback to summary
public void addIfAbsentConnectionFactory(ConnectionFactory factory)
clearConnectionFactoriesback to summary
public void clearConnectionFactories()
doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

If there was a problem starting. Will cause a transition to FAILED state

doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

If there was a problem stopping. Will cause a transition to FAILED state

getAcceptorPriorityDeltaback to summary
public int getAcceptorPriorityDelta()
Annotations
@ManagedAttribute:The priority delta to apply to acceptor threads
getAcceptorsback to summary
public int getAcceptors()
Returns:int

Returns the number of acceptor threads.

Annotations
@ManagedAttribute:number of acceptor threads
getByteBufferPoolback to summary
public ByteBufferPool getByteBufferPool()

Implements org.eclipse.jetty.server.Connector.getByteBufferPool.

Doc from org.eclipse.jetty.server.Connector.getByteBufferPool.

Get the ByteBufferPool to acquire buffers from and release buffers to.

Returns:ByteBufferPool

the ByteBufferPool to acquire buffers from and release buffers to

Annotations
@Override
getConnectedEndPointsback to summary
public Collection<EndPoint> getConnectedEndPoints()

Implements org.eclipse.jetty.server.Connector.getConnectedEndPoints.

Returns:Collection<EndPoint>

Doc from org.eclipse.jetty.server.Connector.getConnectedEndPoints.

immutable collection of connected endpoints

Annotations
@Override
getConnectionFactoriesback to summary
public Collection<ConnectionFactory> getConnectionFactories()

Implements org.eclipse.jetty.server.Connector.getConnectionFactories.

Annotations
@Override
getConnectionFactoryback to summary
public ConnectionFactory getConnectionFactory(String protocol)

Implements org.eclipse.jetty.server.Connector.getConnectionFactory.

Parameters
protocol:String

Doc from org.eclipse.jetty.server.Connector.getConnectionFactory.

the next protocol

Returns:ConnectionFactory

Doc from org.eclipse.jetty.server.Connector.getConnectionFactory.

the ConnectionFactory associated with the protocol name

Annotations
@Override
getConnectionFactoryback to summary
public <T> T getConnectionFactory(Class<T> factoryType)

Implements org.eclipse.jetty.server.Connector.getConnectionFactory.

Annotations
@Override
getDefaultConnectionFactoryback to summary
public ConnectionFactory getDefaultConnectionFactory()

Implements org.eclipse.jetty.server.Connector.getDefaultConnectionFactory.

Doc from org.eclipse.jetty.server.Connector.getDefaultConnectionFactory.

Get the default ConnectionFactory associated with the default protocol name.

Returns:ConnectionFactory

the default ConnectionFactory associated with the default protocol name

Annotations
@Override
getDefaultProtocolback to summary
public String getDefaultProtocol()
Annotations
@ManagedAttribute:This connector\'s default protocol
getExecutorback to summary
public Executor getExecutor()

Implements org.eclipse.jetty.server.Connector.getExecutor.

Doc from org.eclipse.jetty.server.Connector.getExecutor.

Get the Executor used to submit tasks.

Returns:Executor

the Executor used to submit tasks

Annotations
@Override
getIdleTimeoutback to summary
public long getIdleTimeout()

Implements org.eclipse.jetty.server.Connector.getIdleTimeout.

Returns:long

Doc from org.eclipse.jetty.server.Connector.getIdleTimeout.

the max idle timeout for connections in milliseconds

Annotations
@Override
@ManagedAttribute:The connection idle timeout in milliseconds
getNameback to summary
public String getName()

Implements org.eclipse.jetty.server.Connector.getName.

Doc from org.eclipse.jetty.server.Connector.getName.

Get the connector name if set.

A ContextHandler may be configured with virtual hosts in the form "@connectorName" and will only serve requests from the named connector.

Returns:String

The connector name or null.

Annotations
@Override
getProtocolsback to summary
public List<String> getProtocols()

Implements org.eclipse.jetty.server.Connector.getProtocols.

Annotations
@Override
@ManagedAttribute:Protocols supported by this connector
getSchedulerback to summary
public Scheduler getScheduler()

Implements org.eclipse.jetty.server.Connector.getScheduler.

Doc from org.eclipse.jetty.server.Connector.getScheduler.

Get the Scheduler used to schedule tasks.

Returns:Scheduler

the Scheduler used to schedule tasks

Annotations
@Override
getServerback to summary
public Server getServer()

Implements org.eclipse.jetty.server.Connector.getServer.

Doc from org.eclipse.jetty.server.Connector.getServer.

Get the Server instance associated with this Connector.

Returns:Server

the Server instance associated with this Connector

Annotations
@Override
getShutdownIdleTimeoutback to summary
public long getShutdownIdleTimeout()
handleAcceptFailureback to summary
protected boolean handleAcceptFailure(Throwable ex)
interruptAcceptorsback to summary
protected void interruptAcceptors()
isAcceptingback to summary
public boolean isAccepting()
Returns:boolean

Is the connector accepting new connections

isShutdownback to summary
public boolean isShutdown()

Implements org.eclipse.jetty.util.component.Graceful.isShutdown.

Returns:boolean

Doc from org.eclipse.jetty.util.component.Graceful.isShutdown.

True if shutdown() has been called.

Annotations
@Override
joinback to summary
public void join() throws InterruptedException
joinback to summary
public void join(long timeout) throws InterruptedException
onEndPointClosedback to summary
protected void onEndPointClosed(EndPoint endp)
onEndPointOpenedback to summary
protected void onEndPointOpened(EndPoint endp)
removeConnectionFactoryback to summary
public ConnectionFactory removeConnectionFactory(String protocol)
setAcceptingback to summary
public void setAccepting(boolean accepting)
setAcceptorPriorityDeltaback to summary
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:int

the acceptor priority delta

setConnectionFactoriesback to summary
public void setConnectionFactories(Collection<ConnectionFactory> factories)
setDefaultProtocolback to summary
public void setDefaultProtocol(String defaultProtocol)
setIdleTimeoutback to summary
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:long

the idle timeout

setNameback to summary
public void setName(String name)

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:String

A connector name.

setShutdownIdleTimeoutback to summary
public void setShutdownIdleTimeout(long idle)
shutdownback to summary
public CompletableFuture<Void> shutdown()

Implements org.eclipse.jetty.util.component.Graceful.shutdown.

Doc from org.eclipse.jetty.util.component.Graceful.shutdown.

Shutdown the component. When this method returns, the component should not accept any new load.

Returns:CompletableFuture<Void>

A future that is completed once all load on the component is completed

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.eclipse.jetty.server back to summary

private Class AbstractConnector.Acceptor

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private final int
private String

Constructor Summary

AccessConstructor and Description
private
Acceptor(int id)

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_idback to summary
private final int _id
_nameback to summary
private String _name

Constructor Detail

Acceptorback to summary
private Acceptor(int id)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override