@@ -48,39 +48,18 @@ public class {{className}} {
4848 private { {serviceName} }CompletableFutureStub(Channel channel, CallOptions callOptions, Function<ListenableFuture , CompletableFuture > futureAdapter) {
4949 super(channel, callOptions);
5050 this.futureAdapter = futureAdapter;
51- innerStub = {{serviceName} }Grpc.newFutureStub(channel);
51+ innerStub = {{serviceName} }Grpc.newFutureStub(channel).build(channel, callOptions) ;
5252 }
5353
5454 @Override
5555 protected { {serviceName} }CompletableFutureStub build(Channel channel, CallOptions callOptions) {
5656 {{serviceName} }CompletableFutureStub stub = new { {serviceName} }CompletableFutureStub(channel, callOptions, futureAdapter);
57- forceCallOptions(stub.innerStub, callOptions);
5857 return stub;
5958 }
6059 { {#methods} }{ {#deprecated} }@Deprecated{ {/deprecated} }
6160 public CompletableFuture<{ {outputType} }> { {methodName} }({ {inputType} } request) {
6261 return futureAdapter.apply(innerStub.{{methodName} }(request));
6362 }
6463 { {/methods} }
65-
66- private void forceCallOptions({ {serviceName} }Grpc.{ {serviceName} }FutureStub stub, CallOptions options) {
67- try {
68- callOptionsField.set(stub, options);
69- } catch (IllegalAccessException e) {
70- throw new RuntimeException(e);
71- }
72- }
73- }
74-
75- private static final Field callOptionsField = getWritableCallOptonsField();
76-
77- private static Field getWritableCallOptonsField() {
78- try {
79- Field callOptionsField = AbstractStub.class.getDeclaredField(" callOptions" );
80- callOptionsField.setAccessible(true );
81- return callOptionsField;
82- } catch (NoSuchFieldException e) {
83- throw new RuntimeException(e);
84- }
8564 }
8665}
0 commit comments