@ManagedObject(value="HTTP connector using NIO ByteChannels and Selectors") public class ServerConnector extends AbstractNetworkConnector
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.
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.
Executor
service to execute a number of Selector Tasks,
which are implemented to each use a NIO Selector
instance to asynchronously
schedule a set of accepted connections. It is the selector thread that will call the
Callback
instances passed in the EndPoint.fillInterested(Callback)
or
EndPoint.write(Callback, java.nio.ByteBuffer...)
methods. It is expected
that these callbacks may do some non-blocking IO work, but will always dispatch to the
Executor
service any blocking, long running or application tasks.
The default number of selectors is equal to 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 |
ServerConnector.ServerConnectorManager |
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
LOG
Constructor and Description |
---|
ServerConnector(Server server)
HTTP Server Connection.
|
ServerConnector(Server server,
ConnectionFactory... factories)
Generic Server Connection with default configuration.
|
ServerConnector(Server server,
Executor executor,
Scheduler scheduler,
ByteBufferPool bufferPool,
int acceptors,
int selectors,
ConnectionFactory... factories)
Generic Server Connection.
|
ServerConnector(Server server,
int acceptors,
int selectors)
HTTP Server Connection.
|
ServerConnector(Server server,
int acceptors,
int selectors,
ConnectionFactory... factories)
HTTP Server Connection.
|
ServerConnector(Server server,
int acceptors,
int selectors,
SslContextFactory sslContextFactory)
HTTP Server Connection.
|
ServerConnector(Server server,
SslContextFactory sslContextFactory)
HTTP Server Connection.
|
ServerConnector(Server server,
SslContextFactory sslContextFactory,
ConnectionFactory... factories)
Generic SSL Server Connection.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(int acceptorID) |
void |
close()
Performs the activities needed to close the network communication
(for example, to stop accepting network connections).
|
protected void |
configure(Socket socket) |
protected void |
doStart() |
int |
getAcceptQueueSize() |
int |
getLocalPort() |
boolean |
getReuseAddress() |
SelectorManager |
getSelectorManager() |
int |
getSelectorPriorityDelta()
Deprecated.
not implemented
|
int |
getSoLingerTime() |
Object |
getTransport() |
boolean |
isInheritChannel() |
boolean |
isOpen()
A Connector may be opened and not started (to reserve a port)
or closed and running (to allow graceful shutdown of existing connections)
|
protected SelectChannelEndPoint |
newEndPoint(SocketChannel channel,
ManagedSelector selectSet,
SelectionKey key) |
protected SelectorManager |
newSelectorManager(Executor executor,
Scheduler scheduler,
int selectors) |
void |
open()
Performs the activities needed to open the network communication
(for example, to start accepting incoming network connections).
|
void |
setAcceptQueueSize(int acceptQueueSize) |
void |
setInheritChannel(boolean inheritChannel)
Sets whether this connector uses a channel inherited from the JVM.
|
void |
setReuseAddress(boolean reuseAddress) |
void |
setSelectorPriorityDelta(int selectorPriorityDelta)
Deprecated.
not implemented
|
void |
setSoLingerTime(int lingerTime) |
Future<Void> |
shutdown() |
doStop, getHost, getPort, isAccepting, setHost, setPort, toString
addConnectionFactory, addFirstConnectionFactory, addIfAbsentConnectionFactory, clearConnectionFactories, getAcceptorPriorityDelta, getAcceptors, getByteBufferPool, getConnectedEndPoints, getConnectionFactories, getConnectionFactory, getConnectionFactory, getDefaultConnectionFactory, getDefaultProtocol, getExecutor, getIdleTimeout, getName, getProtocols, getScheduler, getServer, interruptAcceptors, join, join, onEndPointClosed, onEndPointOpened, removeConnectionFactory, setAcceptorPriorityDelta, setConnectionFactories, setDefaultProtocol, setIdleTimeout, setName
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, 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
getByteBufferPool, getConnectedEndPoints, getConnectionFactories, getConnectionFactory, getConnectionFactory, getDefaultConnectionFactory, getExecutor, getIdleTimeout, getName, getProtocols, getScheduler, getServer
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public ServerConnector(@Name(value="server") Server server)
Construct a ServerConnector with a private instance of HttpConnectionFactory
as the only factory.
server
- The Server
this connector will accept connection for.public ServerConnector(@Name(value="server") Server server, @Name(value="acceptors") int acceptors, @Name(value="selectors") int selectors)
Construct a ServerConnector with a private instance of HttpConnectionFactory
as the only factory.
server
- The Server
this connector will accept connection for.acceptors
- 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.selectors
- the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress.public ServerConnector(@Name(value="server") Server server, @Name(value="acceptors") int acceptors, @Name(value="selectors") int selectors, @Name(value="factories") ConnectionFactory... factories)
Construct a ServerConnector with a private instance of HttpConnectionFactory
as the only factory.
server
- The Server
this connector will accept connection for.acceptors
- 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.selectors
- the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress.factories
- Zero or more ConnectionFactory
instances used to create and configure connections.public ServerConnector(@Name(value="server") Server server, @Name(value="factories") ConnectionFactory... factories)
Construct a Server Connector with the passed Connection factories.
server
- The Server
this connector will accept connection for.factories
- Zero or more ConnectionFactory
instances used to create and configure connections.public ServerConnector(@Name(value="server") Server server, @Name(value="sslContextFactory") SslContextFactory sslContextFactory)
Construct a ServerConnector with a private instance of HttpConnectionFactory
as the primary protocol
server
- The Server
this connector will accept connection for.sslContextFactory
- If non null, then a SslConnectionFactory
is instantiated and prepended to the
list of HTTP Connection Factory.public ServerConnector(@Name(value="server") Server server, @Name(value="acceptors") int acceptors, @Name(value="selectors") int selectors, @Name(value="sslContextFactory") SslContextFactory sslContextFactory)
Construct a ServerConnector with a private instance of HttpConnectionFactory
as the primary protocol
server
- The Server
this connector will accept connection for.sslContextFactory
- If non null, then a SslConnectionFactory
is instantiated and prepended to the
list of HTTP Connection Factory.acceptors
- 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.selectors
- the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress.public ServerConnector(@Name(value="server") Server server, @Name(value="sslContextFactory") SslContextFactory sslContextFactory, @Name(value="factories") ConnectionFactory... factories)
server
- The Server
this connector will accept connection for.sslContextFactory
- If non null, then a SslConnectionFactory
is instantiated and prepended to the
list of ConnectionFactories, with the first factory being the default protocol for the SslConnectionFactory.factories
- Zero or more ConnectionFactory
instances used to create and configure connections.public ServerConnector(@Name(value="server") Server server, @Name(value="executor") Executor executor, @Name(value="scheduler") Scheduler scheduler, @Name(value="bufferPool") ByteBufferPool bufferPool, @Name(value="acceptors") int acceptors, @Name(value="selectors") int selectors, @Name(value="factories") ConnectionFactory... factories)
server
- The server this connector will be accept connection for.executor
- An executor used to run tasks for handling requests, acceptors and selectors.
If null then use the servers executorscheduler
- A scheduler used to schedule timeouts. If null then use the servers schedulerbufferPool
- A ByteBuffer pool used to allocate buffers. If null then create a private pool with default configuration.acceptors
- 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.selectors
- the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress.factories
- Zero or more ConnectionFactory
instances used to create and configure connections.protected SelectorManager newSelectorManager(Executor executor, Scheduler scheduler, int selectors)
protected void doStart() throws Exception
doStart
in class AbstractNetworkConnector
Exception
public boolean isOpen()
NetworkConnector
@Deprecated public int getSelectorPriorityDelta()
@Deprecated public void setSelectorPriorityDelta(int selectorPriorityDelta)
selectorPriorityDelta
- the selector priority deltapublic boolean isInheritChannel()
System.inheritedChannel()
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 ServerSocketChannel
.
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.
inheritChannel
- whether this connector uses a channel inherited from the JVM.public void open() throws IOException
NetworkConnector
Performs the activities needed to open the network communication (for example, to start accepting incoming network connections).
open
in interface NetworkConnector
open
in class AbstractNetworkConnector
IOException
- if this connector cannot be openedNetworkConnector.close()
public Future<Void> shutdown()
shutdown
in interface Graceful
shutdown
in class AbstractNetworkConnector
public void close()
NetworkConnector
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 callingLifeCycle.stop()
and it will not be active again until a subsequent call to LifeCycle.start()
close
in interface Closeable
close
in interface AutoCloseable
close
in interface NetworkConnector
close
in class AbstractNetworkConnector
public void accept(int acceptorID) throws IOException
accept
in class AbstractConnector
IOException
protected void configure(Socket socket)
public SelectorManager getSelectorManager()
public Object getTransport()
@ManagedAttribute(value="local port") public int getLocalPort()
getLocalPort
in interface NetworkConnector
getLocalPort
in class AbstractNetworkConnector
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException
IOException
@ManagedAttribute(value="TCP/IP solinger time or -1 to disable") public int getSoLingerTime()
Socket.getSoLinger()
public void setSoLingerTime(int lingerTime)
lingerTime
- the linger time. Use -1 to disable.Socket.setSoLinger(boolean, int)
@ManagedAttribute(value="Accept Queue size") public int getAcceptQueueSize()
public void setAcceptQueueSize(int acceptQueueSize)
acceptQueueSize
- the accept queue size (also known as accept backlog)public boolean getReuseAddress()
ServerSocket.getReuseAddress()
public void setReuseAddress(boolean reuseAddress)
reuseAddress
- whether the server socket reuses addressesServerSocket.setReuseAddress(boolean)
Copyright © 1995-2015 Webtide. All Rights Reserved.