Java Code Examples for io.grpc.examples.helloworld.GreeterGrpc#GreeterBlockingStub
The following examples show how to use
io.grpc.examples.helloworld.GreeterGrpc#GreeterBlockingStub .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloWorldAltsClient.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
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(); } }
Example 2
Source File: HelloworldActivity.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Override protected String doInBackground(String... params) { String host = params[0]; String message = params[1]; String portStr = params[2]; int port = TextUtils.isEmpty(portStr) ? 0 : Integer.valueOf(portStr); try { channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build(); GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel); HelloRequest request = HelloRequest.newBuilder().setName(message).build(); HelloReply reply = stub.sayHello(request); return reply.getMessage(); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); return String.format("Failed... : %n%s", sw); } }
Example 3
Source File: HelloWorldAltsClient.java From grpc-java with Apache License 2.0 | 6 votes |
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(); } }
Example 4
Source File: HelloworldActivity.java From grpc-java with Apache License 2.0 | 6 votes |
@Override protected String doInBackground(String... params) { String host = params[0]; String message = params[1]; String portStr = params[2]; int port = TextUtils.isEmpty(portStr) ? 0 : Integer.valueOf(portStr); try { channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build(); GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel); HelloRequest request = HelloRequest.newBuilder().setName(message).build(); HelloReply reply = stub.sayHello(request); return reply.getMessage(); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); return String.format("Failed... : %n%s", sw); } }
Example 5
Source File: StrictModeHelloworldActivity.java From grpc-java with Apache License 2.0 | 6 votes |
@Override protected String doInBackground(String... params) { String host = params[0]; String message = params[1]; String portStr = params[2]; int port = TextUtils.isEmpty(portStr) ? 0 : Integer.valueOf(portStr); try { channel = OkHttpChannelBuilder.forAddress(host, port) .transportExecutor(new NetworkTaggingExecutor(0xFDD)) .usePlaintext() .build(); GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel); HelloRequest request = HelloRequest.newBuilder().setName(message).build(); HelloReply reply = stub.sayHello(request); return reply.getMessage(); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); return String.format("Failed... : %n%s", sw); } }
Example 6
Source File: SafeMethodCachingInterceptorTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void unsafeCallsAreNotCached() { GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channelToUse); HelloReply reply1 = stub.sayHello(message); HelloReply reply2 = stub.sayHello(message); assertNotEquals(reply1, reply2); }
Example 7
Source File: SafeMethodCachingInterceptorTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void unsafeCallsAreNotCached() { GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channelToUse); HelloReply reply1 = stub.sayHello(message); HelloReply reply2 = stub.sayHello(message); assertNotEquals(reply1, reply2); }
Example 8
Source File: ClientCacheExampleActivity.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override protected String doInBackground(Object... params) { String host = (String) params[0]; String message = (String) params[1]; String portStr = (String) params[2]; boolean useGet = (boolean) params[3]; boolean noCache = (boolean) params[4]; boolean onlyIfCached = (boolean) params[5]; int port = TextUtils.isEmpty(portStr) ? 0 : Integer.valueOf(portStr); try { channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build(); Channel channelToUse = ClientInterceptors.intercept( channel, SafeMethodCachingInterceptor.newSafeMethodCachingInterceptor(cache)); HelloRequest request = HelloRequest.newBuilder().setName(message).build(); HelloReply reply; if (useGet) { MethodDescriptor<HelloRequest, HelloReply> safeCacheableUnaryCallMethod = GreeterGrpc.getSayHelloMethod().toBuilder().setSafe(true).build(); CallOptions callOptions = CallOptions.DEFAULT; if (noCache) { callOptions = callOptions.withOption(SafeMethodCachingInterceptor.NO_CACHE_CALL_OPTION, true); } if (onlyIfCached) { callOptions = callOptions.withOption( SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true); } reply = ClientCalls.blockingUnaryCall( channelToUse, safeCacheableUnaryCallMethod, callOptions, request); } else { GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channelToUse); reply = stub.sayHello(request); } return reply.getMessage(); } catch (Exception e) { Log.e(TAG, "RPC failed", e); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); return String.format("Failed... : %n%s", sw); } }
Example 9
Source File: HelloWorldSchemaModule.java From rejoiner with Apache License 2.0 | 4 votes |
@Query("sayHello") HelloReply sayHello(HelloRequest request, GreeterGrpc.GreeterBlockingStub client) { return client.sayHello(request); }
Example 10
Source File: ClientCacheExampleActivity.java From grpc-java with Apache License 2.0 | 4 votes |
@Override protected String doInBackground(Object... params) { String host = (String) params[0]; String message = (String) params[1]; String portStr = (String) params[2]; boolean useGet = (boolean) params[3]; boolean noCache = (boolean) params[4]; boolean onlyIfCached = (boolean) params[5]; int port = TextUtils.isEmpty(portStr) ? 0 : Integer.valueOf(portStr); try { channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build(); Channel channelToUse = ClientInterceptors.intercept( channel, SafeMethodCachingInterceptor.newSafeMethodCachingInterceptor(cache)); HelloRequest request = HelloRequest.newBuilder().setName(message).build(); HelloReply reply; if (useGet) { MethodDescriptor<HelloRequest, HelloReply> safeCacheableUnaryCallMethod = GreeterGrpc.getSayHelloMethod().toBuilder().setSafe(true).build(); CallOptions callOptions = CallOptions.DEFAULT; if (noCache) { callOptions = callOptions.withOption(SafeMethodCachingInterceptor.NO_CACHE_CALL_OPTION, true); } if (onlyIfCached) { callOptions = callOptions.withOption( SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true); } reply = ClientCalls.blockingUnaryCall( channelToUse, safeCacheableUnaryCallMethod, callOptions, request); } else { GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channelToUse); reply = stub.sayHello(request); } return reply.getMessage(); } catch (Exception e) { Log.e(TAG, "RPC failed", e); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); return String.format("Failed... : %n%s", sw); } }