List of usage examples for io.vertx.core AsyncResult AsyncResult
AsyncResult
From source file:io.apiman.rls.vertx.TaskExecutor.java
License:Apache License
/** * Constructor.//from w w w. j ava 2 s. c om * @param executorId * @param vertx */ public TaskExecutor(int executorId, Vertx vertx) { this.vertx = vertx; log.debug("{0} :: Creating task executor {1}", Thread.currentThread(), executorId); //$NON-NLS-1$ this.executorId = executorId; thread = new Thread(() -> { while (Boolean.TRUE) { TaskAndStuff taskAndStuff = null; try { taskAndStuff = queue.take(); log.debug("{0} :: Task received by executor, processing.", Thread.currentThread()); //$NON-NLS-1$ final Object rval = taskAndStuff.task.execute(); AsyncResult result = new AsyncResult() { @Override public Object result() { return rval; } @Override public Throwable cause() { return null; } @Override public boolean succeeded() { return true; } @Override public boolean failed() { return false; } }; log.debug("{0} :: Task executed. Result: {1}", Thread.currentThread(), rval); //$NON-NLS-1$ final AsyncResultHandler handler = taskAndStuff.handler; taskAndStuff.context.runOnContext((v1) -> { log.debug("{0} :: Calling the async result handler: {1}", Thread.currentThread(), handler); //$NON-NLS-1$ handler.handle(result); }); log.debug("{0} :: Task handler scheduled to be run on context: {1}", Thread.currentThread(), //$NON-NLS-1$ taskAndStuff.context); } catch (InterruptedException e) { // skip - keep trying! } catch (Exception e) { AsyncResult result = new AsyncResult() { @Override public Object result() { return null; } @Override public Throwable cause() { return e; } @Override public boolean succeeded() { return false; } @Override public boolean failed() { return true; } }; final AsyncResultHandler handler = taskAndStuff.handler; taskAndStuff.context.runOnContext((v1) -> { handler.handle(result); }); } } }); thread.setName("TaskExecutor-" + this.executorId); //$NON-NLS-1$ thread.setDaemon(true); thread.start(); }
From source file:org.mustertech.webapp.vertxutils.VerticleDeployer.java
License:Open Source License
private static <T> AsyncResult<T> makeAsyncResult(Throwable cause, T result) { AsyncResult<T> ar;/*from w w w.j a va2 s .c o m*/ if (null != cause) { ar = new AsyncResult<T>() { public Throwable cause() { return cause; } public boolean failed() { return true; } public T result() { return null; } public boolean succeeded() { return false; } }; } else { ar = new AsyncResult<T>() { public Throwable cause() { return null; } public boolean failed() { return false; } public T result() { return result; } public boolean succeeded() { return true; } }; } return ar; }
From source file:org.schors.flibot.DBServiceImpl.java
License:Open Source License
public static AsyncResult<JsonObject> makeAsyncResult(final JsonObject result, final Throwable cause, final boolean success) { return new AsyncResult<JsonObject>() { @Override/*from w w w. j ava 2 s .c o m*/ public JsonObject result() { return result; } @Override public Throwable cause() { return cause; } @Override public boolean succeeded() { return success; } @Override public boolean failed() { return !success; } }; }
From source file:org.schors.flibot.Util.java
License:Open Source License
public static AsyncResult createResult(boolean success, Object result, Throwable e) { return new AsyncResult() { @Override//w w w . j av a2 s. co m public Object result() { return result; } @Override public Throwable cause() { return e; } @Override public boolean succeeded() { return success; } @Override public boolean failed() { return !success; } }; }