Top Description Fields Constructors Methods
io.vertx.core.net.impl

public Class NetClientImpl

extends Object
implements MetricsProvider, NetClient, Closeable
Class Inheritance
All Implemented Interfaces
io.vertx.core.Closeable, io.vertx.core.net.NetClient, io.vertx.core.metrics.Measured, io.vertx.core.spi.metrics.MetricsProvider
Imports
io.netty.bootstrap.Bootstrap, io.netty.channel.Channel, .ChannelOption, .ChannelPipeline, .EventLoop, io.netty.channel.group.ChannelGroup, .ChannelGroupFuture, .DefaultChannelGroup, io.netty.handler.logging.LoggingHandler, io.netty.handler.stream.ChunkedWriteHandler, io.netty.handler.timeout.IdleStateHandler, io.netty.util.concurrent.GenericFutureListener, io.vertx.core.AsyncResult, .Closeable, .Future, .Handler, .Promise, io.vertx.core.impl.CloseFuture, .ContextInternal, .VertxInternal, io.vertx.core.impl.future.PromiseInternal, io.vertx.core.impl.logging.Logger, .LoggerFactory, io.vertx.core.net.NetClient, .NetClientOptions, .NetSocket, .ProxyOptions, .SSLOptions, .SocketAddress, io.vertx.core.spi.metrics.Metrics, .MetricsProvider, .TCPMetrics, java.io.FileNotFoundException, java.net.ConnectException, java.util.Objects, java.util.concurrent.TimeUnit, java.util.function.Predicate

This class is thread-safe
Author
Tim Fox

Field Summary

Modifier and TypeField and Description
private final ChannelGroup
private final CloseFuture
protected final int
private final TimeUnit
private static final Logger
protected final boolean
private final TCPMetrics<S>
private final NetClientOptions
private final Predicate<SocketAddress>
protected final int
private Future<SslContextUpdate>
private final SSLHelper
private final VertxInternal
protected final int

Constructor Summary

AccessConstructor and Description
public
NetClientImpl(VertxInternal vertx, TCPMetrics<S> metrics, NetClientOptions options, CloseFuture closeFuture)

Method Summary

