Class ServerConnector
- java.lang.Object
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Connector
,NetworkConnector
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,Graceful
,LifeCycle
- Direct Known Subclasses:
NetworkTrafficServerConnector
@ManagedObject("HTTP connector using NIO ByteChannels and Selectors") @Deprecated(since="2021-05-27") public class ServerConnector extends AbstractNetworkConnector
Deprecated.The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.ThisConnector
implementation is the primary connector for the Jetty server over TCP/IP. By the use of variousConnectionFactory
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 passedServer
instance, but all services may also be constructor injected into the connector so that it may operate with dedicated or otherwise shared services.Connection Factories
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 aHttpConnectionFactory
. If an non nullSslContextFactory
instance is passed, then this used to instantiate aSslConnectionFactory
which is prepended to the other passed or default factories.Selectors
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Graceful
Graceful.Shutdown
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Constructor Summary
Constructors Constructor Description ServerConnector(Server server)
Deprecated.Construct a ServerConnector with a private instance ofHttpConnectionFactory
as the only factory.ServerConnector(Server server, int acceptors, int selectors)
Deprecated.Construct a ServerConnector with a private instance ofHttpConnectionFactory
as the only factory.ServerConnector(Server server, int acceptors, int selectors, ConnectionFactory... factories)
Deprecated.Construct a ServerConnector with a private instance ofHttpConnectionFactory
as the only factory.ServerConnector(Server server, int acceptors, int selectors, SslContextFactory sslContextFactory)
Deprecated.Construct a ServerConnector with a private instance ofHttpConnectionFactory
as the primary protocolServerConnector(Server server, java.util.concurrent.Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, int acceptors, int selectors, ConnectionFactory... factories)
Deprecated.ServerConnector(Server server, ConnectionFactory... factories)
Deprecated.Construct a Server Connector with the passed Connection factories.ServerConnector(Server server, SslContextFactory sslContextFactory)
Deprecated.Construct a ServerConnector with a private instance ofHttpConnectionFactory
as the primary protocolServerConnector(Server server, SslContextFactory sslContextFactory, ConnectionFactory... factories)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
accept(int acceptorID)
Deprecated.void
close()
Deprecated.Performs the activities needed to close the network communication (for example, to stop accepting network connections).int
getAcceptedReceiveBufferSize()
Deprecated.int
getAcceptedSendBufferSize()
Deprecated.boolean
getAcceptedTcpNoDelay()
Deprecated.int
getAcceptQueueSize()
Deprecated.int
getLocalPort()
Deprecated.boolean
getReuseAddress()
Deprecated.SelectorManager
getSelectorManager()
Deprecated.int
getSoLingerTime()
Deprecated.don't use as socket close linger time has undefined behavior for non-blocking socketsjava.lang.Object
getTransport()
Deprecated.boolean
isInheritChannel()
Deprecated.boolean
isOpen()
Deprecated.A Connector may be opened and not started (to reserve a port) or closed and running (to allow graceful shutdown of existing connections)void
open()
Deprecated.Performs the activities needed to open the network communication (for example, to start accepting incoming network connections).void
open(java.nio.channels.ServerSocketChannel acceptChannel)
Deprecated.Open the connector using the passed ServerSocketChannel.void
setAcceptedReceiveBufferSize(int receiveBufferSize)
Deprecated.void
setAcceptedSendBufferSize(int sendBufferSize)
Deprecated.void
setAcceptedTcpNoDelay(boolean tcpNoDelay)
Deprecated.void
setAccepting(boolean accepting)
Deprecated.void
setAcceptQueueSize(int acceptQueueSize)
Deprecated.void
setInheritChannel(boolean inheritChannel)
Deprecated.Sets whether this connector uses a channel inherited from the JVM.void
setReuseAddress(boolean reuseAddress)
Deprecated.void
setSoLingerTime(int lingerTime)
Deprecated.don't use as socket close linger time has undefined behavior for non-blocking sockets-
Methods inherited from class org.eclipse.jetty.server.AbstractNetworkConnector
getHost, getPort, setHost, setPort, shutdown, toString
-
Methods inherited from class org.eclipse.jetty.server.AbstractConnector
addConnectionFactory, addFirstConnectionFactory, addIfAbsentConnectionFactory, clearConnectionFactories, getAcceptorPriorityDelta, getAcceptors, getByteBufferPool, getConnectedEndPoints, getConnectionFactories, getConnectionFactory, getConnectionFactory, getDefaultConnectionFactory, getDefaultProtocol, getExecutor, getHttpChannelListeners, getIdleTimeout, getName, getProtocols, getScheduler, getServer, isAccepting, isShutdown, join, join, removeConnectionFactory, setAcceptorPriorityDelta, setConnectionFactories, setDefaultProtocol, setIdleTimeout, setName
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.server.Connector
getByteBufferPool, getConnectedEndPoints, getConnectionFactories, getConnectionFactory, getConnectionFactory, getDefaultConnectionFactory, getExecutor, getIdleTimeout, getName, getProtocols, getScheduler, getServer
-
Methods inherited from interface org.eclipse.jetty.util.component.Container
addBean, addBean, addEventListener, getBean, getBeans, getBeans, getContainedBeans, isManaged, manage, removeBean, removeEventListener, unmanage
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Methods inherited from interface org.eclipse.jetty.util.component.Graceful
isShutdown
-
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Constructor Detail
-
ServerConnector
public ServerConnector(@Name("server") Server server)
Deprecated.Construct a ServerConnector with a private instance of
HttpConnectionFactory
as the only factory.- Parameters:
server
- TheServer
this connector will accept connection for.
-
ServerConnector
public ServerConnector(@Name("server") Server server, @Name("acceptors") int acceptors, @Name("selectors") int selectors)
Deprecated.Construct a ServerConnector with a private instance of
HttpConnectionFactory
as the only factory.- Parameters:
server
- TheServer
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.
-
ServerConnector
public ServerConnector(@Name("server") Server server, @Name("acceptors") int acceptors, @Name("selectors") int selectors, @Name("factories") ConnectionFactory... factories)
Deprecated.Construct a ServerConnector with a private instance of
HttpConnectionFactory
as the only factory.- Parameters:
server
- TheServer
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 moreConnectionFactory
instances used to create and configure connections.
-
ServerConnector
public ServerConnector(@Name("server") Server server, @Name("factories") ConnectionFactory... factories)
Deprecated.Construct a Server Connector with the passed Connection factories.
- Parameters:
server
- TheServer
this connector will accept connection for.factories
- Zero or moreConnectionFactory
instances used to create and configure connections.
-
ServerConnector
public ServerConnector(@Name("server") Server server, @Name("sslContextFactory") SslContextFactory sslContextFactory)
Deprecated.Construct a ServerConnector with a private instance of
.HttpConnectionFactory
as the primary protocol- Parameters:
server
- TheServer
this connector will accept connection for.sslContextFactory
- If non null, then aSslConnectionFactory
is instantiated and prepended to the list of HTTP Connection Factory.
-
ServerConnector
public ServerConnector(@Name("server") Server server, @Name("acceptors") int acceptors, @Name("selectors") int selectors, @Name("sslContextFactory") SslContextFactory sslContextFactory)
Deprecated.Construct a ServerConnector with a private instance of
.HttpConnectionFactory
as the primary protocol- Parameters:
server
- TheServer
this connector will accept connection for.sslContextFactory
- If non null, then aSslConnectionFactory
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.
-
ServerConnector
public ServerConnector(@Name("server") Server server, @Name("sslContextFactory") SslContextFactory sslContextFactory, @Name("factories") ConnectionFactory... factories)
Deprecated.- Parameters:
server
- TheServer
this connector will accept connection for.sslContextFactory
- If non null, then aSslConnectionFactory
is instantiated and prepended to the list of ConnectionFactories, with the first factory being the default protocol for the SslConnectionFactory.factories
- Zero or moreConnectionFactory
instances used to create and configure connections.
-
ServerConnector
public ServerConnector(@Name("server") Server server, @Name("executor") java.util.concurrent.Executor executor, @Name("scheduler") Scheduler scheduler, @Name("bufferPool") ByteBufferPool bufferPool, @Name("acceptors") int acceptors, @Name("selectors") int selectors, @Name("factories") ConnectionFactory... factories)
Deprecated.- Parameters:
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 moreConnectionFactory
instances used to create and configure connections.
-
-
Method Detail
-
isOpen
public boolean isOpen()
Deprecated.Description copied from interface:NetworkConnector
A Connector may be opened and not started (to reserve a port) or closed and running (to allow graceful shutdown of existing connections)- Returns:
- True if the connector is Open.
-
isInheritChannel
public boolean isInheritChannel()
Deprecated.- Returns:
- whether this connector uses a channel inherited from the JVM.
- See Also:
System.inheritedChannel()
-
setInheritChannel
public void setInheritChannel(boolean inheritChannel)
Deprecated.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.
- Parameters:
inheritChannel
- whether this connector uses a channel inherited from the JVM.- See Also:
openAcceptChannel()
-
open
public void open(java.nio.channels.ServerSocketChannel acceptChannel) throws java.io.IOException
Deprecated.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 fromopenAcceptChannel()
- Parameters:
acceptChannel
- the channel to use- Throws:
java.io.IOException
- if the server channel is not bound
-
open
public void open() throws java.io.IOException
Deprecated.Description copied from interface:NetworkConnector
Performs the activities needed to open the network communication (for example, to start accepting incoming network connections).
- Specified by:
open
in interfaceNetworkConnector
- Overrides:
open
in classAbstractNetworkConnector
- Throws:
java.io.IOException
- if this connector cannot be opened- See Also:
NetworkConnector.close()
-
close
public void close()
Deprecated.Description copied from interface: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 toLifeCycle.start()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceNetworkConnector
- Overrides:
close
in classAbstractNetworkConnector
-
accept
public void accept(int acceptorID) throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
getSelectorManager
@ManagedAttribute("The Selector Manager") public SelectorManager getSelectorManager()
Deprecated.
-
getTransport
public java.lang.Object getTransport()
Deprecated.- Returns:
- the underlying socket, channel, buffer etc. for the connector.
-
getLocalPort
@ManagedAttribute("local port") public int getLocalPort()
Deprecated.- Specified by:
getLocalPort
in interfaceNetworkConnector
- Overrides:
getLocalPort
in classAbstractNetworkConnector
- Returns:
- The actual port the connector is listening on, or -1 if it has not been opened, or -2 if it has been closed.
-
getSoLingerTime
@ManagedAttribute(value="Socket close linger time. Deprecated, always returns -1", readonly=true) @Deprecated public int getSoLingerTime()
Deprecated.don't use as socket close linger time has undefined behavior for non-blocking socketsReturns the socket close linger time.- Returns:
- -1 as the socket close linger time is always disabled.
- See Also:
StandardSocketOptions.SO_LINGER
-
setSoLingerTime
@Deprecated public void setSoLingerTime(int lingerTime)
Deprecated.don't use as socket close linger time has undefined behavior for non-blocking sockets- Parameters:
lingerTime
- the socket close linger time; use -1 to disable.- See Also:
StandardSocketOptions.SO_LINGER
-
getAcceptQueueSize
@ManagedAttribute("Accept Queue size") public int getAcceptQueueSize()
Deprecated.- Returns:
- the accept queue size
-
setAcceptQueueSize
public void setAcceptQueueSize(int acceptQueueSize)
Deprecated.- Parameters:
acceptQueueSize
- the accept queue size (also known as accept backlog)
-
getReuseAddress
@ManagedAttribute("Server Socket SO_REUSEADDR") public boolean getReuseAddress()
Deprecated.- Returns:
- whether the server socket reuses addresses
- See Also:
ServerSocket.getReuseAddress()
-
setReuseAddress
public void setReuseAddress(boolean reuseAddress)
Deprecated.- Parameters:
reuseAddress
- whether the server socket reuses addresses- See Also:
ServerSocket.setReuseAddress(boolean)
-
getAcceptedTcpNoDelay
@ManagedAttribute("Accepted Socket TCP_NODELAY") public boolean getAcceptedTcpNoDelay()
Deprecated.- Returns:
- whether the accepted socket gets
TCP_NODELAY
enabled. - See Also:
Socket.getTcpNoDelay()
-
setAcceptedTcpNoDelay
public void setAcceptedTcpNoDelay(boolean tcpNoDelay)
Deprecated.- Parameters:
tcpNoDelay
- whetherTCP_NODELAY
gets enabled on the the accepted socket.- See Also:
Socket.setTcpNoDelay(boolean)
-
getAcceptedReceiveBufferSize
@ManagedAttribute("Accepted Socket SO_RCVBUF") public int getAcceptedReceiveBufferSize()
Deprecated.- Returns:
- the
SO_RCVBUF
size to set onto the accepted socket. A value of -1 indicates that it is left to its default value. - See Also:
Socket.getReceiveBufferSize()
-
setAcceptedReceiveBufferSize
public void setAcceptedReceiveBufferSize(int receiveBufferSize)
Deprecated.- Parameters:
receiveBufferSize
- theSO_RCVBUF
size to set onto the accepted socket. A value of -1 indicates that it is left to its default value.- See Also:
Socket.setReceiveBufferSize(int)
-
getAcceptedSendBufferSize
@ManagedAttribute("Accepted Socket SO_SNDBUF") public int getAcceptedSendBufferSize()
Deprecated.- Returns:
- the
SO_SNDBUF
size to set onto the accepted socket. A value of -1 indicates that it is left to its default value. - See Also:
Socket.getSendBufferSize()
-
setAcceptedSendBufferSize
public void setAcceptedSendBufferSize(int sendBufferSize)
Deprecated.- Parameters:
sendBufferSize
- theSO_SNDBUF
size to set onto the accepted socket. A value of -1 indicates that it is left to its default value.- See Also:
Socket.setSendBufferSize(int)
-
setAccepting
public void setAccepting(boolean accepting)
Deprecated.- Overrides:
setAccepting
in classAbstractConnector
-
-