content: /*
   * Copyright (C) 2018-2024 Lightbend Inc. <https://www.lightbend.com>
   */
  
  //#full-server
  package example.myapp.helloworld;
  
  import akka.actor.ActorSystem;
  import akka.grpc.javadsl.ServerReflection;
  import akka.grpc.javadsl.ServiceHandler;
  
  import akka.http.javadsl.Http;
  import akka.http.javadsl.ServerBinding;
  import akka.http.javadsl.model.HttpRequest;
  import akka.http.javadsl.model.HttpResponse;
  import akka.japi.function.Function;
  import akka.stream.SystemMaterializer;
  import akka.stream.Materializer;
  import com.typesafe.config.Config;
  import com.typesafe.config.ConfigFactory;
  import example.myapp.helloworld.grpc.GreeterService;
  import example.myapp.helloworld.grpc.GreeterServiceHandlerFactory;
  
  import java.util.Arrays;
  import java.util.concurrent.CompletionStage;
  
  class GreeterServer {
    public static void main(String[] args) throws Exception {
      // important to enable HTTP/2 in ActorSystem's config
      Config conf = ConfigFactory.parseString("akka.http.server.enable-http2 = on")
              .withFallback(ConfigFactory.defaultApplication());
  
      // Akka ActorSystem Boot
      ActorSystem sys = ActorSystem.create("HelloWorld", conf);
  
      run(sys).thenAccept(binding -> {
        System.out.println("gRPC server bound to: " + binding.localAddress());
      });
  
      // ActorSystem threads will keep the app alive until `system.terminate()` is called
    }
  
    public static CompletionStage<ServerBinding> run(ActorSystem sys) throws Exception {
      Materializer mat = SystemMaterializer.get(sys).materializer();
  
      // Instantiate implementation
      GreeterService impl = new GreeterServiceImpl(mat);
  
      // Create the reflection handler for multiple services
      Function<HttpRequest, CompletionStage<HttpResponse>> reflectionPartial =
        ServerReflection.create(Arrays.asList(GreeterService.description), sys);
  
      Function<HttpRequest, CompletionStage<HttpResponse>> serviceHandlers =
        ServiceHandler.concatOrNotFound(GreeterServiceHandlerFactory.create(impl, sys), reflectionPartial);
  
      return Http
        .get(sys)
        .newServerAt("127.0.0.1", 8090)
        .bind(serviceHandlers);
    }
  }
  //#full-server
  