Top Description Inners Fields Constructors Methods
org.eclipse.jetty.io

public Class ClientConnector

extends ContainerLifeCycle
Class Inheritance
Annotations
@ManagedObject
Imports
java.io.IOException, java.net.InetSocketAddress, .ProtocolFamily, .SocketAddress, .SocketException, .SocketOption, .StandardProtocolFamily, .StandardSocketOptions, java.nio.channels.NetworkChannel, .SelectableChannel, .SelectionKey, .SocketChannel, java.nio.file.Path, java.time.Duration, java.util.Map, .Objects, java.util.concurrent.ConcurrentHashMap, .Executor, org.eclipse.jetty.util.IO, .JavaVersion, .Promise, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.component.ContainerLifeCycle, org.eclipse.jetty.util.ssl.SslContextFactory, org.eclipse.jetty.util.thread.QueuedThreadPool, .ScheduledExecutorScheduler, .Scheduler, org.slf4j.Logger, .LoggerFactory

The client-side component that connects to server sockets.

ClientConnector delegates the handling of SocketChannels 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 SocketChannels 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 and Inner Type Summary

Modifier and TypeClass and Description
protected class
public static class

Field Summary

Modifier and TypeField and Description
public static final String
private SocketAddress
private ByteBufferPool
public static final String
public static final String
private final ClientConnector.Configurator
private boolean
public static final String
private Duration
private Executor
private Duration
private static final Logger
private int
public static final String
private boolean
private boolean
private Scheduler
private SelectorManager
private int
private int
private SslContextFactory.Client
private boolean

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
accept(SelectableChannel selectable, Map<String, Object> context)

private void
bind(NetworkChannel channel, SocketAddress bindAddress)

protected void
public void
connect(SocketAddress address, Map<String, Object> context)

protected void
connectFailed(Throwable failure, Map<String, Object> context)

protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

protected void
doStop()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

public static ClientConnector

Returns:

a ClientConnector that connects to the given Unix-Domain path
forUnixDomain
(Path
the Unix-Domain path to connect to
path
)

Creates a ClientConnector configured to connect via Unix-Domain sockets to the given Unix-Domain path

public SocketAddress
getBindAddress()

Returns: the address to bind a socket to before the connect operation

public ByteBufferPool
public Duration
getConnectTimeout()

Returns: the timeout of connect(SocketAddress, Map) operations

public Executor
public Duration
getIdleTimeout()

Returns: the max duration for which a connection can be idle (that is, without traffic of bytes in either direction)

public int
getReceiveBufferSize()

Returns: the receive buffer size in bytes, or -1 for the default value

public boolean
getReuseAddress()

Returns: whether rebinding is allowed with sockets in tear-down states

public Scheduler
public int
getSelectors()

Returns: the number of NIO selectors

public int
getSendBufferSize()

Returns: the send buffer size in bytes, or -1 for the default value

public SslContextFactory.Client
public boolean
isConnectBlocking()

Returns: whether connect(SocketAddress, Map) operations are performed in blocking mode

public boolean
isIntrinsicallySecure(SocketAddress
the SocketAddress to connect to
address
)

Returns: whether the connection to the given SocketAddress is intrinsically secure

public boolean
isReusePort()

Returns: whether binding to same host and port is allowed

public boolean
isTCPNoDelay()

Returns: whether small TCP packets are sent without delay

protected Connection
newConnection(EndPoint endPoint, Map<String, Object> context)

protected EndPoint
newEndPoint(SelectableChannel selectable, ManagedSelector selector, SelectionKey selectionKey)

protected SelectorManager
protected SslContextFactory.Client
public void
setBindAddress(SocketAddress
the socket address to bind to before the connect operation
bindAddress
)

Sets the bind address of sockets before the connect operation.

public void
public void
setConnectBlocking(boolean connectBlocking)

public void
setConnectTimeout(Duration connectTimeout)

public void
public void
setIdleTimeout(Duration idleTimeout)

public void
setReceiveBufferSize(int receiveBufferSize)

public void
setReuseAddress(boolean
whether rebinding is allowed with sockets in tear-down states
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.

public void
setReusePort(boolean
whether binding to same host and port is allowed
reusePort
)

Sets whether it is allowed to bind multiple sockets to the same socket address (same host and same port).

public void
public void
setSelectors(int selectors)

public void
setSendBufferSize(int sendBufferSize)

private <T> void
setSocketOption(NetworkChannel channel, SocketOption<T> option, T value)

public void
public void
setTCPNoDelay(boolean tcpNoDelay)

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydumpdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans