List of usage examples for io.vertx.core Future cause
@Override Throwable cause();
From source file:com.dinstone.vertx.web.core.AbstractRouteResolver.java
License:Apache License
private static Handler<RoutingContext> asyncHandler(final Object service, final RouteDefinition definition, RouterContext routerContext) {/*from ww w. j a v a 2 s. co m*/ return context -> { try { Object[] args = prepareArguments(context, definition, routerContext); Object result = definition.getMethod().invoke(service, args); if (result instanceof Future) { Future<?> future = (Future<?>) result; // wait for future to complete ... don't block vertx event bus in the mean time future.setHandler(handler -> { if (future.succeeded()) { try { Object futureResult = future.result(); handleResponse(futureResult, context, definition, routerContext); } catch (Throwable e) { handleException(e, context, definition, routerContext); } } else { handleException(future.cause(), context, definition, routerContext); } }); } } catch (Throwable e) { handleException(e, context, definition, routerContext); } }; }
From source file:com.englishtown.vertx.hk2.HK2VerticleLoader.java
License:Open Source License
/** * Vert.x calls the stop method when the verticle is undeployed. * Put any cleanup code for your verticle in here * * @throws Exception//www . j a v a 2s . c o m */ @Override public void stop(Future<Void> stopFuture) throws Exception { classLoader = null; parent = null; Future<Void> future = Future.future(); future.setHandler(result -> { // Destroy the service locator ServiceLocatorFactory.getInstance().destroy(locator); locator = null; // Pass result to the stop future if (result.succeeded()) { stopFuture.complete(); } else { stopFuture.fail(future.cause()); } }); try { // Stop the real verticle if (realVerticle != null) { realVerticle.stop(future); } else { future.complete(); } } catch (Throwable t) { future.fail(t); } }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void indexValue(String id, String fieldName, RedissonIndex index, JsonObject instance, AsyncResultHandler<Boolean> resultHandler) { try {/*from ww w . j a va2s . c o m*/ Object value = instance.getValue(fieldName); String resolve = index.valueResolver().newInstance().resolve(value, instance, id, fieldName, index); GenericFutureListener<io.netty.util.concurrent.Future<Boolean>> futureListener = ( io.netty.util.concurrent.Future<Boolean> future) -> { resultHandler .handle(future.isSuccess() && future.get() != null ? Future.succeededFuture(future.get()) : Future.failedFuture(future.cause())); }; if (index.scoreResolver().isAssignableFrom(LexicalScoreResolver.class)) { redissonOther.getLexSortedSet(getScoredSortedIndexKey(fieldName, index.name())).addAsync(resolve) .addListener(futureListener); } else { Double score = index.scoreResolver().newInstance().resolve(value, instance, id, fieldName, index); redissonOther .getScoredSortedSet(getScoredSortedIndexKey(fieldName, index.name()), StringCodec.INSTANCE) .addAsync(score, resolve).addListener(futureListener); } } catch (InstantiationException | IllegalAccessException | RuntimeException e) { resultHandler.handle(Future.failedFuture(e)); } }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void unindexValue(String id, String fieldName, RedissonIndex index, JsonObject instance, AsyncResultHandler<Boolean> resultHandler) { try {/* w ww.j a v a 2s . c o m*/ Object value = instance.getValue(fieldName); String resolve = index.valueResolver().newInstance().resolve(value, instance, id, fieldName, index); GenericFutureListener<io.netty.util.concurrent.Future<Boolean>> futureListener = ( io.netty.util.concurrent.Future<Boolean> future) -> { resultHandler .handle(future.isSuccess() && future.get() != null ? Future.succeededFuture(future.get()) : Future.failedFuture(future.cause())); }; if (index.scoreResolver().isAssignableFrom(LexicalScoreResolver.class)) { redissonOther.getLexSortedSet(getScoredSortedIndexKey(fieldName, index.name())).removeAsync(resolve) .addListener(futureListener); } else { redissonOther .getScoredSortedSet(getScoredSortedIndexKey(fieldName, index.name()), StringCodec.INSTANCE) .removeAsync(resolve).addListener(futureListener); } } catch (InstantiationException | IllegalAccessException | RuntimeException e) { resultHandler.handle(Future.failedFuture(e)); } }