static void setContext(ContextImpl context) { Thread current = Thread.currentThread(); if (current instanceof VertxThread) { setContext((VertxThread) current, context); } else { throw new IllegalStateException("Attempt to setContext on non Vert.x thread " + Thread.currentThread()); } }
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); } }); }
<T> boolean executeTask(T arg, Handler<T> hTask) { Thread th = Thread.currentThread(); if (!(th instanceof VertxThread)) { throw new IllegalStateException("Uh oh! context executing with wrong thread! " + th); } VertxThread current = (VertxThread) th; if (!DISABLE_TIMINGS) { current.executeStart(); } try { setContext(current, this); hTask.handle(arg); return true; } catch (Throwable t) { reportException(t); return false; } finally { // We don't unset the context after execution - this is done later when the context is closed via // VertxThreadFactory if (!DISABLE_TIMINGS) { current.executeEnd(); } } }
if (ctx != null) { ContextImpl.setContext(null); } finally { if (ctx != null) { ContextImpl.setContext((ContextImpl) ctx);
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); }); } }
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); } } } } }
ContextImpl.setContext(this); blockingCodeHandler.handle(res); } catch (Throwable e) {
static void setContext(ContextImpl context) { Thread current = Thread.currentThread(); if (current instanceof VertxThread) { setContext((VertxThread) current, context); } else { throw new IllegalStateException("Attempt to setContext on non Vert.x thread " + Thread.currentThread()); } }
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); } }); }
<T> boolean executeTask(T arg, Handler<T> hTask) { Thread th = Thread.currentThread(); if (!(th instanceof VertxThread)) { throw new IllegalStateException("Uh oh! context executing with wrong thread! " + th); } VertxThread current = (VertxThread) th; if (!DISABLE_TIMINGS) { current.executeStart(); } try { setContext(current, this); hTask.handle(arg); return true; } catch (Throwable t) { reportException(t); return false; } finally { // We don't unset the context after execution - this is done later when the context is closed via // VertxThreadFactory if (!DISABLE_TIMINGS) { current.executeEnd(); } } }
if (ctx != null) { ContextImpl.setContext(null); } finally { if (ctx != null) { ContextImpl.setContext((ContextImpl) ctx);
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); }); } }
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); } } } } }
ContextImpl.setContext(this); blockingCodeHandler.handle(res); } catch (Throwable e) {