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

akka.grpc.interop.AkkaGrpcClientJava Maven / Gradle / Ivy

Go to download

Akka gRPC - Support for building streaming gRPC servers and clients on top of Akka Streams.

There is a newer version: 2.3.4
Show newest version
/*
 * Copyright (C) 2018-2023 Lightbend Inc. 
 */

package akka.grpc.interop;

import akka.actor.ActorSystem;
import io.grpc.internal.testing.TestUtils;
import io.grpc.testing.integration2.ClientTester;
import io.grpc.testing.integration2.TestServiceClient;
import io.grpc.testing.integration2.Settings;
import scala.Function2;
import scala.concurrent.Await;
import scala.concurrent.duration.Duration;

import java.util.concurrent.TimeUnit;

public class AkkaGrpcClientJava extends GrpcClient {

  private final Function2 clientTesterFactory;

  public AkkaGrpcClientJava(Function2 clientTesterFactory) {
    this.clientTesterFactory = clientTesterFactory;
  }

  public void run(String[] args) {
    TestUtils.installConscryptIfAvailable();
    final Settings settings = Settings.parseArgs(args);

    final ActorSystem sys = ActorSystem.create("AkkaGrpcClientJava");

    final TestServiceClient client = new TestServiceClient(clientTesterFactory.apply(settings, sys));
    client.setUp();

    try {
      client.run(settings);
    }
    finally {
      client.tearDown();
      try {
        Await.result(sys.terminate(), Duration.apply(5, TimeUnit.SECONDS));
      }
      catch (Exception ex) {
        throw new RuntimeException(ex);
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy