public static void main()

in pekko-sample-sharding-java/killrweather/src/main/java/sample/killrweather/KillrWeather.java [20:49]


  public static void main(String[] args) throws Exception {
    List<Integer> seedNodePorts =
        ConfigFactory.load().getStringList("pekko.cluster.seed-nodes")
          .stream()
          .map(AddressFromURIString::parse)
          .map(addr -> (Integer) addr.port().get()) // Missing Java getter for port
          .collect(Collectors.toList());

    // Either use a single port provided by the user
    // Or start each listed seed nodes port plus one node on a random port in this single JVM if the user
    // didn't provide args for the app
    // In a production application you wouldn't start multiple ActorSystem instances in the
    // same JVM, here we do it to simplify running a sample cluster from a single main method.
    List<Integer> ports = Arrays.stream(args).findFirst().map(str ->
      Collections.singletonList(Integer.parseInt(str))
    ).orElseGet(() -> {
      List<Integer> portsAndZero = new ArrayList<>(seedNodePorts);
      portsAndZero.add(0);
      return portsAndZero;
    });

    for (int port : ports) {
      final int httpPort;
      if (port > 0) httpPort = 10000 + port;  // offset from pekko port
      else httpPort = 0; // let OS decide

      Config config = configWithPort(port);
      ActorSystem.create(Guardian.create(httpPort), "KillrWeather", config);
    }
  }