use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class HelloWorldClientTls method main.
/**
* Greet server. If provided, the first element of {@code args} is the name to use in the
* greeting.
*/
public static void main(String[] args) throws Exception {
if (args.length < 2 || args.length == 4 || args.length > 5) {
System.out.println("USAGE: HelloWorldClientTls host port [trustCertCollectionFilePath " + "[clientCertChainFilePath clientPrivateKeyFilePath]]\n Note: clientCertChainFilePath and " + "clientPrivateKeyFilePath are only needed if mutual auth is desired.");
System.exit(0);
}
// If only defaults are necessary, you can use TlsChannelCredentials.create() instead of
// interacting with the Builder.
TlsChannelCredentials.Builder tlsBuilder = TlsChannelCredentials.newBuilder();
switch(args.length) {
case 5:
tlsBuilder.keyManager(new File(args[3]), new File(args[4]));
// fallthrough
case 3:
tlsBuilder.trustManager(new File(args[2]));
// fallthrough
default:
}
String host = args[0];
int port = Integer.parseInt(args[1]);
ManagedChannel channel = Grpc.newChannelBuilderForAddress(host, port, tlsBuilder.build()).overrideAuthority("foo.test.google.fr").build();
try {
HelloWorldClientTls client = new HelloWorldClientTls(channel);
client.greet(host);
} finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
}
use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class HelloWorldAltsClient method run.
private void run(String[] args) throws InterruptedException {
parseArgs(args);
ExecutorService executor = Executors.newFixedThreadPool(1);
ManagedChannel channel = AltsChannelBuilder.forTarget(serverAddress).executor(executor).build();
try {
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel);
HelloReply resp = stub.sayHello(HelloRequest.newBuilder().setName("Waldo").build());
logger.log(Level.INFO, "Got {0}", resp);
} finally {
channel.shutdown();
channel.awaitTermination(1, TimeUnit.SECONDS);
// Wait until the channel has terminated, since tasks can be queued after the channel is
// shutdown.
executor.shutdown();
}
}
use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class RouteGuideClient method main.
/**
* Issues several different requests and then exits.
*/
public static void main(String[] args) throws InterruptedException {
String target = "localhost:8980";
if (args.length > 0) {
if ("--help".equals(args[0])) {
System.err.println("Usage: [target]");
System.err.println("");
System.err.println(" target The server to connect to. Defaults to " + target);
System.exit(1);
}
target = args[0];
}
List<Feature> features;
try {
features = RouteGuideUtil.parseFeatures(RouteGuideUtil.getDefaultFeaturesFile());
} catch (IOException ex) {
ex.printStackTrace();
return;
}
ManagedChannel channel = ManagedChannelBuilder.forTarget(target).usePlaintext().build();
try {
RouteGuideClient client = new RouteGuideClient(channel);
// Looking for a valid feature
client.getFeature(409146138, -746188906);
// Feature missing.
client.getFeature(0, 0);
// Looking for features between 40, -75 and 42, -73.
client.listFeatures(400000000, -750000000, 420000000, -730000000);
// Record a few randomly selected points from the features file.
client.recordRoute(features, 10);
// Send and receive some notes.
CountDownLatch finishLatch = client.routeChat();
if (!finishLatch.await(1, TimeUnit.MINUTES)) {
client.warning("routeChat can not finish within 1 minutes");
}
} finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
}
use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class NettyChannelBuilderTest method authorityIsReadable.
@Test
public void authorityIsReadable() throws Exception {
NettyChannelBuilder builder = NettyChannelBuilder.forAddress("original", 1234);
ManagedChannel b = builder.build();
try {
assertEquals("original:1234", b.authority());
} finally {
shutdown(b);
}
}
use of io.grpc.ManagedChannel in project grpc-java by grpc.
the class NettyChannelBuilderTest method overrideAuthorityIsReadableHelper.
private void overrideAuthorityIsReadableHelper(NettyChannelBuilder builder, String overrideAuthority) throws Exception {
builder.overrideAuthority(overrideAuthority);
ManagedChannel channel = builder.build();
try {
assertEquals(overrideAuthority, channel.authority());
} finally {
shutdown(channel);
}
}
Aggregations