本文整理汇总了Java中io.vertx.core.net.NetServer.connectHandler方法的典型用法代码示例。如果您正苦于以下问题:Java NetServer.connectHandler方法的具体用法?Java NetServer.connectHandler怎么用?Java NetServer.connectHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.net.NetServer
的用法示例。
在下文中一共展示了NetServer.connectHandler方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTcpServerNonSSL
import io.vertx.core.net.NetServer; //导入方法依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testTcpServerNonSSL(@Mocked Vertx vertx, @Mocked AsyncResultCallback<InetSocketAddress> callback,
@Mocked NetServer netServer) {
new Expectations() {
{
vertx.createNetServer();
result = netServer;
netServer.connectHandler((Handler) any);
netServer.listen(anyInt, anyString, (Handler) any);
}
};
URIEndpointObject endpointObject = new URIEndpointObject("highway://127.0.0.1:6663");
TcpServer server = new TcpServerForTest(endpointObject);
// assert done in Expectations
server.init(vertx, "", callback);
}
示例2: testTcpServerSSL
import io.vertx.core.net.NetServer; //导入方法依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testTcpServerSSL(@Mocked Vertx vertx, @Mocked AsyncResultCallback<InetSocketAddress> callback,
@Mocked NetServer netServer) {
new Expectations() {
{
vertx.createNetServer((NetServerOptions) any);
result = netServer;
netServer.connectHandler((Handler) any);
netServer.listen(anyInt, anyString, (Handler) any);
}
};
URIEndpointObject endpointObject = new URIEndpointObject("highway://127.0.0.1:6663?sslEnabled=true");
TcpServer server = new TcpServerForTest(endpointObject);
// assert done in Expectations
server.init(vertx, "", callback);
}
示例3: start
import io.vertx.core.net.NetServer; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
NetServerOptions options = new NetServerOptions().setPort(8380);
NetServer server = vertx.createNetServer(options);
server.connectHandler(this::handle);
server.close(result -> {
if(result.succeeded()){
//TCP server fully closed
System.out.println("server close succeeded.");
}else {
System.out.println("server status: " + result.result().toString());
}
});
server.listen();
}
示例4: testConnectionDisconnectedDuringCreation
import io.vertx.core.net.NetServer; //导入方法依赖的package包/类
@Test(timeout = 20000)
public void testConnectionDisconnectedDuringCreation(TestContext context) {
server.close();
Async connectFailsAsync = context.async();
NetServer netServer = this.vertx.createNetServer();
netServer.connectHandler(netSocket -> {
netSocket.pause();
vertx.setTimer(50, x -> {
netSocket.close();
});
});
netServer.listen(listenResult -> {
context.assertTrue(listenResult.succeeded());
ProtonClient.create(vertx).connect("localhost", netServer.actualPort(), connResult -> {
context.assertFalse(connResult.succeeded());
connectFailsAsync.complete();
});
});
connectFailsAsync.awaitSuccess();
}
示例5: init
import io.vertx.core.net.NetServer; //导入方法依赖的package包/类
public void init(Vertx vertx, String sslKey, AsyncResultCallback<InetSocketAddress> callback) {
NetServer netServer;
if (endpointObject.isSslEnabled()) {
SSLOptionFactory factory =
SSLOptionFactory.createSSLOptionFactory(sslKey, null);
SSLOption sslOption;
if (factory == null) {
sslOption = SSLOption.buildFromYaml(sslKey);
} else {
sslOption = factory.createSSLOption();
}
SSLCustom sslCustom = SSLCustom.createSSLCustom(sslOption.getSslCustomClass());
NetServerOptions serverOptions = new NetServerOptions();
VertxTLSBuilder.buildNetServerOptions(sslOption, sslCustom, serverOptions);
netServer = vertx.createNetServer(serverOptions);
} else {
netServer = vertx.createNetServer();
}
netServer.connectHandler(netSocket -> {
TcpServerConnection connection = createTcpServerConnection();
connection.init(netSocket);
});
InetSocketAddress socketAddress = endpointObject.getSocketAddress();
netServer.listen(socketAddress.getPort(), socketAddress.getHostString(), ar -> {
if (ar.succeeded()) {
callback.success(socketAddress);
return;
}
// 监听失败
String msg = String.format("listen failed, address=%s", socketAddress.toString());
callback.fail(new Exception(msg, ar.cause()));
});
}
示例6: testMetricsCleanupedOnVertxClose
import io.vertx.core.net.NetServer; //导入方法依赖的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;
}
示例7: start
import io.vertx.core.net.NetServer; //导入方法依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
NetServer tcpServer = vertx.createNetServer();
tcpServer.connectHandler(socket -> {
socket.handler(recordParser);
});
tcpServer.listen(port, result -> {
if (result.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(result.cause());
}
});
}