当前位置: 首页>>代码示例>>Java>>正文


Java NetClient类代码示例

本文整理汇总了Java中io.vertx.core.net.NetClient的典型用法代码示例。如果您正苦于以下问题:Java NetClient类的具体用法?Java NetClient怎么用?Java NetClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NetClient类属于io.vertx.core.net包,在下文中一共展示了NetClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Override
public void start() throws Exception {
    NetServer netServer = vertx.createNetServer();//创建代理服务器
    NetClient netClient = vertx.createNetClient();//创建连接mysql客户端
    netServer.connectHandler(socket -> netClient.connect(port, mysqlHost, result -> {
        //响应来自客户端的连接请求,成功之后,在建立一个与目标mysql服务器的连接
        if (result.succeeded()) {
            //与目标mysql服务器成功连接连接之后,创造一个MysqlProxyConnection对象,并执行代理方法
            new MysqlProxyConnection(socket, result.result()).proxy();
        } else {
            logger.error(result.cause().getMessage(), result.cause());
            socket.close();
        }
    })).listen(port, listenResult -> {//代理服务器的监听端口
        if (listenResult.succeeded()) {
            //成功启动代理服务器
            logger.info("Mysql proxy server start up.");
        } else {
            //启动代理服务器失败
            logger.error("Mysql proxy exit. because: " + listenResult.cause().getMessage(), listenResult.cause());
            System.exit(1);
        }
    });
}
 
开发者ID:jacklcz,项目名称:mysql_proxy,代码行数:25,代码来源:MysqlProxyServer.java

示例2: registerTimerOut

import io.vertx.core.net.NetClient; //导入依赖的package包/类
private void registerTimerOut(final Session session, final NetClient client) {
    vertx.setPeriodic(config.getJsonObject("application").getInteger("tcp-session-timeout", 1200) * 1000, new Handler<Long>() {
        private int readCount = 0;
        private int writeCount = 0;

        @Override
        public void handle(Long timerID) {
            if ((session.getRead_count() <= readCount) && (session.getWrite_count() <= writeCount)) {
                session.setActive(false);
                if (client != null) {
                    client.close();
                }
                vertx.cancelTimer(timerID);
            }
            readCount = session.getRead_count();
            writeCount = session.getWrite_count();
        }
    });
}
 
开发者ID:zyclonite,项目名称:nassh-relay,代码行数:20,代码来源:ProxyHandler.java

示例3: start

import io.vertx.core.net.NetClient; //导入依赖的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

示例4: waitPortToClose

import io.vertx.core.net.NetClient; //导入依赖的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

示例5: noConnectSent

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Test
public void noConnectSent(TestContext context) {

  NetClient client = this.vertx.createNetClient();
  Async async = context.async();

  client.connect(MQTT_SERVER_PORT, MQTT_SERVER_HOST, done -> {

    if (done.succeeded()) {

      done.result().closeHandler(v -> {
        log.info("No CONNECT sent in " + MQTT_TIMEOUT_ON_CONNECT + " secs. Closing connection.");
        async.complete();
      });

    } else {
      context.fail();
    }
  });

  // check that the async is completed (so connection was closed by server) in
  // the specified timeout (+500 ms just for being sure)
  async.await(500 + MQTT_TIMEOUT_ON_CONNECT * 1000);
  if (!async.isCompleted())
    context.fail();
}
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:27,代码来源:MqttServerConnectionTest.java

示例6: start

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) {
    log.info("start", "initializationStarted");

    MemcacheClusterConfig memcacheClusterConfig;
    try {
        memcacheClusterConfig = new MemcacheClusterConfig(config().getJsonObject(MEMCACHE_CLUSTER_KEY));
    } catch (MemcacheException me) {
        log.error("start", "exception", me.getMessage());
        startFuture.fail(new Exception(me.getMessage()));
        return;
    }


    NetClient netClient = vertx.createNetClient();
    establishSockets(memcacheClusterConfig, netClient);

    log.info("start", "initializationCompleted");
    startFuture.complete();
}
 
开发者ID:groupon,项目名称:vertx-memcache,代码行数:21,代码来源:MemcacheClusterVerticle.java

示例7: testSendMessageWithReplyBacktrack

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Test
public void testSendMessageWithReplyBacktrack(TestContext context) {
  // Send a request and get a response
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      JsonObject frame = parse.result();
      context.assertNotEquals("err", frame.getString("type"));
      context.assertEquals("Hello vert.x", frame.getJsonObject("body").getString("value"));
      client.close();
      async.complete();
    });

    socket.handler(parser);

    FrameHelper.sendFrame("send", "hello", "#backtrack", new JsonObject().put("value", "vert.x"), socket);
  });
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:26,代码来源:TcpEventBusBridgeInteropTest.java

