Example usage for io.vertx.core VertxOptions setClusterPort

List of usage examples for io.vertx.core VertxOptions setClusterPort

Introduction

In this page you can find the example usage for io.vertx.core VertxOptions setClusterPort.

Prototype

@Deprecated
public VertxOptions setClusterPort(int clusterPort) 

Source Link

Document

Set the port to be used for clustering.

Usage

From source file:com.consol.citrus.vertx.factory.AbstractVertxInstanceFactory.java

License:Apache License

/**
 * Creates new Vert.x instance with default factory. Subclasses may overwrite this
 * method in order to provide special Vert.x instance.
 * @return/*w  w w .  j  a va2  s  . c  o m*/
 */
protected Vertx createVertx(VertxEndpointConfiguration endpointConfiguration) {
    final Vertx[] vertx = new Vertx[1];
    final Future loading = new FutureFactoryImpl().future();

    Handler<AsyncResult<Vertx>> asyncLoadingHandler = new Handler<AsyncResult<Vertx>>() {
        @Override
        public void handle(AsyncResult<Vertx> event) {
            vertx[0] = event.result();
            loading.complete();
            log.info("Vert.x instance started");
        }
    };

    if (endpointConfiguration.getPort() > 0) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Creating new Vert.x instance '%s:%s' ...", endpointConfiguration.getHost(),
                    endpointConfiguration.getPort()));
        }
        VertxOptions vertxOptions = new VertxOptions();
        vertxOptions.setClusterPort(endpointConfiguration.getPort());
        vertxOptions.setClusterHost(endpointConfiguration.getHost());
        vertxFactory.clusteredVertx(vertxOptions, asyncLoadingHandler);
    } else {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Creating new Vert.x instance '%s:%s' ...", endpointConfiguration.getHost(),
                    0L));
        }
        VertxOptions vertxOptions = new VertxOptions();
        vertxOptions.setClusterPort(0);
        vertxOptions.setClusterHost(endpointConfiguration.getHost());
        vertxFactory.clusteredVertx(vertxOptions, asyncLoadingHandler);
    }

    // Wait for full loading
    while (!loading.isComplete()) {
        try {
            log.debug("Waiting for Vert.x instance to startup");
            Thread.sleep(250L);
        } catch (InterruptedException e) {
            log.warn("Interrupted while waiting for Vert.x instance startup", e);
        }
    }

    return vertx[0];
}

From source file:net.kuujo.copycat.vertx.VertxEventBusProtocol.java

License:Apache License

/**
 * Creates a Vert.x instance.// ww  w  .j  a  va2 s. c  o  m
 */
private Vertx createVertx() {
    VertxOptions options = new VertxOptions();
    options.setClusterPort(getPort());
    options.setClusterHost(getHost());
    Vertx vertx = Vertx.vertx(options);
    setVertx(vertx);
    return vertx;
}

From source file:scp.targets.vertx.CommunicationManagerImpl.java

License:Open Source License

/**
 * Instantiates a new Communication manager impl based on clustered Vertx instance.
 *
 * @param port the port.  If this argument is 0, then the system will pick the port.
 * @param hostname the hostname//from w  ww.  j  ava  2 s. co  m
 */
public CommunicationManagerImpl(int port, String hostname) {
    final Semaphore _sem = new Semaphore(0);
    final Handler<AsyncResult<Vertx>> _handler = event -> {
        try {
            if (event.succeeded()) {
                LOGGER.info("Vertx creation succeeded");
                CommunicationManagerImpl.this.vertx = event.result();
            } else {
                LOGGER.error("Vertx creation failed");
                throw new RuntimeException("Could not initialize Communication manager", event.cause());
            }
        } finally {
            _sem.release();
        }
    };
    final VertxOptions _opt = new VertxOptions();
    _opt.setClustered(true);
    _opt.setClusterHost(hostname);
    _opt.setClusterPort(port);
    Vertx.clusteredVertx(_opt, _handler);

    try {
        _sem.acquire();
    } catch (final InterruptedException _e) {
        final String _msg = "Why did the semaphore encountered InterruptedException?";
        LOGGER.error(_msg, _e);
        throw new RuntimeException(_msg, _e);
    }

    assert this.vertx != null;
}