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