本文整理汇总了Java中io.vertx.core.net.NetClientOptions类的典型用法代码示例。如果您正苦于以下问题:Java NetClientOptions类的具体用法?Java NetClientOptions怎么用?Java NetClientOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetClientOptions类属于io.vertx.core.net包,在下文中一共展示了NetClientOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:folio-org,项目名称:okapi,代码行数:20,代码来源:ProcessModuleHandle.java
示例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());
}
}
开发者ID:folio-org,项目名称:okapi,代码行数:23,代码来源:ProcessModuleHandle.java
示例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;
}
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:20,代码来源:ManagementApiProbe.java
示例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;
}
开发者ID:gravitee-io,项目名称:gravitee-gateway,代码行数:20,代码来源:GatewayProbe.java
示例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);
}
开发者ID:vert-x3,项目名称:vertx-mail-client,代码行数:18,代码来源:SMTPConnectionPool.java
示例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();
}
开发者ID:gengteng,项目名称:vertx-fastdfs-client,代码行数:8,代码来源:FdfsClientImpl.java
示例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);
}
开发者ID:ivkos,项目名称:gpsd4j,代码行数:12,代码来源:GpsdClient.java
示例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();
}
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:28,代码来源:PgConnectionFactory.java
示例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()));
}
});
}
开发者ID:folio-org,项目名称:okapi,代码行数:28,代码来源:ProcessModuleHandle.java
示例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();
}
});
}
开发者ID:Bestoa,项目名称:shadowsocks-vertx,代码行数:29,代码来源:ServerHandler.java
示例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);
}
开发者ID:vert-x3,项目名称:vertx-amqp-service,代码行数:30,代码来源:MyReceiver.java
示例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);
}
开发者ID:vert-x3,项目名称:vertx-amqp-service,代码行数:29,代码来源:MySender.java
示例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;
});
}
开发者ID:jotak,项目名称:mipod.x,代码行数:32,代码来源:MpdClient.java
示例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);
}
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:11,代码来源:VertxMetricsImpl.java
示例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;
}
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:11,代码来源:MetricsTestBase.java
示例16: testNetMetricsOnClose
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
@Test
public void testNetMetricsOnClose() throws Exception {
int requests = 8;
CountDownLatch latch = new CountDownLatch(requests);
NetClient client = vertx.createNetClient(new NetClientOptions());
NetServer server = vertx.createNetServer(new NetServerOptions().setHost("localhost").setPort(1235).setReceiveBufferSize(50)).connectHandler(socket -> {
socket.handler(buff -> latch.countDown());
}).listen(ar -> {
assertTrue(ar.succeeded());
client.connect(1235, "localhost", ar2 -> {
assertTrue(ar2.succeeded());
for (int i = 0; i < requests; i++) {
ar2.result().write(randomBuffer(50));
}
});
});
awaitLatch(latch);
client.close();
server.close(ar -> {
assertTrue(ar.succeeded());
vertx.runOnContext(v -> testComplete());
});
await();
JsonObject metrics = metricsService.getMetricsSnapshot(server);
assertNotNull(metrics);
assertTrue(metrics.isEmpty());
metrics = metricsService.getMetricsSnapshot(client);
assertNotNull(metrics);
assertTrue(metrics.isEmpty());
cleanup(client);
cleanup(server);
}
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:40,代码来源:MetricsTest.java
示例17: testMetricsCleanupedOnVertxClose
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
@Test
public void testMetricsCleanupedOnVertxClose() throws Exception {
CountDownLatch latch1 = new CountDownLatch(1);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestHandler(req -> {});
server.listen(onSuccess(res -> {
latch1.countDown();
}));
awaitLatch(latch1);
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
CountDownLatch latch2 = new CountDownLatch(1);
NetServer nServer = vertx.createNetServer(new NetServerOptions().setPort(1234));
nServer.connectHandler(conn -> {});
nServer.listen(res -> {
latch2.countDown();
});
awaitLatch(latch2);
NetClient nClient = vertx.createNetClient(new NetClientOptions());
DatagramSocket sock = vertx.createDatagramSocket(new DatagramSocketOptions());
EventBus eb = vertx.eventBus();
assertFalse(metricsService.getMetricsSnapshot(vertx).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(server).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(client).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(nServer).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(nClient).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(sock).isEmpty());
assertFalse(metricsService.getMetricsSnapshot(eb).isEmpty());
vertx.close(res -> {
assertTrue(metricsService.getMetricsSnapshot(vertx).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(server).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(client).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(nServer).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(nClient).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(sock).isEmpty());
assertTrue(metricsService.getMetricsSnapshot(eb).isEmpty());
testComplete();
});
await();
vertx = null;
}
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:41,代码来源:MetricsTest.java
示例18: connectTcpEndpoint
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
private Future<UUID> connectTcpEndpoint(final UUID sid, final String host, final int port, final String clienthost) {
final Future<UUID> future = Future.future();
final NetClient client = vertx.createNetClient(new NetClientOptions().setReconnectAttempts(10).setReconnectInterval(500));
client.connect(port, host, asyncResult -> {
if (asyncResult.succeeded()) {
logger.info("Connected to ssh server: " + host + ":" + port + " (" + clienthost + ")");
QueueFactory.createQueue(sid.toString());
asyncResult.result().drainHandler(v -> asyncResult.result().resume());
asyncResult.result().handler(buffer -> {
try {
final TransferQueue queue = QueueFactory.getQueue(sid.toString());
if (!queue.isFull()) {
queue.add(buffer);
} else {
asyncResult.result().pause();
}
} catch (NoSuchQueueException ex) {
logger.warn(ex, ex.fillInStackTrace());
}
});
asyncResult.result().closeHandler(v -> {
logger.info("ssh server connection closed " + host + ":" + port);
QueueFactory.deleteQueue(sid.toString());
sessions.remove(sid.toString());
});
final Session session = new Session();
session.setHandler(asyncResult.result().writeHandlerID());
sessions.put(sid.toString(), session);
registerTimerOut(session, client);
future.complete(sid);
} else {
future.fail(asyncResult.cause());
logger.warn("Could not connect to ssh server: " + asyncResult.cause().getMessage(), asyncResult.cause());
}
});
return future;
}
开发者ID:zyclonite,项目名称:nassh-relay,代码行数:38,代码来源:ProxyHandler.java
示例19: createMetrics
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
@Override
default TCPMetrics<?> createMetrics(NetClientOptions options) {
return DummyVertxMetrics.DummyTCPMetrics.INSTANCE;
}
开发者ID:unbroken-dome,项目名称:vertx-spring,代码行数:5,代码来源:VertxMetricsAdapter.java
示例20: createMetrics
import io.vertx.core.net.NetClientOptions; //导入依赖的package包/类
@Override
public TCPMetrics<?> createMetrics(NetClientOptions options) {
return this.<TCPMetrics<?>> createSubMetrics(v -> v.createMetrics(options),
d -> new DispatchingTcpMetrics(d));
}
开发者ID:unbroken-dome,项目名称:vertx-spring,代码行数:6,代码来源:DispatchingVertxMetrics.java
注:本文中的io.vertx.core.net.NetClientOptions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论