All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.scalecube.issues.i187.SeedRunner Maven / Gradle / Ivy

package io.scalecube.issues.i187;

import io.scalecube.cluster.Cluster;
import io.scalecube.cluster.ClusterConfig;
import io.scalecube.cluster.ClusterImpl;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SeedRunner {

  public static final Logger logger = LoggerFactory.getLogger(SeedRunner.class);

  public static final int DEFALT_PORT = 4545;

  /**
   * Maibn.
   *
   * @param args args
   * @throws Exception exception
   */
  public static void main(String[] args) throws Exception {
    int port = getPort(args).orElse(DEFALT_PORT);

    Map metadata =
        Collections.singletonMap("seed", Integer.toHexString(new Object().hashCode()));

    ClusterConfig config =
        new ClusterConfig()
            .membership(opts -> opts.syncGroup("issue187").syncInterval(1000).syncTimeout(1000))
            .transport(opts -> opts.connectTimeout(1000).port(port))
            .metadata(metadata)
            .metadataTimeout(1000);

    logger.debug("Starting Seed with config {}", config);
    Cluster cluster = new ClusterImpl(config).startAwait();
    logger.debug("Started Seed: {}, address: {}", cluster, cluster.address());

    Thread.currentThread().join();
  }

  private static Optional getPort(String[] args) {
    if (args.length < 1) {
      return Optional.empty();
    }
    String portArg = args[0];
    if (portArg.isEmpty()) {
      return Optional.empty();
    }
    try {
      return Optional.of(Integer.parseInt(portArg));
    } catch (Exception ex) {
      logger.error("Error in getPort: " + ex);
      return Optional.empty();
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy