Example #1
0
 public void reportException(Throwable t) {
   Context ctx = getContext();
   if (ctx != null) {
     ctx.reportException(t);
   } else {
     log.error(" default vertx Unhandled exception ", t);
   }
 }
Example #2
0
 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());
   }
 }
Example #3
0
 public void runOnLoop(final Handler<Void> handler) {
   Context context = getOrAssignContext();
   context.execute(
       new Runnable() {
         public void run() {
           handler.handle(null);
         }
       });
 }
Example #4
0
 private VerticleHolder getVerticleHolder() {
   Context context = vertx.getContext();
   if (context != null) {
     VerticleHolder holder = (VerticleHolder) context.getDeploymentHandle();
     return holder;
   } else {
     return null;
   }
 }
Example #5
0
 // 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);
 }
Example #6
0
  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);
            }
          });
    }
  }
Example #7
0
 public boolean isWorker() {
   Context context = Context.getContext();
   if (context != null) {
     return context instanceof WorkerContext;
   }
   return false;
 }
Example #8
0
 public boolean isEventLoop() {
   Context context = Context.getContext();
   if (context != null) {
     return context instanceof EventLoopContext;
   }
   return false;
 }
Example #9
0
 private void executeCloseDone(final Context closeContext, final Handler<Void> done) {
   closeContext.execute(
       new Runnable() {
         public void run() {
           done.handle(null);
         }
       });
 }
Example #10
0
 private void runOnContext(final Context context, final Runnable runnable) {
   context.execute(
       new Runnable() {
         public void run() {
           runnable.run();
         }
       });
 }
Example #11
0
 public Context getOrAssignContext() {
   Context ctx = Context.getContext();
   if (ctx == null) {
     // Assign a context
     ctx = createEventLoopContext();
   }
   return ctx;
 }
Example #12
0
 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);
 }
Example #13
0
 protected void setContext() {
   Context.setContext(context);
 }
Example #14
0
 public void setContext(Context context) {
   contextTL.set(context);
   if (context != null) {
     context.setTCCL();
   }
 }
Example #15
0
 public Context startInBackground(final Runnable runnable) {
   Context context = createWorkerContext();
   context.execute(runnable);
   return context;
 }
Example #16
0
 public Context startOnEventLoop(final Runnable runnable) {
   Context context = createEventLoopContext();
   context.execute(runnable);
   return context;
 }