@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, SPDY 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(Object, Callback)
or
EndPoint.write(Object, 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.
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
LOG
Constructor and Description |
---|
ServerConnector(Server server) |
ServerConnector(Server server,
ConnectionFactory... factories) |
ServerConnector(Server server,
Executor executor,
Scheduler scheduler,
ByteBufferPool pool,
int acceptors,
int selectors,
ConnectionFactory... factories) |
ServerConnector(Server server,
SslContextFactory sslContextFactory) |
ServerConnector(Server server,
SslContextFactory sslContextFactory,
ConnectionFactory... factories) |
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) |
int |
getAcceptQueueSize() |
int |
getLingerTime() |
int |
getLocalPort() |
boolean |
getReuseAddress() |
SelectorManager |
getSelectorManager() |
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,
SelectorManager.ManagedSelector selectSet,
SelectionKey key) |
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 |
setSoLingerTime(int lingerTime) |
<C> Future<C> |
shutdown(C c) |
doStart, doStop, getHost, getPort, isAccepting, setHost, setPort, toString
addConnectionFactory, clearConnectionFactories, getAcceptors, getByteBufferPool, getConnectionFactories, getConnectionFactory, getConnectionFactory, getDefaultConnectionFactory, getDefaultProtocol, getExecutor, getIdleTimeout, getProtocols, getScheduler, getServer, interruptAcceptors, join, join, removeConnectionFactory, setConnectionFactories, setDefaultProtocol, setIdleTimeout
addBean, addBean, addBean, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, setStopTimeout, 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
getByteBufferPool, getConnectionFactories, getConnectionFactory, getConnectionFactory, getDefaultConnectionFactory, getExecutor, getIdleTimeout, getProtocols, getScheduler, getServer
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public ServerConnector(@Name(value="server") Server server, @Name(value="factories") ConnectionFactory... factories)
public ServerConnector(@Name(value="server") Server server, @Name(value="sslContextFactory") SslContextFactory sslContextFactory)
public ServerConnector(@Name(value="server") Server server, @Name(value="sslContextFactory") SslContextFactory sslContextFactory, @Name(value="factories") ConnectionFactory... factories)
public ServerConnector(@Name(value="server") Server server, @Name(value="executor") Executor executor, @Name(value="scheduler") Scheduler scheduler, @Name(value="bufferPool") ByteBufferPool pool, @Name(value="acceptors") int acceptors, @Name(value="selectors") int selectors, @Name(value="factories") 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 use the servers schedulerpool
- A buffer pool for this connector or null to use a default ByteBufferPool
acceptors
- the number of acceptor threads to use, or 0 for a default value.factories
- Zero or more ConnectionFactory
instances.public boolean isOpen()
NetworkConnector
public 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 <C> Future<C> shutdown(C c)
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 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()
public int getLocalPort()
getLocalPort
in interface NetworkConnector
getLocalPort
in class AbstractNetworkConnector
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.ManagedSelector selectSet, SelectionKey key) throws IOException
IOException
public int getLingerTime()
Socket.getSoLinger()
public void setSoLingerTime(int lingerTime)
lingerTime
- the linger time. Use -1 to disable.Socket.setSoLinger(boolean, int)
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-2012 Mort Bay Consulting. All Rights Reserved.