Class ClientConnector
- All Implemented Interfaces:
Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
The client-side component that connects to server sockets.
ClientConnector delegates the handling of SocketChannel
s
to a SelectorManager
, and centralizes the configuration of
necessary components such as the executor, the scheduler, etc.
ClientConnector offers a low-level API that can be used to
connect SocketChannel
s to listening servers via the
connect(SocketAddress, Map)
method.
However, a ClientConnector instance is typically just configured and then passed to an HttpClient transport, so that applications can use high-level APIs to make HTTP requests to servers:
// Create a ClientConnector instance. ClientConnector connector = new ClientConnector(); // Configure the ClientConnector. connector.setSelectors(1); connector.setSslContextFactory(new SslContextFactory.Client()); // Pass it to the HttpClient transport. HttpClientTransport transport = new HttpClientTransportDynamic(connector); HttpClient httpClient = new HttpClient(transport); httpClient.start();
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
static class
Deprecated, for removal: This API element is subject to removal in a future version.Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
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.LifeCycle
LifeCycle.Listener
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
-
Constructor Summary
ConstructorDescriptionClientConnector
(ClientConnector.Configurator configurator) Deprecated, for removal: This API element is subject to removal in a future version.replaced byTransport
-
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(SelectableChannel selectable, Map<String, Object> context) protected void
acceptFailed
(Throwable failure, SelectableChannel channel, Map<String, Object> context) protected void
configure
(SelectableChannel selectable) void
connect
(SocketAddress address, Map<String, Object> context) protected void
connectFailed
(Throwable failure, Map<String, Object> context) protected void
doStart()
Starts the managed lifecycle beans in the order they were added.protected void
doStop()
Stops the managed lifecycle beans in the reverse order they were added.static ClientConnector
forUnixDomain
(Path path) Deprecated, for removal: This API element is subject to removal in a future version.replaced byTransport.TCPUnix
int
boolean
int
int
boolean
boolean
isIntrinsicallySecure
(SocketAddress address) Deprecated, for removal: This API element is subject to removal in a future version.replaced byTransport.isIntrinsicallySecure()
boolean
boolean
protected Connection
newConnection
(EndPoint endPoint, Map<String, Object> context) protected EndPoint
newEndPoint
(SelectableChannel selectable, ManagedSelector selector, SelectionKey selectionKey) protected SelectorManager
protected SslContextFactory.Client
Deprecated, for removal: This API element is subject to removal in a future version.useTransport
insteadvoid
setBindAddress
(SocketAddress bindAddress) Sets the bind address of sockets before the connect operation.void
setByteBufferPool
(ByteBufferPool byteBufferPool) void
setConnectBlocking
(boolean connectBlocking) void
setConnectTimeout
(Duration connectTimeout) void
setExecutor
(Executor executor) void
setIdleTimeout
(Duration idleTimeout) void
setReceiveBufferSize
(int receiveBufferSize) void
setReuseAddress
(boolean reuseAddress) Sets whether it is allowed to bind a socket to a socket address that may be in use by another socket in tear-down state, for example in TIME_WAIT state.void
setReusePort
(boolean reusePort) Sets whether it is allowed to bind multiple sockets to the same socket address (same host and same port).void
setScheduler
(Scheduler scheduler) void
setSelectors
(int selectors) void
setSendBufferSize
(int sendBufferSize) void
setSslContextFactory
(SslContextFactory.Client sslContextFactory) void
setTCPNoDelay
(boolean tcpNoDelay) Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Field Details
-
CLIENT_CONNECTOR_CONTEXT_KEY
- See Also:
-
REMOTE_SOCKET_ADDRESS_CONTEXT_KEY
- See Also:
-
CLIENT_CONNECTION_FACTORY_CONTEXT_KEY
- See Also:
-
CONNECTION_PROMISE_CONTEXT_KEY
- See Also:
-
APPLICATION_PROTOCOLS_CONTEXT_KEY
- See Also:
-
-
Constructor Details
-
ClientConnector
public ClientConnector() -
ClientConnector
@Deprecated(since="12.0.7", forRemoval=true) public ClientConnector(ClientConnector.Configurator configurator) Deprecated, for removal: This API element is subject to removal in a future version.replaced byTransport
- Parameters:
configurator
- theClientConnector.Configurator
-
-
Method Details
-
forUnixDomain
Deprecated, for removal: This API element is subject to removal in a future version.replaced byTransport.TCPUnix
Creates a ClientConnector configured to connect via Unix-Domain sockets to the given Unix-Domain path
- Parameters:
path
- the Unix-Domain path to connect to- Returns:
- a ClientConnector that connects to the given Unix-Domain path
-
isIntrinsicallySecure
@Deprecated(since="12.0.7", forRemoval=true) public boolean isIntrinsicallySecure(SocketAddress address) Deprecated, for removal: This API element is subject to removal in a future version.replaced byTransport.isIntrinsicallySecure()
- Parameters:
address
- the SocketAddress to connect to- Returns:
- whether the connection to the given SocketAddress is intrinsically secure
- See Also:
-
getSelectorManager
-
getExecutor
-
newTransport
Deprecated, for removal: This API element is subject to removal in a future version.useTransport
insteadReturns the default
Transport
for this connector.This method only exists for backwards compatibility, when
ClientConnector.Configurator
was used, and should be removed whenClientConnector.Configurator
is removed.- Returns:
- the default
Transport
for this connector
-
setExecutor
-
getScheduler
-
setScheduler
-
getByteBufferPool
-
setByteBufferPool
-
getSslContextFactory
-
setSslContextFactory
-
getSelectors
- Returns:
- the number of NIO selectors
-
setSelectors
public void setSelectors(int selectors) -
isConnectBlocking
@ManagedAttribute("Whether connect operations are performed in blocking mode") public boolean isConnectBlocking()- Returns:
- whether
connect(SocketAddress, Map)
operations are performed in blocking mode
-
setConnectBlocking
public void setConnectBlocking(boolean connectBlocking) -
getConnectTimeout
- Returns:
- the timeout of
connect(SocketAddress, Map)
operations
-
setConnectTimeout
-
getIdleTimeout
@ManagedAttribute("The duration for which a connection can be idle") public Duration getIdleTimeout()- Returns:
- the max duration for which a connection can be idle (that is, without traffic of bytes in either direction)
-
setIdleTimeout
-
getBindAddress
@ManagedAttribute("The socket address to bind sockets to before the connect operation") public SocketAddress getBindAddress()- Returns:
- the address to bind a socket to before the connect operation
-
setBindAddress
Sets the bind address of sockets before the connect operation.
In multi-homed hosts, you may want to connect from a specific address:
clientConnector.setBindAddress(new InetSocketAddress("127.0.0.2", 0));
Note the use of the port
0
to indicate that a different ephemeral port should be used for each different connection.In the rare cases where you want to use the same port for all connections, you must also call
setReusePort(true)
.- Parameters:
bindAddress
- the socket address to bind to before the connect operation
-
isTCPNoDelay
- Returns:
- whether small TCP packets are sent without delay
-
setTCPNoDelay
public void setTCPNoDelay(boolean tcpNoDelay) -
getReuseAddress
@ManagedAttribute("Whether rebinding is allowed with sockets in tear-down states") public boolean getReuseAddress()- Returns:
- whether rebinding is allowed with sockets in tear-down states
-
setReuseAddress
public void setReuseAddress(boolean reuseAddress) Sets whether it is allowed to bind a socket to a socket address that may be in use by another socket in tear-down state, for example in TIME_WAIT state.
This is useful when ClientConnector is restarted: an existing connection may still be using a network address (same host and same port) that is also chosen for a new connection.
- Parameters:
reuseAddress
- whether rebinding is allowed with sockets in tear-down states- See Also:
-
isReusePort
- Returns:
- whether binding to same host and port is allowed
-
setReusePort
public void setReusePort(boolean reusePort) Sets whether it is allowed to bind multiple sockets to the same socket address (same host and same port).
- Parameters:
reusePort
- whether binding to same host and port is allowed
-
getReceiveBufferSize
- Returns:
- the receive buffer size in bytes, or -1 for the default value
-
setReceiveBufferSize
public void setReceiveBufferSize(int receiveBufferSize) -
getSendBufferSize
- Returns:
- the send buffer size in bytes, or -1 for the default value
-
setSendBufferSize
public void setSendBufferSize(int sendBufferSize) -
doStart
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:ContainerLifeCycle
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in classContainerLifeCycle
- Throws:
Exception
- If there was a problem stopping. Will cause a transition to FAILED state
-
newSslContextFactory
-
newSelectorManager
-
connect
-
accept
-
configure
- Throws:
IOException
-
newEndPoint
protected EndPoint newEndPoint(SelectableChannel selectable, ManagedSelector selector, SelectionKey selectionKey) -
newConnection
protected Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException- Throws:
IOException
-
acceptFailed
protected void acceptFailed(Throwable failure, SelectableChannel channel, Map<String, Object> context) -
connectFailed
-
Transport