示例8: testSendMessageWithDuplicateReplyID

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Test
public void testSendMessageWithDuplicateReplyID(TestContext context) {
  // replies must always return to the same origin

  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    vertx.eventBus().consumer("third-party-receiver", msg -> context.fail());

    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      client.close();
      async.complete();
    });

    socket.handler(parser);


    FrameHelper.sendFrame("send", "hello", "third-party-receiver", new JsonObject().put("value", "vert.x"), socket);
  });
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:27,代码来源:TcpEventBusBridgeInteropTest.java

示例9: testSendVoidMessage

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Test
public void testSendVoidMessage(TestContext context) {
  // Send a request and get a response
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  vertx.eventBus().consumer("test", (Message<JsonObject> msg) -> {
    client.close();
    async.complete();
  });

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    FrameHelper.sendFrame("send", "test", new JsonObject().put("value", "vert.x"), socket);
  });
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:20,代码来源:TcpEventBusBridgeTest.java

示例10: testSendsFromOtherSideOfBridge

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Test
public void testSendsFromOtherSideOfBridge(TestContext context) {
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      JsonObject frame = parse.result();
      context.assertNotEquals("err", frame.getString("type"));
      context.assertEquals(true, frame.getBoolean("send"));
      context.assertEquals("hi", frame.getJsonObject("body").getString("value"));
      client.close();
      async.complete();
    });

    socket.handler(parser);

    FrameHelper.sendFrame("register", "ping", null, socket);
  });

}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:27,代码来源:TcpEventBusBridgeTest.java

示例11: testSendMessageWithReplyBacktrack

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Test
public void testSendMessageWithReplyBacktrack(TestContext context) {
  // Send a request and get a response
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      JsonObject frame = parse.result();
      context.assertNotEquals("err", frame.getString("type"));
      context.assertEquals(true, frame.getBoolean("send"));
      context.assertEquals("Hello vert.x", frame.getJsonObject("body").getString("value"));
      client.close();
      async.complete();
    });

    socket.handler(parser);

    FrameHelper.sendFrame("send", "hello", "#backtrack", new JsonObject().put("value", "vert.x"), socket);
  });
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:27,代码来源:TcpEventBusBridgeTest.java

示例12: testSendPing

import io.vertx.core.net.NetClient; //导入依赖的package包/类
@Test
public void testSendPing(TestContext context) {
  NetClient client = vertx.createNetClient();
  final Async async = context.async();
  eventHandler = event -> {
    if (event.type() == BridgeEventType.SOCKET_PING) {
      async.complete();
    }
  };
  client.connect(7000, "localhost", context.asyncAssertSuccess(socket -> {
    socket.handler(buff -> {

    });
    FrameHelper.sendFrame("register", "echo", null, socket);
    FrameHelper.sendFrame("ping", socket);
  }));
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:18,代码来源:TcpEventBusBridgeTest.java

示例13: check

import io.vertx.core.net.NetClient; //导入依赖的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

示例14: check

import io.vertx.core.net.NetClient; //导入依赖的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

示例15: ProtonTransport

import io.vertx.core.net.NetClient; //导入依赖的package包/类
ProtonTransport(Connection connection, Vertx vertx, NetClient netClient, NetSocket socket,
                ProtonSaslAuthenticator authenticator, ProtonTransportOptions options) {
  this.connection = connection;
  this.vertx = vertx;
  this.netClient = netClient;
  this.socket = socket;
  transport.setMaxFrameSize(options.getMaxFrameSize() == 0 ? DEFAULT_MAX_FRAME_SIZE : options.getMaxFrameSize());
  transport.setEmitFlowEventOnSend(false); // TODO: make configurable
  transport.setIdleTimeout(2 * options.getHeartbeat());
  if (authenticator != null) {
    authenticator.init(this.socket, (ProtonConnection) this.connection.getContext(), transport);
  }
  this.authenticator = authenticator;
  transport.bind(connection);
  connection.collect(collector);
  socket.endHandler(this::handleSocketEnd);
  socket.handler(this::handleSocketBuffer);
}
 
开发者ID:vert-x3,项目名称:vertx-proton,代码行数:19,代码来源:ProtonTransport.java


注:本文中的io.vertx.core.net.NetClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。