Example usage for io.vertx.core Future succeededFuture

List of usage examples for io.vertx.core Future succeededFuture

Introduction

In this page you can find the example usage for io.vertx.core Future succeededFuture.

Prototype

static <T> Future<T> succeededFuture() 

Source Link

Document

Create a succeeded future with a null result

Usage

From source file:org.eclipse.hono.messaging.HonoMessaging.java

License:Open Source License

@Override
protected Future<Void> preStartServers() {

    checkStandardEndpointsAreRegistered();
    logStartupMessage();
    return Future.succeededFuture();
}

From source file:org.eclipse.hono.messaging.MessageDiscardingDownstreamAdapter.java

License:Open Source License

@Override
public void onClientAttach(UpstreamReceiver client, Handler<AsyncResult<Void>> resultHandler) {
    client.replenish(DEFAULT_CREDIT);/*  ww  w. j a v a  2 s  . c o  m*/
    resultHandler.handle(Future.succeededFuture());
}

From source file:org.eclipse.hono.messaging.UpstreamReceiverImpl.java

License:Open Source License

@Override
public void drain(final long timeoutMillis, final Handler<AsyncResult<Void>> drainCompletionHandler) {
    if (drainFlag.compareAndSet(false, true)) {
        LOG.debug("draining client [{}]", id);
        link.drain(timeoutMillis, result -> {
            drainFlag.set(false);/*from w ww.  j a va 2s.com*/
            drainCompletionHandler.handle(result);
        });
    } else {
        // already draining
        LOG.debug("already draining client, discarding additional drain request");
        drainCompletionHandler.handle(Future.succeededFuture());
    }
}

From source file:org.eclipse.hono.server.ForwardingDownstreamAdapter.java

License:Open Source License

@Override
public final void onClientAttach(final UpstreamReceiver client,
        final Handler<AsyncResult<Void>> resultHandler) {

    if (!running) {
        throw new IllegalStateException("adapter must be started first");
    }//from w  w w . j  ava  2  s  .co  m

    Objects.requireNonNull(client);
    Objects.requireNonNull(resultHandler);

    ProtonSender sender = activeSenders.get(client);
    if (sender != null && sender.isOpen()) {
        logger.info("reusing existing downstream sender [con: {}, link: {}]", client.getConnectionId(),
                client.getLinkId());
        resultHandler.handle(Future.succeededFuture());
    } else {
        removeSender(client);
        // register the result handler to be failed if the connection to the downstream container fails during
        // the attempt to create a downstream sender
        clientAttachHandlers.add(resultHandler);
        Future<Void> tracker = Future.future();
        tracker.setHandler(attempt -> {
            if (attempt.succeeded()) {
                logger.info("created downstream sender [con: {}, link: {}]", client.getConnectionId(),
                        client.getLinkId());
            } else {
                logger.warn("can't create downstream sender [con: {}, link: {}]", client.getConnectionId(),
                        client.getLinkId(), attempt.cause());
            }
            clientAttachHandlers.remove(resultHandler);
            resultHandler.handle(attempt);
        });

        createSender(client.getTargetAddress(), replenishedSender -> handleFlow(replenishedSender, client))
                .compose(createdSender -> {
                    addSender(client, createdSender);
                    tracker.complete();
                }, tracker);
    }
}

From source file:org.eclipse.hono.service.AbstractApplication.java

License:Open Source License

/**
 * Invoked before the service instances are being deployed.
 * <p>//from  w w w.j av a2  s . c  o m
 * May be overridden to prepare the environment for the service instances,
 * e.g. deploying additional (prerequisite) verticles.
 * <p>
 * This default implementation simply returns a succeeded future.
 * 
 * @param maxInstances The number of service verticle instances to deploy.
 * @return A future indicating success. Application start-up fails if the
 *         returned future fails.
 */
protected Future<Void> deployRequiredVerticles(final int maxInstances) {
    return Future.succeededFuture();
}

