Java Code Examples for io.vertx.core.Future#complete()

The following examples show how to use io.vertx.core.Future#complete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VxmsEndpoint.java    From vxms with Apache License 2.0 6 votes vote down vote up
/**
 * Executes the postConstruct using Reflection. This solves the issue that you can extend from a
 * VxmsEndpoint or use the static invocation of an AbstractVerticle.
 *
 * @param router             the http router handler
 * @param startFuture        the vert.x start future
 * @param registrationObject the object to execute postConstruct
 */
private static void executePostConstruct(AbstractVerticle registrationObject, Router router,
                                         final Future<Void> startFuture) {
    final Stream<ReflectionExecutionWrapper> reflectionExecutionWrapperStream = Stream
            .of(new ReflectionExecutionWrapper("postConstruct",
                            registrationObject, new Object[]{router, startFuture}, startFuture),
                    new ReflectionExecutionWrapper("postConstruct",
                            registrationObject, new Object[]{startFuture, router}, startFuture),
                    new ReflectionExecutionWrapper("postConstruct",
                            registrationObject, new Object[]{startFuture}, startFuture));
    final Optional<ReflectionExecutionWrapper> methodWrapperToInvoke = reflectionExecutionWrapperStream
            .filter(ReflectionExecutionWrapper::isPresent).findFirst();
    methodWrapperToInvoke.ifPresent(ReflectionExecutionWrapper::invoke);
    if (!methodWrapperToInvoke.isPresent() && !startFuture.isComplete()) {
        startFuture.complete();
    }

}
 
Example 2
Source File: ServiceRegistry.java    From nubes with Apache License 2.0 6 votes vote down vote up
public void startAll(Future<Void> future) {
  if (isEmpty()) {
    future.complete();
    return;
  }
  MultipleFutures<Void> futures = new MultipleFutures<>(future);
  futures.addAll(services(), obj -> {
    try {
      introspectService(obj);
    } catch (Exception e) {
      return res -> res.fail(e);
    }
    if (obj instanceof Service) {
      Service service = (Service) obj;
      service.init(vertx, config.json());
      return service::start;
    }
    return null;
  });
  futures.start();
}
 
Example 3
Source File: HighwayServerVerticle.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
// TODO: vert.x 3.8.3 does not update startListen to promise, so we keep use deprecated API now. update in newer version.
protected void startListen(Future<Void> startFuture) {
  // if listen address is not provided, do not fail and maybe a consumer service.
  if (endpointObject == null) {
    LOGGER.warn("highway listen address is not configured, will not listen.");
    startFuture.complete();
    return;
  }

  HighwayServer server = new HighwayServer(endpoint);
  server.init(vertx, SSL_KEY, ar -> {
    if (ar.succeeded()) {
      InetSocketAddress socketAddress = ar.result();
      LOGGER.info("highway listen success. address={}:{}",
          socketAddress.getHostString(),
          socketAddress.getPort());
      startFuture.complete();
      return;
    }

    LOGGER.error(Const.HIGHWAY, ar.cause());
    startFuture.fail(ar.cause());
  });
}
 
Example 4
Source File: DataLoader.java    From vertx-dataloader with Apache License 2.0 6 votes vote down vote up
/**
 * Requests to load the data with the specified key asynchronously, and returns a future of the resulting value.
 * <p>
 * If batching is enabled (the default), you'll have to call {@link DataLoader#dispatch()} at a later stage to
 * start batch execution. If you forget this call the future will never be completed (unless already completed,
 * and returned from cache).
 *
 * @param key the key to load
 * @return the future of the value
 */
public Future<V> load(K key) {
    Objects.requireNonNull(key, "Key cannot be null");
    Object cacheKey = getCacheKey(key);
    if (loaderOptions.cachingEnabled() && futureCache.containsKey(cacheKey)) {
        return futureCache.get(cacheKey);
    }

    Future<V> future = Future.future();
    if (loaderOptions.batchingEnabled()) {
        loaderQueue.put(key, future);
    } else {
        CompositeFuture compositeFuture = batchLoadFunction.load(Collections.singleton(key));
        if (compositeFuture.succeeded()) {
            future.complete(compositeFuture.result().resultAt(0));
        } else {
            future.fail(compositeFuture.cause());
        }
    }
    if (loaderOptions.cachingEnabled()) {
        futureCache.set(cacheKey, future);
    }
    return future;
}
 