Modifier and TypeMethod and Description
public void
close(Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.net.NetClient.close.

Close the client.

public Future<Void>
close()

Implements io.vertx.core.net.NetClient.close.

Like close(Handler) but returns a Future of the asynchronous result

public void
close(Promise<Void>
the promise to signal when close has completed
completion
)

Implements io.vertx.core.Closeable.close.

Close this resource, the completion promise must be notified when the operation has completed.

public Future<NetSocket>
connect(int port, String host)

Implements io.vertx.core.net.NetClient.connect.

Like connect(int, String, Handler) but returns a Future of the asynchronous result

public Future<NetSocket>
connect(int port, String host, String serverName)

Implements io.vertx.core.net.NetClient.connect.

Like connect(int, String, String, Handler) but returns a Future of the asynchronous result

public Future<NetSocket>
connect(SocketAddress remoteAddress)

Implements io.vertx.core.net.NetClient.connect.

Like connect(SocketAddress, Handler) but returns a Future of the asynchronous result

public Future<NetSocket>
connect(SocketAddress remoteAddress, String serverName)

Implements io.vertx.core.net.NetClient.connect.

Like connect(SocketAddress, String, Handler) but returns a Future of the asynchronous result

public Future<NetSocket>
connect(ContextInternal context, SocketAddress remoteAddress, String serverName)

public NetClient
connect(int
the port
port
,
String
the host
host
,
Handler<AsyncResult<NetSocket>> connectHandler)

Implements io.vertx.core.net.NetClient.connect.

Open a connection to a server at the specific port and host.

public NetClient
connect(int
the port
port
,
String
the host
host
,
String
the SNI server name
serverName
,
Handler<AsyncResult<NetSocket>> connectHandler)

Implements io.vertx.core.net.NetClient.connect.

Open a connection to a server at the specific port and host.

public NetClient
connect(SocketAddress
the remote address
remoteAddress
,
String
the SNI server name
serverName
,
Handler<AsyncResult<NetSocket>> connectHandler)

Implements io.vertx.core.net.NetClient.connect.

Open a connection to a server at the specific remoteAddress.

public NetClient
connect(SocketAddress
the remote address
remoteAddress
,
Handler<AsyncResult<NetSocket>> connectHandler)

Implements io.vertx.core.net.NetClient.connect.

Open a connection to a server at the specific remoteAddress.

private void
connect(SocketAddress remoteAddress, String serverName, Promise<NetSocket> connectHandler, ContextInternal ctx)

private void
connected(ContextInternal context, Channel ch, Promise<NetSocket> connectHandler, SocketAddress remoteAddress, SslChannelProvider sslChannelProvider, String applicationLayerProtocol, boolean registerWriteHandlers)

public void
connectInternal(ProxyOptions
optional proxy configuration
proxyOptions
,
SocketAddress
the server address
remoteAddress
,
SocketAddress
the peer address (along with SSL)
peerAddress
,
String
the SNI server name (along with SSL)
serverName
,
boolean
whether to use SSL
ssl
,
boolean
wether to use ALPN (along with SSL)
useAlpn
,
boolean
whether to register event-bus write handlers
registerWriteHandlers
,
Promise<NetSocket>
the promise to resolve with the connect result
connectHandler
,
ContextInternal
the socket context
context
,
int
how many times reconnection is reattempted
remainingAttempts
)

Open a socket to the remoteAddress server.

private void
connectInternal2(ProxyOptions proxyOptions, SocketAddress remoteAddress, SocketAddress peerAddress, SslChannelProvider sslChannelProvider, String serverName, boolean ssl, boolean useAlpn, boolean registerWriteHandlers, Promise<NetSocket> connectHandler, ContextInternal context, int remainingAttempts)

private void
failed(ContextInternal context, Channel ch, Throwable th, Promise<NetSocket> connectHandler)

public Metrics
getMetrics()

Implements io.vertx.core.spi.metrics.MetricsProvider.getMetrics.

Returns the metrics implementation.

protected void
public boolean
isMetricsEnabled()

Overrides default io.vertx.core.metrics.Measured.isMetricsEnabled.

Whether the metrics are enabled for this measured object

public Future<Boolean>
updateSSLOptions(SSLOptions
the new SSL options
options
,
boolean
force the update when options are equals
force
)

Implements io.vertx.core.net.NetClient.updateSSLOptions.

Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

channelGroupback to summary
private final ChannelGroup channelGroup
closeFutureback to summary
private final CloseFuture closeFuture
idleTimeoutback to summary
protected final int idleTimeout
idleTimeoutUnitback to summary
private final TimeUnit idleTimeoutUnit
logback to summary
private static final Logger log
logEnabledback to summary
protected final boolean logEnabled
metricsback to summary
private final TCPMetrics<S> metrics
optionsback to summary
private final NetClientOptions options
proxyFilterback to summary
private final Predicate<SocketAddress> proxyFilter
readIdleTimeoutback to summary
protected final int readIdleTimeout
sslChannelProviderback to summary
private Future<SslContextUpdate> sslChannelProvider
sslHelperback to summary
private final SSLHelper sslHelper
vertxback to summary
private final VertxInternal vertx
writeIdleTimeoutback to summary
protected final int writeIdleTimeout

Constructor Detail

NetClientImplback to summary
public NetClientImpl(VertxInternal vertx, TCPMetrics<S> metrics, NetClientOptions options, CloseFuture closeFuture)

Method Detail

closeback to summary
public void close(Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.net.NetClient.close.

Doc from io.vertx.core.net.NetClient.close.

Close the client.

Any sockets which have not been closed manually will be closed here. The close is asynchronous and may not complete until some time after the method has returned.

Annotations
@Override
closeback to summary
public Future<Void> close()

Implements io.vertx.core.net.NetClient.close.

Doc from io.vertx.core.net.NetClient.close.

Like close(Handler) but returns a Future of the asynchronous result

Annotations
@Override
closeback to summary
public void close(Promise<Void> completion)

Implements io.vertx.core.Closeable.close.

Doc from io.vertx.core.Closeable.close.

Close this resource, the completion promise must be notified when the operation has completed.

Parameters
completion:Promise<Void>

the promise to signal when close has completed

Annotations
@Override
connectback to summary
public Future<NetSocket> connect(int port, String host)

Implements io.vertx.core.net.NetClient.connect.

Doc from io.vertx.core.net.NetClient.connect.

Like connect(int, String, Handler) but returns a Future of the asynchronous result

Annotations
@Override
connectback to summary
public Future<NetSocket> connect(int port, String host, String serverName)

Implements io.vertx.core.net.NetClient.connect.

Doc from io.vertx.core.net.NetClient.connect.

Like connect(int, String, String, Handler) but returns a Future of the asynchronous result

Annotations
@Override
connectback to summary
public Future<NetSocket> connect(SocketAddress remoteAddress)

Implements io.vertx.core.net.NetClient.connect.

Doc from io.vertx.core.net.NetClient.connect.

Like connect(SocketAddress, Handler) but returns a Future of the asynchronous result

Annotations
@Override
connectback to summary
public Future<NetSocket> connect(SocketAddress remoteAddress, String serverName)

Implements io.vertx.core.net.NetClient.connect.

Doc from io.vertx.core.net.NetClient.connect.

Like connect(SocketAddress, String, Handler) but returns a Future of the asynchronous result

Annotations
@Override
connectback to summary
public Future<NetSocket> connect(ContextInternal context, SocketAddress remoteAddress, String serverName)
connectback to summary
public NetClient connect(int port, String host, Handler<AsyncResult<NetSocket>> connectHandler)

Implements io.vertx.core.net.NetClient.connect.

Doc from io.vertx.core.net.NetClient.connect.

Open a connection to a server at the specific port and host.

host can be a valid host name or IP address. The connect is done asynchronously and on success, a NetSocket instance is supplied via the connectHandler instance

Parameters
port:int

the port

host:String

the host

Returns:NetClient

a reference to this, so the API can be used fluently

connectback to summary
public NetClient connect(int port, String host, String serverName, Handler<AsyncResult<NetSocket>> connectHandler)

Implements io.vertx.core.net.NetClient.connect.

Doc from io.vertx.core.net.NetClient.connect.

Open a connection to a server at the specific port and host.

host can be a valid host name or IP address. The connect is done asynchronously and on success, a NetSocket instance is supplied via the connectHandler instance

Parameters
port:int

the port

host:String

the host

serverName:String

the SNI server name

Returns:NetClient

a reference to this, so the API can be used fluently

Annotations
@Override
connectback to summary
public NetClient connect(SocketAddress remoteAddress, String serverName, Handler<AsyncResult<NetSocket>> connectHandler)

Implements io.vertx.core.net.NetClient.connect.

Doc from io.vertx.core.net.NetClient.connect.

Open a connection to a server at the specific remoteAddress.

The connect is done asynchronously and on success, a NetSocket instance is supplied via the connectHandler instance

Parameters
remoteAddress:SocketAddress

the remote address

serverName:String

the SNI server name

Returns:NetClient

a reference to this, so the API can be used fluently

Annotations
@Override
connectback to summary
public NetClient connect(SocketAddress remoteAddress, Handler<AsyncResult<NetSocket>> connectHandler)

Implements io.vertx.core.net.NetClient.connect.

Doc from io.vertx.core.net.NetClient.connect.

Open a connection to a server at the specific remoteAddress.

The connect is done asynchronously and on success, a NetSocket instance is supplied via the connectHandler instance

Parameters
remoteAddress:SocketAddress

the remote address

Returns:NetClient

a reference to this, so the API can be used fluently

Annotations
@Override
connectback to summary
private void connect(SocketAddress remoteAddress, String serverName, Promise<NetSocket> connectHandler, ContextInternal ctx)
connectedback to summary
private void connected(ContextInternal context, Channel ch, Promise<NetSocket> connectHandler, SocketAddress remoteAddress, SslChannelProvider sslChannelProvider, String applicationLayerProtocol, boolean registerWriteHandlers)
connectInternalback to summary
public void connectInternal(ProxyOptions proxyOptions, SocketAddress remoteAddress, SocketAddress peerAddress, String serverName, boolean ssl, boolean useAlpn, boolean registerWriteHandlers, Promise<NetSocket> connectHandler, ContextInternal context, int remainingAttempts)

Open a socket to the remoteAddress server.

Parameters
proxyOptions:ProxyOptions

optional proxy configuration

remoteAddress:SocketAddress

the server address

peerAddress:SocketAddress

the peer address (along with SSL)

serverName:String

the SNI server name (along with SSL)

ssl:boolean

whether to use SSL

useAlpn:boolean

wether to use ALPN (along with SSL)

registerWriteHandlers:boolean

whether to register event-bus write handlers

connectHandler:Promise<NetSocket>

the promise to resolve with the connect result

context:ContextInternal

the socket context

remainingAttempts:int

how many times reconnection is reattempted

connectInternal2back to summary
private void connectInternal2(ProxyOptions proxyOptions, SocketAddress remoteAddress, SocketAddress peerAddress, SslChannelProvider sslChannelProvider, String serverName, boolean ssl, boolean useAlpn, boolean registerWriteHandlers, Promise<NetSocket> connectHandler, ContextInternal context, int remainingAttempts)
failedback to summary
private void failed(ContextInternal context, Channel ch, Throwable th, Promise<NetSocket> connectHandler)
getMetricsback to summary
public Metrics getMetrics()

Implements io.vertx.core.spi.metrics.MetricsProvider.getMetrics.

Doc from io.vertx.core.spi.metrics.MetricsProvider.getMetrics.

Returns the metrics implementation.

Returns:Metrics

the metrics

Annotations
@Override
initChannelback to summary
protected void initChannel(ChannelPipeline pipeline)
isMetricsEnabledback to summary
public boolean isMetricsEnabled()

Overrides default io.vertx.core.metrics.Measured.isMetricsEnabled.

Doc from io.vertx.core.metrics.Measured.isMetricsEnabled.

Whether the metrics are enabled for this measured object

Returns:boolean

true if metrics are enabled

Annotations
@Override
updateSSLOptionsback to summary
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force)

Implements io.vertx.core.net.NetClient.updateSSLOptions.

Doc from io.vertx.core.net.NetClient.updateSSLOptions.

Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

The boolean succeeded future result indicates whether the update occurred.

Parameters
options:SSLOptions

the new SSL options

force:boolean

force the update when options are equals

Returns:Future<Boolean>

a future signaling the update success

Annotations
@Override