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