Example 5
Source File: WeldVerticle.java    From weld-vertx with Apache License 2.0 6 votes vote down vote up
@Override
public void stop(Future<Void> stopFuture) throws Exception {
    if (weldContainer != null && weldContainer.isRunning()) {
        // Shutdown can take some time to complete
        vertx.executeBlocking(future -> {
            try {
                weldContainer.shutdown();
                future.complete();
            } catch (Exception e) {
                future.fail(e);
            }
        }, result -> {
            if (result.succeeded()) {
                stopFuture.complete();
            } else {
                stopFuture.fail(result.cause());
            }
        });
    } else {
        stopFuture.complete();
    }
}
 
Example 6
Source File: MyFirstVerticle.java    From my-vertx-first-app with Apache License 2.0 5 votes vote down vote up
private void completeStartup(AsyncResult<HttpServer> http, Future<Void> fut) {
  if (http.succeeded()) {
    fut.complete();
  } else {
    fut.fail(http.cause());
  }
}
 
Example 7
Source File: SimpleVerticle.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {
    int httpPort = config().getInteger("http.port");
    System.out.println("Configured HTTP Port is :" + httpPort);
    startFuture.complete();
    vertx.close();
}
 
Example 8
Source File: SimpleVerticle.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {
    int httpPort = config().getInteger("http.port");
    System.out.println("Configured HTTP Port is :" + httpPort);
    startFuture.complete();
    vertx.close();
}
 
Example 9
Source File: AuditVerticle.java    From microtrader with MIT License 5 votes vote down vote up
/**
 * A utility method returning a `Handler<SQLConnection>`
 *
 * @param future     the future.
 * @param connection the connection
 * @return the handler.
 */
private static Handler<AsyncResult<Void>> completer(Future<SQLConnection> future, SQLConnection connection) {
    return ar -> {
        if (ar.failed()) {
            future.fail(ar.cause());
        } else {
            future.complete(connection);
        }
    };
}
 
Example 10
Source File: ConvertUtil.java    From gushici with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param obj base64 加密后的图片
 * @return Buffer 流
 */
public static Future<Buffer> getImageFromBase64(String obj) {
    Future<Buffer> result = Future.future();
    if (obj == null) {
        result.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 500, "图片读取失败"));
        return result;
    }

    Base64.Decoder decoder = Base64.getDecoder();
    byte[] bs;
    bs = decoder.decode(obj);
    Buffer buffer = Buffer.buffer(bs);
    result.complete(buffer);
    return result;
}
 
Example 11
Source File: VxmsGateway.java    From vxms with Apache License 2.0 5 votes vote down vote up
@Override
public void postConstruct(final Future<Void> startFuture) {
  // for demo purposes
//  InitMongoDB.initMongoData(vertx, config());
  startFuture.complete();

}
 
Example 12
Source File: SimpleREST.java    From vxms with Apache License 2.0 4 votes vote down vote up
@Override
public void postConstruct(Router router, final Future<Void> startFuture) {
    router.get("/helloGET").handler(getSimpleResponse());
    router.get("/helloGET/:name").handler(getName());
    startFuture.complete();
}
 
Example 13
Source File: SimpleVerticle.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {
    startFuture.complete();

    vertx.close();
}
 
Example 14
Source File: AnnotatedVerticle.java    From nubes with Apache License 2.0 4 votes vote down vote up
@Override
public void stop(Future<Void> future) {
  isStarted.set(false);
  future.complete();
}
 
Example 15
Source File: UsersWriteToMongo.java    From vxms with Apache License 2.0 4 votes vote down vote up
@Override
public void postConstruct(final Future<Void> startFuture) {
  service = new UserService(InitMongoDB.initMongoData(vertx, config()));
  startFuture.complete();
}
 
Example 16
Source File: DogService.java    From nubes with Apache License 2.0 4 votes vote down vote up
@Override
public void stop(Future<Void> future) {
  dogs.clear();
  future.complete();
}
 
Example 17
Source File: VxmsGateway.java    From vxms with Apache License 2.0 4 votes vote down vote up
private void checkHealth(Future<String> future) {
  future.complete("Ready");
}
 
Example 18
Source File: SimpleVerticle.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {
    startFuture.complete();

    vertx.close();
}
 
Example 19
Source File: VxmsGateway.java    From vxms with Apache License 2.0 4 votes vote down vote up
@Override
public void postConstruct(final Future<Void> startFuture) {

  startFuture.complete();
}
 
Example 20
Source File: UsersWriteToMongo.java    From vxms with Apache License 2.0 4 votes vote down vote up
@Override
public void postConstruct(final Future<Void> startFuture) {
    mongo = InitMongoDB.initMongoData(vertx, config());
    startFuture.complete();
}