public HandshakeInboundHandler(Handler<WebSocket> wsConnect, boolean supportsContinuation) { this.supportsContinuation = supportsContinuation; this.wsConnect = wsConnect; this.context = vertx.getContext(); }
protected final void checkContext() { // Sanity check if (context != vertx.getContext()) { throw new IllegalStateException("Wrong context!"); } }
private void checkContext() { if (!vertx.getContext().equals(context)) { throw new IllegalStateException("AsyncFile must only be used in the context that created it, expected: " + context + " actual " + vertx.getContext()); } }
private void addToHADeployList(final String verticleName, final DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler) { toDeployOnQuorum.add(() -> { ContextInternal ctx = vertx.getContext(); try { ContextImpl.setContext(null); deployVerticle(verticleName, deploymentOptions, doneHandler); } finally { ContextImpl.setContext((ContextImpl) ctx); } }); }
private void actualClose(final ContextInternal closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedHttpServers().remove(id); } ContextInternal currCon = vertx.getContext(); for (ConnectionBase conn : connectionMap.values()) { conn.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } if (metrics != null) { metrics.close(); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cgf -> executeCloseDone(closeContext, done, fut.cause())); }
private void actualClose(ContextInternal closeContext, Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedNetServers().remove(id); } ContextInternal currCon = vertx.getContext(); for (NetSocketImpl sock : socketMap.values()) { sock.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cg -> { if (metrics != null) { metrics.close(); } executeCloseDone(closeContext, done, fut.cause()); }); }
final AtomicReference<Throwable> err = new AtomicReference<>(); ContextInternal ctx = vertx.getContext(); if (ctx != null) {
private synchronized void checkQuorumWhenAdded(final String nodeID, final long start) { if (clusterMap.containsKey(nodeID)) { checkQuorum(); if (attainedQuorum) { checkSubs(nodeID); } } else { vertx.setTimer(200, tid -> { // This can block on a monitor so it needs to run as a worker vertx.executeBlockingInternal(fut -> { if (System.currentTimeMillis() - start > 10000) { log.warn("Timed out waiting for group information to appear"); } else if (!stopped) { ContextInternal context = vertx.getContext(); try { // Remove any context we have here (from the timer) otherwise will screw things up when verticles are deployed ContextImpl.setContext(null); checkQuorumWhenAdded(nodeID, start); } finally { ContextImpl.setContext((ContextImpl) context); } } fut.complete(); }, null); }); } }
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); } }
ContextInternal creatingContext = vertx.getContext();
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(); }
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(); }
@Test public void testContextsSend() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); CountDownLatch latch = new CountDownLatch(2); vertx.eventBus().consumer(ADDRESS1).handler(msg -> { msg.reply("bar"); contexts.add(((VertxInternal) vertx).getContext()); latch.countDown(); }); vertx.eventBus().send(ADDRESS1, "foo", onSuccess((Message<Object> reply) -> { assertEquals("bar", reply.body()); contexts.add(((VertxInternal) vertx).getContext()); latch.countDown(); })); awaitLatch(latch); assertEquals(2, contexts.size()); }
private void undeployHADeployments() { for (String deploymentID: deploymentManager.deployments()) { Deployment dep = deploymentManager.getDeployment(deploymentID); if (dep != null) { if (dep.deploymentOptions().isHa()) { ContextInternal ctx = vertx.getContext(); try { ContextImpl.setContext(null); deploymentManager.undeployVerticle(deploymentID, result -> { if (result.succeeded()) { log.info("Successfully undeployed HA deployment " + deploymentID + "-" + dep.verticleIdentifier() + " as there is no quorum"); addToHADeployList(dep.verticleIdentifier(), dep.deploymentOptions(), result1 -> { if (result1.succeeded()) { log.info("Successfully redeployed verticle " + dep.verticleIdentifier() + " after quorum was re-attained"); } else { log.error("Failed to redeploy verticle " + dep.verticleIdentifier() + " after quorum was re-attained", result1.cause()); } }); } else { log.error("Failed to undeploy deployment on lost quorum", result.cause()); } }); } finally { ContextImpl.setContext((ContextImpl) ctx); } } } } }
ContextInternal serverContext = ((VertxInternal) vertx).getContext(); if (serverRequestContext.get() != null) { assertSame(serverRequestContext.get(), serverContext); server.listen(ar -> { assertTrue(ar.succeeded()); listenContext.set(((VertxInternal) vertx).getContext()); latch.countDown(); }); client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(resp -> { assertEquals(200, resp.statusCode()); contexts.add(((VertxInternal) vertx).getContext()); if (cnt.incrementAndGet() == numReqs) { int size = contexts.size(); ContextInternal closeContext = ((VertxInternal) vertx).getContext(); assertFalse(contexts.contains(closeContext)); assertNotSame(serverRequestContext.get(), closeContext);
@Test public void testContextsPublish() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); AtomicInteger cnt = new AtomicInteger(); int numHandlers = 10; for (int i = 0; i < numHandlers; i++) { vertx.eventBus().consumer(ADDRESS1).handler(msg -> { contexts.add(((VertxInternal) vertx).getContext()); if (cnt.incrementAndGet() == numHandlers) { assertEquals(numHandlers, contexts.size()); testComplete(); } }); } vertx.eventBus().publish(ADDRESS1, "foo"); await(); }
setApplicationProtocols(alpnVersions); sslHelper.validate(vertx); this.creatingContext = vertx.getContext(); closeHook = completionHandler -> { HttpClientImpl.this.close();
public HandshakeInboundHandler(Handler<WebSocket> wsConnect, boolean supportsContinuation) { this.supportsContinuation = supportsContinuation; this.wsConnect = wsConnect; this.context = vertx.getContext(); }
private void checkContext() { if (!vertx.getContext().equals(context)) { throw new IllegalStateException("AsyncFile must only be used in the context that created it, expected: " + context + " actual " + vertx.getContext()); } }
private void addToHADeployList(final String verticleName, final DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler) { toDeployOnQuorum.add(() -> { ContextInternal ctx = vertx.getContext(); try { ContextImpl.setContext(null); deployVerticle(verticleName, deploymentOptions, doneHandler); } finally { ContextImpl.setContext((ContextImpl) ctx); } }); }