use of io.vertx.core.http.HttpServer in project vert.x by eclipse.
the class HttpTestBase method startServer.
protected void startServer(Context context, HttpServer server) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
context.runOnContext(v -> {
server.listen(onSuccess(s -> latch.countDown()));
});
awaitLatch(latch);
}
use of io.vertx.core.http.HttpServer in project vert.x by eclipse.
the class DummyMetricsTest method testDummyHttpServerMetrics.
@Test
public void testDummyHttpServerMetrics() {
HttpServer server = vertx.createHttpServer(new HttpServerOptions());
assertFalse(server.isMetricsEnabled());
}
use of io.vertx.core.http.HttpServer in project vert.x by eclipse.
the class VertxImpl method close.
@Override
public synchronized void close(Handler<AsyncResult<Void>> completionHandler) {
if (closed || eventBus == null) {
// Just call the handler directly since pools shutdown
if (completionHandler != null) {
completionHandler.handle(Future.succeededFuture());
}
return;
}
closed = true;
closeHooks.run(ar -> {
deploymentManager.undeployAll(ar1 -> {
if (haManager() != null) {
haManager().stop();
}
addressResolver.close(ar2 -> {
eventBus.close(ar3 -> {
closeClusterManager(ar4 -> {
Set<HttpServer> httpServers = new HashSet<>(sharedHttpServers.values());
Set<NetServerBase> netServers = new HashSet<>(sharedNetServers.values());
sharedHttpServers.clear();
sharedNetServers.clear();
int serverCount = httpServers.size() + netServers.size();
AtomicInteger serverCloseCount = new AtomicInteger();
Handler<AsyncResult<Void>> serverCloseHandler = res -> {
if (res.failed()) {
log.error("Failure in shutting down server", res.cause());
}
if (serverCloseCount.incrementAndGet() == serverCount) {
deleteCacheDirAndShutdown(completionHandler);
}
};
for (HttpServer server : httpServers) {
server.close(serverCloseHandler);
}
for (NetServerBase server : netServers) {
server.close(serverCloseHandler);
}
if (serverCount == 0) {
deleteCacheDirAndShutdown(completionHandler);
}
});
});
});
});
});
}
use of io.vertx.core.http.HttpServer in project java-chassis by ServiceComb.
the class TestGrpcVerticle method testGrpcVerticle.
@Test
public void testGrpcVerticle(@Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject json) throws Exception {
new Expectations() {
{
context.config();
result = json;
json.getString(anyString);
result = "grpc://127.0.0.1:9090";
}
};
GrpcVerticle grpcVerticle = new GrpcVerticle();
grpcVerticle.init(vertx, context);
@SuppressWarnings("unchecked") Future<Void> startFuture = Mockito.mock(Future.class);
grpcVerticle.startListen(startFuture);
MockUtil.getInstance().mockGrpcConfig();
try {
grpcVerticle.startListen(startFuture);
Assert.assertTrue(true);
} catch (Exception e) {
Assert.assertTrue(false);
}
IpPort ipPort = Mockito.mock(IpPort.class);
HttpServer server = Mockito.mock(HttpServer.class);
Deencapsulation.invoke(grpcVerticle, "startListen", server, ipPort, startFuture);
Assert.assertEquals("clientMgr", GrpcVerticle.CLIENT_MGR);
}
use of io.vertx.core.http.HttpServer in project java-chassis by ServiceComb.
the class GrpcVerticle method startListen.
protected void startListen(Future<Void> startFuture) {
// 如果本地未配置grpc地址,则表示不必监听,只需要作为客户端使用即可
if (StringUtils.isEmpty(this.endpoint)) {
LOGGER.warn("grpc listen address is not configured, will not listen.");
startFuture.complete();
return;
}
Router mainRouter = Router.router(vertx);
mainRouter.route().handler(new GrpcBodyHandler());
new GrpcServer(mainRouter);
HttpServerOptions serverOptions = new HttpServerOptions();
serverOptions.setAcceptBacklog(ACCEPT_BACKLOG);
serverOptions.setSendBufferSize(SEND_BUFFER_SIZE);
serverOptions.setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
serverOptions.setUsePooledBuffers(true);
String key = System.getProperty("store.key");
if (key != null && !key.isEmpty()) {
serverOptions.setUseAlpn(true);
serverOptions.setSsl(true);
serverOptions.setKeyStoreOptions(new JksOptions().setPath(System.getProperty("store.key")).setPassword(System.getProperty("store.pass")));
}
HttpServer server = vertx.createHttpServer(serverOptions).requestHandler(mainRouter::accept);
IpPort ipPort = NetUtils.parseIpPortFromURI(this.endpoint);
if (ipPort == null) {
LOGGER.error("wrong grpc listen address {}", this.endpoint);
return;
}
startListen(server, ipPort, startFuture);
}
Aggregations