public NetServerImpl(VertxInternal vertx, NetServerOptions options) { this.vertx = vertx; this.options = new NetServerOptions(options); this.sslHelper = new SSLHelper(options, options.getKeyCertOptions(), options.getTrustOptions()); this.creatingContext = vertx.getContext(); this.logEnabled = options.getLogActivity(); if (creatingContext != null) { creatingContext.addCloseHook(this); } }
public HttpServerImpl(VertxInternal vertx, HttpServerOptions options) { this.options = new HttpServerOptions(options); this.vertx = vertx; this.creatingContext = vertx.getContext(); if (creatingContext != null) { creatingContext.addCloseHook(this); } this.sslHelper = new SSLHelper(options, options.getKeyCertOptions(), options.getTrustOptions()); this.subProtocols = options.getWebsocketSubProtocols(); this.logEnabled = options.getLogActivity(); }
@Test public void testCloseHooksCalled() throws Exception { AtomicInteger closedCount = new AtomicInteger(); Closeable myCloseable1 = completionHandler -> { closedCount.incrementAndGet(); completionHandler.handle(Future.succeededFuture()); }; Closeable myCloseable2 = completionHandler -> { closedCount.incrementAndGet(); completionHandler.handle(Future.succeededFuture()); }; MyAsyncVerticle verticle = new MyAsyncVerticle(f-> { ContextInternal ctx = (ContextInternal)Vertx.currentContext(); ctx.addCloseHook(myCloseable1); ctx.addCloseHook(myCloseable2); f.complete(null); }, f -> f.complete(null)); vertx.deployVerticle(verticle, ar -> { assertTrue(ar.succeeded()); assertEquals(0, closedCount.get()); // Now undeploy vertx.undeploy(ar.result(), ar2 -> { assertTrue(ar2.succeeded()); assertEquals(2, closedCount.get()); testComplete(); }); }); await(); }
public NetClientImpl(VertxInternal vertx, NetClientOptions options, boolean useCreatingContext) { this.vertx = vertx; this.options = new NetClientOptions(options); this.sslHelper = new SSLHelper(options, options.getKeyCertOptions(), options.getTrustOptions()); this.closeHook = completionHandler -> { NetClientImpl.this.close(); completionHandler.handle(Future.succeededFuture()); }; if (useCreatingContext) { creatingContext = vertx.getContext(); if (creatingContext != null) { creatingContext.addCloseHook(closeHook); } } else { creatingContext = null; } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createNetClientMetrics(options) : null; logEnabled = options.getLogActivity(); idleTimeout = options.getIdleTimeout(); idleTimeoutUnit = options.getIdleTimeoutUnit(); }
throw new IllegalStateException("Cannot use HttpClient with HTTP_2 in a worker"); creatingContext.addCloseHook(closeHook);
public NetServerImpl(VertxInternal vertx, NetServerOptions options) { this.vertx = vertx; this.options = new NetServerOptions(options); this.sslHelper = new SSLHelper(options, options.getKeyCertOptions(), options.getTrustOptions()); this.creatingContext = vertx.getContext(); this.logEnabled = options.getLogActivity(); if (creatingContext != null) { if (creatingContext.isMultiThreadedWorkerContext()) { throw new IllegalStateException("Cannot use NetServer in a multi-threaded worker verticle"); } creatingContext.addCloseHook(this); } }
public HttpServerImpl(VertxInternal vertx, HttpServerOptions options) { this.options = new HttpServerOptions(options); this.vertx = vertx; this.creatingContext = vertx.getContext(); if (creatingContext != null) { if (creatingContext.isMultiThreadedWorkerContext()) { throw new IllegalStateException("Cannot use HttpServer in a multi-threaded worker verticle"); } creatingContext.addCloseHook(this); } this.sslHelper = new SSLHelper(options, options.getKeyCertOptions(), options.getTrustOptions()); this.subProtocols = options.getWebsocketSubProtocols(); this.logEnabled = options.getLogActivity(); }
@Test public void testCloseHooksCalled() throws Exception { AtomicInteger closedCount = new AtomicInteger(); Closeable myCloseable1 = completionHandler -> { closedCount.incrementAndGet(); completionHandler.handle(Future.succeededFuture()); }; Closeable myCloseable2 = completionHandler -> { closedCount.incrementAndGet(); completionHandler.handle(Future.succeededFuture()); }; MyAsyncVerticle verticle = new MyAsyncVerticle(f-> { ContextInternal ctx = (ContextInternal)Vertx.currentContext(); ctx.addCloseHook(myCloseable1); ctx.addCloseHook(myCloseable2); f.complete(null); }, f -> f.complete(null)); vertx.deployVerticle(verticle, ar -> { assertTrue(ar.succeeded()); assertEquals(0, closedCount.get()); // Now undeploy vertx.undeploy(ar.result(), ar2 -> { assertTrue(ar2.succeeded()); assertEquals(2, closedCount.get()); testComplete(); }); }); await(); }
public NetClientImpl(VertxInternal vertx, NetClientOptions options, boolean useCreatingContext) { this.vertx = vertx; this.options = new NetClientOptions(options); this.sslHelper = new SSLHelper(options, options.getKeyCertOptions(), options.getTrustOptions()); this.closeHook = completionHandler -> { NetClientImpl.this.close(); completionHandler.handle(Future.succeededFuture()); }; if (useCreatingContext) { creatingContext = vertx.getContext(); if (creatingContext != null) { if (creatingContext.isMultiThreadedWorkerContext()) { throw new IllegalStateException("Cannot use NetClient in a multi-threaded worker verticle"); } creatingContext.addCloseHook(closeHook); } } else { creatingContext = null; } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createNetClientMetrics(options) : null; logEnabled = options.getLogActivity(); idleTimeout = options.getIdleTimeout(); idleTimeoutUnit = options.getIdleTimeoutUnit(); }
throw new IllegalStateException("Cannot use HttpClient with HTTP_2 in a worker"); creatingContext.addCloseHook(closeHook);
public VertxServer start(Handler<AsyncResult<Void>> completionHandler) { if (id.port > 0) { actual = map.computeIfAbsent(id, id -> new ActualServer(context.owner(), id, options, builder)); } else { actual = new ActualServer(context.owner(), id, options, builder); } actual.start(context, ar1 -> { if (ar1.succeeded()) { hook = ar2 -> shutdown(); context.addCloseHook(hook); } completionHandler.handle(ar1); }); return this; }