From source file:org.eclipse.hono.service.AbstractApplication.java

License:Open Source License

private Future<Void> stopHealthCheckServer() {
    if (healthCheckServer != null) {
        return healthCheckServer.stop();
    } else {// w  ww  . ja va 2s. c  o m
        return Future.succeededFuture();
    }
}

From source file:org.eclipse.hono.service.AbstractApplication.java

License:Open Source License

/**
 * Invoked after the service instances have been deployed successfully.
 * <p>/*from www  .  j  a  v  a 2 s  .  co  m*/
 * May be overridden to provide additional startup logic, e.g. deploying
 * additional verticles.
 * <p>
 * This default implementation simply returns a succeeded future.
 * 
 * @return A future indicating success. Application start-up fails if the
 *         returned future fails.
 */
protected Future<Void> postRegisterServiceVerticles() {
    return Future.succeededFuture();
}

From source file:org.eclipse.hono.service.AbstractProtocolAdapterBase.java

License:Open Source License

/**
 * Closes the connections to the Hono Messaging component and the Device Registration service.
 * //from  ww  w .jav a  2  s . com
 * @param closeHandler The handler to notify about the result.
 */
protected final void closeClients(final Handler<AsyncResult<Void>> closeHandler) {

    Future<Void> messagingTracker = Future.future();
    Future<Void> registrationTracker = Future.future();
    Future<Void> credentialsTracker = Future.future();

    if (messaging == null) {
        messagingTracker.complete();
    } else {
        messaging.shutdown(messagingTracker.completer());
    }

    if (registration == null) {
        registrationTracker.complete();
    } else {
        registration.shutdown(registrationTracker.completer());
    }

    if (credentials == null) {
        credentialsTracker.complete();
    } else {
        credentials.shutdown(credentialsTracker.completer());
    }

    CompositeFuture.all(messagingTracker, registrationTracker, credentialsTracker).setHandler(s -> {
        if (closeHandler != null) {
            if (s.succeeded()) {
                closeHandler.handle(Future.succeededFuture());
            } else {
                closeHandler.handle(Future.failedFuture(s.cause()));
            }
        }
    });
}

From source file:org.eclipse.hono.service.amqp.AmqpServiceBase.java

License:Open Source License

/**
 * Invoked before binding listeners to the configured socket addresses.
 * <p>//www.ja  v  a2  s  .c  om
 * Subclasses may override this method to do any kind of initialization work.
 * 
 * @return A future indicating the outcome of the operation. The listeners will not
 *         be bound if the returned future fails.
 */
protected Future<Void> preStartServers() {
    return Future.succeededFuture();
}

From source file:org.eclipse.hono.service.amqp.AmqpServiceBase.java

License:Open Source License

private Future<Void> startInsecureServer() {

    if (isInsecurePortEnabled()) {
        int insecurePort = determineInsecurePort();
        final Future<Void> result = Future.future();
        final ProtonServerOptions options = createInsecureServerOptions();
        insecureServer = createProtonServer(options).connectHandler(this::onRemoteConnectionOpenInsecurePort)
                .listen(insecurePort, getConfig().getInsecurePortBindAddress(), bindAttempt -> {
                    if (bindAttempt.succeeded()) {
                        if (getInsecurePort() == getInsecurePortDefaultValue()) {
                            LOG.info("server listens on standard insecure port [{}:{}]",
                                    getInsecurePortBindAddress(), getInsecurePort());
                        } else {
                            LOG.warn("server listens on non-standard insecure port [{}:{}], default is {}",
                                    getInsecurePortBindAddress(), getInsecurePort(),
                                    getInsecurePortDefaultValue());
                        }//from  w  ww .j  av a  2 s. co  m
                        result.complete();
                    } else {
                        LOG.error("cannot bind to insecure port", bindAttempt.cause());
                        result.fail(bindAttempt.cause());
                    }
                });
        return result;
    } else {
        LOG.info("insecure port is not enabled");
        return Future.succeededFuture();
    }
}