本文整理汇总了Java中io.vertx.core.net.NetClientOptions类的典型用法代码示例。如果您正苦于以下问题:Java NetClientOptions类的具体用法?Java NetClientOptions怎么用?Java NetClientOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetClientOptions类属于io.vertx.core.net包,在下文中一共展示了NetClientOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
@Override
public void start(Handler<AsyncResult<Void>> startFuture) {
if (port > 0) {
// fail if port is already in use
NetClientOptions options = new NetClientOptions().setConnectTimeout(200);
NetClient c = vertx.createNetClient(options);
c.connect(port, "localhost", res -> {
if (res.succeeded()) {
NetSocket socket = res.result();
socket.close();
startFuture.handle(Future.failedFuture("port " + port + " already in use"));
} else {
start2(startFuture);
}
});
} else {
start2(startFuture);
}
}
示例2: waitPortToClose
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
private void waitPortToClose(Handler<AsyncResult<Void>> stopFuture, int iter) {
if (port > 0) {
// fail if port is already in use
NetClientOptions options = new NetClientOptions().setConnectTimeout(50);
NetClient c = vertx.createNetClient(options);
c.connect(port, "localhost", res -> {
if (res.succeeded()) {
NetSocket socket = res.result();
socket.close();
if (iter > 0) {
vertx.setTimer(100, x -> waitPortToClose(stopFuture, iter - 1));
} else {
stopFuture.handle(Future.failedFuture("port " + port + " not shut down"));
}
} else {
stopFuture.handle(Future.succeededFuture());
}
});
} else {
stopFuture.handle(Future.succeededFuture());
}
}
示例3: check
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
@Override
public Future<Result> check() {
Future<Result> future = Future.future();
NetClientOptions options = new NetClientOptions().setConnectTimeout(500);
NetClient client = vertx.createNetClient(options);
client.connect(port, host, res -> {
if (res.succeeded()) {
future.complete(Result.healthy());
} else {
future.complete(Result.unhealthy(res.cause()));
}
client.close();
});
return future;
}
示例4: check
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
@Override
public CompletableFuture<Result> check() {
VertxCompletableFuture<Result> result = new VertxCompletableFuture<>(vertx);
NetClientOptions options = new NetClientOptions().setConnectTimeout(500);
NetClient client = vertx.createNetClient(options);
client.connect(port, host, res -> {
if (res.succeeded()) {
result.complete(Result.healthy());
} else {
result.complete(Result.unhealthy(res.cause()));
}
client.close();
});
return result;
}
示例5: SMTPConnectionPool
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
SMTPConnectionPool(Vertx vertx, MailConfig config) {
this.config = config;
this.vertx = vertx;
maxSockets = config.getMaxPoolSize();
keepAlive = config.isKeepAlive();
NetClientOptions netClientOptions = new NetClientOptions().setSsl(config.isSsl()).setTrustAll(config.isTrustAll());
if ((config.isSsl() || config.getStarttls() != StartTLSOptions.DISABLED) && !config.isTrustAll()) {
// we can use HTTPS verification, which matches the requirements for SMTPS
netClientOptions.setHostnameVerificationAlgorithm("HTTPS");
}
if (config.getKeyStore() != null) {
// assume that password could be null if the keystore doesn't use one
netClientOptions.setTrustStoreOptions(new JksOptions().setPath(config.getKeyStore())
.setPassword(config.getKeyStorePassword()));
}
netClient = vertx.createNetClient(netClientOptions);
}
示例6: FdfsClientImpl
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
public FdfsClientImpl(Vertx vertx, FdfsClientOptions options) {
this.vertx = vertx;
this.pool = new FdfsConnectionPool(vertx, new NetClientOptions().setConnectTimeout((int) options.getConnectTimeout()), options.getPoolSize());
this.options = options;
this.currentTrackerIndex = 0;
this.trackerCount = options.getTrackers().size();
}
示例7: createNetClient
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
private void createNetClient()
{
NetClientOptions netClientOptions = new NetClientOptions()
.setConnectTimeout(options.getConnectTimeout())
.setIdleTimeout(options.getIdleTimeout())
.setReconnectAttempts(options.getReconnectAttempts())
.setReconnectInterval(options.getReconnectInterval())
.setReceiveBufferSize(BUFFER_SIZE);
this.netClient = this.vertx.createNetClient(netClientOptions);
}
示例8: PgConnectionFactory
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
public PgConnectionFactory(Context context,
boolean registerCloseHook,
PgConnectOptions options) {
hook = this::close;
this.registerCloseHook = registerCloseHook;
ctx = context;
if (registerCloseHook) {
ctx.addCloseHook(hook);
}
NetClientOptions netClientOptions = new NetClientOptions(options);
// Make sure ssl=false as we will use STARTLS
netClientOptions.setSsl(false);
this.ssl = options.isSsl();
this.host = options.getHost();
this.port = options.getPort();
this.database = options.getDatabase();
this.username = options.getUsername();
this.password = options.getPassword();
this.client = context.owner().createNetClient(netClientOptions);
this.cachePreparedStatements = options.getCachePreparedStatements();
this.pipeliningLimit = options.getPipeliningLimit();
}
示例9: tryConnect
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
private void tryConnect(Handler<AsyncResult<Void>> startFuture, int count) {
NetClientOptions options = new NetClientOptions().setConnectTimeout(MILLISECONDS);
NetClient c = vertx.createNetClient(options);
c.connect(port, "localhost", res -> {
if (res.succeeded()) {
logger.info("Connected to service at port " + port + " count " + count);
NetSocket socket = res.result();
socket.close();
try {
p.getErrorStream().close();
} catch (Exception e) {
logger.error("Closing streams failed: " + e);
}
startFuture.handle(Future.succeededFuture());
} else if (!p.isAlive() && p.exitValue() != 0) {
logger.warn("Service returned with exit code " + p.exitValue());
startFuture.handle(Future.failedFuture("Service returned with exit code "
+ p.exitValue()));
} else if (count < maxIterations) {
vertx.setTimer((long) (count + 1) * MILLISECONDS,
id -> tryConnect(startFuture, count + 1));
} else {
startFuture.handle(Future.failedFuture("Deployment failed. "
+ "Could not connect to port " + port + ": " + res.cause().getMessage()));
}
});
}
示例10: connectToRemote
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
private void connectToRemote(String addr, int port) {
// 5s timeout.
NetClientOptions options = new NetClientOptions().setConnectTimeout(5000);
NetClient client = mVertx.createNetClient(options);
client.connect(port, addr, res -> { // connect handler
if (!res.succeeded()) {
log.error("Failed to connect " + addr + ":" + port + ". Caused by " + res.cause().getMessage());
destory();
return;
}
mTargetSocket = res.result();
setFinishHandler(mTargetSocket);
mTargetSocket.handler(buffer -> { // remote socket data handler
try {
byte [] data = buffer.getBytes();
byte [] encryptData = mCrypto.encrypt(data, data.length);
flowControl(mClientSocket, mTargetSocket);
mClientSocket.write(Buffer.buffer(encryptData));
}catch(CryptoException e){
log.error("Catch exception", e);
destory();
}
});
if (mBufferQueue.length() > 0) {
handleStageData();
}
});
}
示例11: MyReceiver
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
public MyReceiver(String host, int port, String dest) throws MessagingException
{
NetClient netClient = Vertx.factory.vertx().createNetClient(new NetClientOptions());
DefaultConnectionSettings settings = new DefaultConnectionSettings();
settings.setHost(host);
settings.setPort(port);
connection = new ManagedConnection(settings, this, false);
netClient.connect(settings.getPort(), settings.getHost(), result -> {
if (result.succeeded())
{
connection.setNetSocket(result.result());
connection.write();
connection.addDisconnectHandler(c -> {
LOG.warn("Connection lost to peer at %s:%s", connection.getSettings().getHost(), connection
.getSettings().getPort());
});
LOG.info("Connected to AMQP peer at %s:%s", connection.getSettings().getHost(), connection
.getSettings().getPort());
}
else
{
LOG.warn("Error {%s}, when connecting to AMQP peer at %s:%s", result.cause(), connection.getSettings()
.getHost(), connection.getSettings().getPort());
}
});
link = connection.createInboundLink(dest, ReliabilityMode.AT_LEAST_ONCE, CreditMode.AUTO);
link.setCredits(10);
}
示例12: MySender
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
public MySender(String host, int port, String destination) throws MessagingException
{
NetClient netClient = Vertx.factory.vertx().createNetClient(new NetClientOptions());
DefaultConnectionSettings settings = new DefaultConnectionSettings();
settings.setHost(host);
settings.setPort(port);
connection = new ManagedConnection(settings, this, false);
netClient.connect(settings.getPort(), settings.getHost(), result -> {
if (result.succeeded())
{
connection.setNetSocket(result.result());
connection.write();
connection.addDisconnectHandler(c -> {
LOG.warn("Connection lost to peer at %s:%s", connection.getSettings().getHost(), connection
.getSettings().getPort());
});
LOG.info("Connected to AMQP peer at %s:%s", connection.getSettings().getHost(), connection
.getSettings().getPort());
}
else
{
LOG.warn("Error {%s}, when connecting to AMQP peer at %s:%s", result.cause(), connection.getSettings()
.getHost(), connection.getSettings().getPort());
}
});
link = connection.createOutboundLink(destination, ReliabilityMode.AT_LEAST_ONCE);
}
示例13: connect
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
private CompletableFuture<ConnectionInstance> connect() {
LOGGER.info("Connecting to MPD...");
final CompletableFuture<NetSocket> netSocketReady = new CompletableFuture<>();
vertx.createNetClient(new NetClientOptions()
.setConnectTimeout(CONNECTION_TIMEOUT)
.setReceiveBufferSize(DEFAULT_BUFFER_SIZE)
.setReconnectAttempts(RECONNECT_ATTEMPTS)
.setReconnectInterval(RECONNECT_INTERVAL_MS)
.setTcpKeepAlive(true))
.connect(configuration.getPort(), configuration.getHostname(), res -> {
if (res.succeeded()) {
netSocketReady.complete(res.result());
LOGGER.info("Connection successful");
} else {
error("Connection failure", res.cause());
netSocketReady.completeExceptionally(res.cause());
}
});
return netSocketReady
.thenApply(netSocket -> {
LineStreamer ls = new LineStreamer(netSocket, "\n");
LOGGER.info(ls);
return ls;
})
.thenCompose(lineStreamer -> lineStreamer.expect(MPD_CONNECT_OK))
.thenCombine(netSocketReady, ConnectionInstance::new)
.exceptionally(t -> {
error("Initial MPD connection failure: ", t);
return null;
});
}
示例14: createMetrics
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
@Override
public TCPMetrics<?> createMetrics(NetClientOptions options) {
String baseName;
if (options.getMetricsName() != null) {
baseName = nameOf("net.clients", options.getMetricsName());
} else {
baseName = nameOf("net.clients");
}
return new TCPMetricsImpl(registry, baseName);
}
示例15: createNetClient
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
protected NetClient createNetClient(NetClientOptions options) {
NetClient client = vertx.createNetClient(options);
toClose.add(() -> {
CountDownLatch latch = new CountDownLatch(1);
client.close();
awaitLatch(latch);
return null;
});
return client;
}