Example usage for io.vertx.core VertxOptions getClusterHost

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

Introduction

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

Prototype

@Deprecated
public String getClusterHost() 

Source Link

Document

Get the host name to be used for clustering.

Usage

From source file:org.wisdom.framework.vertx.VertxSingleton.java

License:Apache License

/**
 * Creates and exposed the instance of Vert.X.
 *///from w ww. j  ava  2  s  .c o m
@Validate
public void start() {
    final Configuration configuration = appConfiguration.getConfiguration("vertx");

    String log = System.getProperty("org.vertx.logger-delegate-factory-class-name");
    if (log == null) {
        // No logging backend configured, set one:
        System.setProperty("org.vertx.logger-delegate-factory-class-name",
                SLF4JLogDelegateFactory.class.getName());
    }

    VertxOptions options = new VertxOptions();
    boolean clustered = false;
    if (configuration != null) {
        clustered = configuration.getBooleanWithDefault("clustered", false);
        options = new VertxOptions(new JsonObject(configuration.asMap()));

        if (clustered) {
            options.setClustered(true).setClusterHost(configuration.getOrDie("cluster-host"));
            // Identify port and configuration file
            String clusterConfig = configuration.getWithDefault("cluster-config", "conf/cluster.xml");
            System.setProperty("hazelcast.config", new File(clusterConfig).getAbsolutePath());
        }
    }

    // To setup the logging backend, Vert.x needs a TTCL.
    final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

        Hashtable<String, Object> properties = new Hashtable<>();
        if (clustered) {
            options.setClusterManager(new HazelcastClusterManager());
            String host = options.getClusterHost();
            properties.put("eventbus.host", host);
            Vertx.clusteredVertx(options, ar -> {
                if (ar.failed()) {
                    throw new IllegalStateException("Cannot join cluster", ar.cause());
                }
                vertx = ar.result();
                vertxRegistration = context.registerService(Vertx.class, vertx, properties);
                busRegistration = context.registerService(EventBus.class, vertx.eventBus(), properties);
            });
        } else {
            // Not a clustered environment
            vertx = Vertx.vertx(options);
            vertxRegistration = context.registerService(Vertx.class, vertx, properties);
            busRegistration = context.registerService(EventBus.class, vertx.eventBus(), properties);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }
}