Skip to content

Commit 09a92db

Browse files
committed
Simplify Jdk8Stub.mustache
1 parent 72d8f07 commit 09a92db

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.salesforce.jprotoc;
2+
3+
public class JavaMethodStubTest {
4+
5+
}

jprotoc/src/main/resources/Jdk8Stub.mustache

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)