Connector implementation is the primary connector for the
Jetty server over TCP/IP. By the use of various ConnectionFactory instances it is able
to accept connections for HTTP, HTTP/2 and WebSocket, either directly or over SSL.
The connector is a fully asynchronous NIO based implementation that by default will
use all the commons services (eg Executor, Scheduler) of the
passed Server instance, but all services may also be constructor injected
into the connector so that it may operate with dedicated or otherwise shared services.
Various convenience constructors are provided to assist with common configurations of
ConnectionFactories, whose generic use is described in AbstractConnector.
If no connection factories are passed, then the connector will
default to use a HttpConnectionFactory. If an non null SslContextFactory
instance is passed, then this used to instantiate a SslConnectionFactory which is
prepended to the other passed or default factories.
The default number of selectors is equal to half of the number of processors available to the JVM, which should allow optimal performance even if all the connections used are performing significant non-blocking work in the callback tasks.
| Modifier and Type | Class and Description |
|---|---|
| protected class |
| Modifier and Type | Field and Description |
|---|---|
| private volatile ServerSocketChannel | |
| private volatile int | |
| private volatile int | |
| private volatile boolean | |
| private final AtomicReference | |
| private volatile int | |
| private volatile boolean | |
| private volatile int | |
| private final SelectorManager | |
| private volatile boolean | |
| private volatile boolean |
| Access | Constructor and Description |
|---|---|
| public | ServerConnector(Server
The server)Server this connector will accept connection for.Construct a ServerConnector with a private instance of |
| public | ServerConnector(Server
The server, int Server this connector will accept connection for.the number of acceptor threads to use, or -1 for a default value. Acceptors accept new TCP/IP connections. If 0, then
the selector threads are used to accept connections. acceptors, int the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress. selectors)Construct a ServerConnector with a private instance of |
| public | ServerConnector(Server
The server, int Server this connector will accept connection for.the number of acceptor threads to use, or -1 for a default value. Acceptors accept new TCP/IP connections. If 0, then
the selector threads are used to accept connections. acceptors, int the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress. selectors, ConnectionFactory... Zero or more factories)ConnectionFactory instances used to create and configure connections.Construct a ServerConnector with a private instance of |
| public | ServerConnector(Server
The server, ConnectionFactory... Server this connector will accept connection for.Zero or more factories)ConnectionFactory instances used to create and configure connections.Construct a Server Connector with the passed Connection factories. |
| public | ServerConnector(Server
The server, SslContextFactory.Server this connector will accept connection for.If non null, then a sslContextFactorySslConnectionFactory is instantiated and prepended to the
list of HTTP Connection Factory.Construct a ServerConnector with a private instance of |
| public | ServerConnector(Server
The server, int Server this connector will accept connection for.the number of acceptor threads to use, or -1 for a default value. Acceptors accept new TCP/IP connections. If 0, then
the selector threads are used to accept connections. acceptors, int the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress. selectors, SslContextFactory.If non null, then a sslContextFactorySslConnectionFactory is instantiated and prepended to the
list of HTTP Connection Factory.Construct a ServerConnector with a private instance of |
| public | ServerConnector(Server
The server, SslContextFactory.Server this connector will accept connection for.If non null, then a sslContextFactory,SslConnectionFactory is instantiated and prepended to the
list of ConnectionFactories, with the first factory being the default protocol for the SslConnectionFactory.Zero or more factories)ConnectionFactory instances used to create and configure connections.
|
| public | ServerConnector(Server
The server this connector will be accept connection for. server, Executor An executor used to run tasks for handling requests, acceptors and selectors.
If null then use the servers executor executor, Scheduler A scheduler used to schedule timeouts. If null then use the servers scheduler scheduler, ByteBufferPool A ByteBuffer pool used to allocate buffers. If null then create a private pool with default configuration. bufferPool, int the number of acceptor threads to use, or -1 for a default value. Acceptors accept new TCP/IP connections. If 0, then
the selector threads are used to accept connections. acceptors, int the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress. selectors, ConnectionFactory... Zero or more factories)ConnectionFactory instances used to create and configure connections.
|
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| private void | |
| public void | close()
Overrides org. Implements org. Performs the activities needed to close the network communication (for example, to stop accepting network connections). |
| protected void | |
| protected void | doStart()
Overrides org. Starts the managed lifecycle beans in the order they were added. |
| protected void | doStop()
Overrides org. Stops the managed lifecycle beans in the reverse order they were added. |
| public int | |
| public int | |
| public boolean | |
| public int | |
| public int | |
| public boolean | getReuseAddress()
Returns: whether rebinding the server socket is allowed with sockets in tear-down states |
| public SelectorManager | |
| public Object | getTransport()
Implements org. Get the underlying socket, channel, buffer etc. for the connector.. |
| public boolean | |
| public boolean | isOpen()
Implements org. A Connector may be opened and not started (to reserve a port) or closed and running (to allow graceful shutdown of existing connections) |
| public boolean | isReusePort()
Returns: whether it is allowed to bind multiple server sockets to the same host and port |
| protected SocketChannelEndPoint | |
| protected SelectorManager | |
| public void | open(ServerSocketChannel
the channel to use acceptChannel)Open the connector using the passed ServerSocketChannel. |
| public void | open()
Overrides org. Implements org. Performs the activities needed to open the network communication (for example, to start accepting incoming network connections). |
| protected ServerSocketChannel | Returns: ServerSocketChannel used to accept connections.Called by |
| public void | setAcceptedReceiveBufferSize(int
the receiveBufferSize)SO_RCVBUF size to set onto the accepted socket.
A value of -1 indicates that it is left to its default value.
|
| public void | setAcceptedSendBufferSize(int
the sendBufferSize)SO_SNDBUF size to set onto the accepted socket.
A value of -1 indicates that it is left to its default value.
|
| public void | setAcceptedTcpNoDelay(boolean
whether tcpNoDelay)TCP_NODELAY gets enabled on the the accepted socket.
|
| public void | |
| public void | setAcceptQueueSize(int
the accept queue size (also known as accept backlog) acceptQueueSize)Set the accept queue size (also known as accept backlog). |
| public void | setInheritChannel(boolean
whether this connector uses a channel inherited from the JVM. inheritChannel)Sets whether this connector uses a channel inherited from the JVM. |
| public void | setReuseAddress(boolean
whether rebinding the server socket is allowed with sockets in tear-down states reuseAddress)
|
| public void | setReusePort(boolean
whether it is allowed to bind multiple server sockets to the same host and port reusePort)Set whether it is allowed to bind multiple server sockets to the same host and port. |
| private <T> void |
| _acceptChannel | back to summary |
|---|---|
| private volatile ServerSocketChannel _acceptChannel | |
| _acceptedReceiveBufferSize | back to summary |
|---|---|
| private volatile int _acceptedReceiveBufferSize | |
| _acceptedSendBufferSize | back to summary |
|---|---|
| private volatile int _acceptedSendBufferSize | |
| _acceptedTcpNoDelay | back to summary |
|---|---|
| private volatile boolean _acceptedTcpNoDelay | |
| _acceptor | back to summary |
|---|---|
| private final AtomicReference<Closeable> _acceptor | |
| _acceptQueueSize | back to summary |
|---|---|
| private volatile int _acceptQueueSize | |
| _inheritChannel | back to summary |
|---|---|
| private volatile boolean _inheritChannel | |
| _localPort | back to summary |
|---|---|
| private volatile int _localPort | |
| _manager | back to summary |
|---|---|
| private final SelectorManager _manager | |
| _reuseAddress | back to summary |
|---|---|
| private volatile boolean _reuseAddress | |
| _reusePort | back to summary |
|---|---|
| private volatile boolean _reusePort | |
| ServerConnector | back to summary |
|---|---|
| public ServerConnector(Server server) Construct a ServerConnector with a private instance of | |
| ServerConnector | back to summary |
|---|---|
| public ServerConnector(Server server, int acceptors, int selectors) Construct a ServerConnector with a private instance of
| |
| ServerConnector | back to summary |
|---|---|
| public ServerConnector(Server server, int acceptors, int selectors, ConnectionFactory... factories) Construct a ServerConnector with a private instance of
| |
| ServerConnector | back to summary |
|---|---|
| public ServerConnector(Server server, ConnectionFactory... factories) Construct a Server Connector with the passed Connection factories.
| |
| ServerConnector | back to summary |
|---|---|
| public ServerConnector(Server server, SslContextFactory. Construct a ServerConnector with a private instance of
| |
| ServerConnector | back to summary |
|---|---|
| public ServerConnector(Server server, int acceptors, int selectors, SslContextFactory. Construct a ServerConnector with a private instance of
| |
| ServerConnector | back to summary |
|---|---|
public ServerConnector(Server server, SslContextFactory.
| |
| ServerConnector | back to summary |
|---|---|
public ServerConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, int acceptors, int selectors, ConnectionFactory... factories)
| |
| accept | back to summary |
|---|---|
| public void accept(int acceptorID) throws IOException Implements abstract org.
| |
| accepted | back to summary |
|---|---|
| private void accepted(SocketChannel channel) throws IOException | |
| close | back to summary |
|---|---|
| public void close() Overrides org. Implements org. Doc from org. Performs the activities needed to close the network communication (for example, to stop accepting network connections). Once a connector has been closed, it cannot be opened again without first callingstop() and it will not be active again until a subsequent call to start()
| |
| configure | back to summary |
|---|---|
| protected void configure(Socket socket) | |
| doStart | back to summary |
|---|---|
| protected void doStart() throws Exception Overrides org. Doc from org. Starts the managed lifecycle beans in the order they were added.
| |
| doStop | back to summary |
|---|---|
| protected void doStop() throws Exception Overrides org. Doc from org. Stops the managed lifecycle beans in the reverse order they were added.
| |
| getAcceptedReceiveBufferSize | back to summary |
|---|---|
public int getAcceptedReceiveBufferSize()
| |
| getAcceptedSendBufferSize | back to summary |
|---|---|
public int getAcceptedSendBufferSize()
| |
| getAcceptedTcpNoDelay | back to summary |
|---|---|
public boolean getAcceptedTcpNoDelay()
| |
| getAcceptQueueSize | back to summary |
|---|---|
public int getAcceptQueueSize()
| |
| getLocalPort | back to summary |
|---|---|
| public int getLocalPort() Overrides org. Implements org.
| |
| getReuseAddress | back to summary |
|---|---|
public boolean getReuseAddress()
| |
| getSelectorManager | back to summary |
|---|---|
public SelectorManager getSelectorManager()
| |
| getTransport | back to summary |
|---|---|
| public Object getTransport() Implements org. Doc from org. Get the underlying socket, channel, buffer etc. for the connector.. | |
| isInheritChannel | back to summary |
|---|---|
public boolean isInheritChannel()
| |
| isOpen | back to summary |
|---|---|
| public boolean isOpen() Implements org. Doc from org. A Connector may be opened and not started (to reserve a port) or closed and running (to allow graceful shutdown of existing connections)
| |
| isReusePort | back to summary |
|---|---|
public boolean isReusePort()
| |
| newEndPoint | back to summary |
|---|---|
| protected SocketChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException | |
| newSelectorManager | back to summary |
|---|---|
| protected SelectorManager newSelectorManager(Executor executor, Scheduler scheduler, int selectors) | |
| open | back to summary |
|---|---|
| public void open(ServerSocketChannel acceptChannel) throws IOException Open the connector using the passed ServerSocketChannel.
This open method can be called before starting the connector to pass it a ServerSocketChannel
that will be used instead of one returned from
| |
| open | back to summary |
|---|---|
| public void open() throws IOException Overrides org. Implements org. Doc from org. Performs the activities needed to open the network communication (for example, to start accepting incoming network connections).
| |
| openAcceptChannel | back to summary |
|---|---|
| protected ServerSocketChannel openAcceptChannel() throws IOException Called by
| |
| setAcceptedReceiveBufferSize | back to summary |
|---|---|
public void setAcceptedReceiveBufferSize(int receiveBufferSize)
| |
| setAcceptedSendBufferSize | back to summary |
|---|---|
public void setAcceptedSendBufferSize(int sendBufferSize)
| |
| setAcceptedTcpNoDelay | back to summary |
|---|---|
public void setAcceptedTcpNoDelay(boolean tcpNoDelay)
| |
| setAccepting | back to summary |
|---|---|
| public void setAccepting(boolean accepting) Overrides org.
| |
| setAcceptQueueSize | back to summary |
|---|---|
| public void setAcceptQueueSize(int acceptQueueSize) Set the accept queue size (also known as accept backlog).
| |
| setInheritChannel | back to summary |
|---|---|
| public void setInheritChannel(boolean inheritChannel) Sets whether this connector uses a channel inherited from the JVM. If true, the connector first tries to inherit from a channel provided by the system.
If there is no inherited channel available, or if the inherited channel is not usable,
then it will fall back using Use it with xinetd/inetd, to launch an instance of Jetty on demand. The port used to access pages on the Jetty instance is the same as the port used to launch Jetty.
| |
| setReuseAddress | back to summary |
|---|---|
public void setReuseAddress(boolean reuseAddress)
| |
| setReusePort | back to summary |
|---|---|
| public void setReusePort(boolean reusePort) Set whether it is allowed to bind multiple server sockets to the same host and port.
| |
| setSocketOption | back to summary |
|---|---|
| private <T> void setSocketOption(ServerSocketChannel channel, SocketOption<T> option, T value) | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | accepted(SelectableChannel
the channel)Overrides org. Callback method when a channel is accepted from the |
| protected void | endPointClosed(EndPoint
the endpoint being closed endpoint)Overrides org. Callback method invoked when an endpoint is closed. |
| protected void | endPointOpened(EndPoint
the endpoint being opened endpoint)Overrides org. Callback method invoked when an endpoint is opened. |
| public Connection | newConnection(SelectableChannel
the channel associated to the connection channel, EndPoint the endpoint endpoint, Object the attachment attachment)Implements abstract org. Factory method to create |
| protected SocketChannelEndPoint | newEndPoint(SelectableChannel
the channel associated to the endpoint channel, ManagedSelector the selector the channel is registered to selector, SelectionKey the selection key selectionKey)Implements abstract org. Factory method to create |
| public String | toString()
Overrides org. Returns a string representation of the object. |
| ServerConnectorManager | back to summary |
|---|---|
| public ServerConnectorManager(Executor executor, Scheduler scheduler, int selectors) | |
| accepted | back to summary |
|---|---|
| protected void accepted(SelectableChannel channel) throws IOException Overrides org. Doc from org. Callback method when a channel is accepted from the
| |
| endPointClosed | back to summary |
|---|---|
| protected void endPointClosed(EndPoint endpoint) Overrides org. Doc from org. Callback method invoked when an endpoint is closed. | |
| endPointOpened | back to summary |
|---|---|
| protected void endPointOpened(EndPoint endpoint) Overrides org. Doc from org. Callback method invoked when an endpoint is opened. | |
| newConnection | back to summary |
|---|---|
| public Connection newConnection(SelectableChannel channel, EndPoint endpoint, Object attachment) throws IOException Implements abstract org. Doc from org. Factory method to create
| |
| newEndPoint | back to summary |
|---|---|
| protected SocketChannelEndPoint newEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey selectionKey) throws IOException Implements abstract org. Doc from org. Factory method to create This method is invoked as a result of the registration of a channel via
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |