public static void start()

in pekko-sample-sharding-java/killrweather/src/main/java/sample/killrweather/WeatherHttpServer.java [19:53]


  public static void start(Route routes, int port, ActorSystem<?> system) {
    org.apache.pekko.actor.ActorSystem classicActorSystem = Adapter.toClassic(system);

    Materializer materializer = SystemMaterializer.get(system).materializer();

    Http.get(classicActorSystem).bindAndHandle(
        routes.flow(classicActorSystem, materializer),
        ConnectHttp.toHost("localhost", port),
        materializer
    ).whenComplete((binding, failure) -> {
      if (failure == null) {
        final InetSocketAddress address = binding.localAddress();
        system.log().info(
            "WeatherServer online at http://{}:{}/",
            address.getHostString(),
            address.getPort());

        CoordinatedShutdown.get(classicActorSystem).addTask(
            CoordinatedShutdown.PhaseServiceRequestsDone(),
            "http-graceful-terminate",
            () ->
              binding.terminate(Duration.ofSeconds(10)).thenApply(terminated -> {
                system.log().info( "WeatherServer http://{}:{}/ graceful shutdown completed",
                    address.getHostString(),
                    address.getPort()
                );
                return done();
              })
        );
      } else {
        system.log().error("Failed to bind HTTP endpoint, terminating system", failure);
        system.terminate();
      }
    });
  }