public void reportException(Throwable t) { Context ctx = getContext(); if (ctx != null) { ctx.reportException(t); } else { log.error(" default vertx Unhandled exception ", t); } }
private void checkContext() { if (!Context.getContext().equals(context)) { throw new IllegalStateException( "AsyncFile must only be used in the context that created it, expected: " + context + " actual " + Context.getContext()); } }
public void runOnLoop(final Handler<Void> handler) { Context context = getOrAssignContext(); context.execute( new Runnable() { public void run() { handler.handle(null); } }); }
private VerticleHolder getVerticleHolder() { Context context = vertx.getContext(); if (context != null) { VerticleHolder holder = (VerticleHolder) context.getDeploymentHandle(); return holder; } else { return null; } }
// Must be synchronized since called directly from different thread private void addVerticle(Deployment deployment, Verticle verticle, VerticleFactory factory) { String loggerName = "org.vertx.deployments." + deployment.name + "-" + deployment.verticles.size(); Logger logger = LoggerFactory.getLogger(loggerName); Context context = vertx.getContext(); VerticleHolder holder = new VerticleHolder( deployment, context, verticle, loggerName, logger, deployment.config, factory); deployment.verticles.add(holder); context.setDeploymentHandle(holder); }
private void actualClose(final Context closeContext, final Handler<Void> done) { if (id != null) { vertx.sharedNetServers().remove(id); } for (DefaultNetSocket sock : socketMap.values()) { sock.internalClose(); } // We need to reset it since sock.internalClose() above can call into the close handlers of // sockets on the same thread // which can cause context id for the thread to change! Context.setContext(closeContext); ChannelGroupFuture fut = serverChannelGroup.close(); if (done != null) { fut.addListener( new ChannelGroupFutureListener() { public void operationComplete(ChannelGroupFuture channelGroupFuture) throws Exception { executeCloseDone(closeContext, done); } }); } }
public boolean isWorker() { Context context = Context.getContext(); if (context != null) { return context instanceof WorkerContext; } return false; }
public boolean isEventLoop() { Context context = Context.getContext(); if (context != null) { return context instanceof EventLoopContext; } return false; }
private void executeCloseDone(final Context closeContext, final Handler<Void> done) { closeContext.execute( new Runnable() { public void run() { done.handle(null); } }); }
private void runOnContext(final Context context, final Runnable runnable) { context.execute( new Runnable() { public void run() { runnable.run(); } }); }
public Context getOrAssignContext() { Context ctx = Context.getContext(); if (ctx == null) { // Assign a context ctx = createEventLoopContext(); } return ctx; }
public DefaultNetServer(VertxInternal vertx) { this.vertx = vertx; ctx = vertx.getOrAssignContext(); if (vertx.isWorker()) { throw new IllegalStateException("Cannot be used in a worker application"); } ctx.addCloseHook( new Runnable() { public void run() { close(); } }); tcpHelper.setReuseAddress(true); }
protected void setContext() { Context.setContext(context); }
public void setContext(Context context) { contextTL.set(context); if (context != null) { context.setTCCL(); } }
public Context startInBackground(final Runnable runnable) { Context context = createWorkerContext(); context.execute(runnable); return context; }
public Context startOnEventLoop(final Runnable runnable) { Context context = createEventLoopContext(); context.execute(runnable); return context; }