Skip to content

Commit f1dbce5

Browse files
authored
use client options for gRPC stubs (cadence-workflow#674)
1 parent d67bb44 commit f1dbce5

File tree

3 files changed

+9
-249
lines changed

3 files changed

+9
-249
lines changed

src/main/java/com/uber/cadence/internal/compatibility/proto/serviceclient/GrpcServiceStubs.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.uber.cadence.api.v1.WorkflowAPIGrpc.WorkflowAPIBlockingStub;
2727
import com.uber.cadence.api.v1.WorkflowAPIGrpc.WorkflowAPIFutureStub;
2828
import com.uber.cadence.internal.Version;
29+
import com.uber.cadence.serviceclient.ClientOptions;
2930
import io.grpc.CallOptions;
3031
import io.grpc.Channel;
3132
import io.grpc.ClientCall;
@@ -47,7 +48,6 @@
4748
final class GrpcServiceStubs implements IGrpcServiceStubs {
4849

4950
private static final Logger log = LoggerFactory.getLogger(GrpcServiceStubs.class);
50-
5151
private static final Metadata.Key<String> LIBRARY_VERSION_HEADER_KEY =
5252
Metadata.Key.of("cadence-client-library-version", Metadata.ASCII_STRING_MARSHALLER);
5353

@@ -60,7 +60,6 @@ final class GrpcServiceStubs implements IGrpcServiceStubs {
6060
private static final String CLIENT_IMPL_HEADER_VALUE = "uber-java";
6161

6262
private final ManagedChannel channel;
63-
private final boolean channelNeedsShutdown;
6463
private final AtomicBoolean shutdownRequested = new AtomicBoolean();
6564
private final DomainAPIGrpc.DomainAPIBlockingStub domainBlockingStub;
6665
private final DomainAPIGrpc.DomainAPIFutureStub domainFutureStub;
@@ -71,19 +70,13 @@ final class GrpcServiceStubs implements IGrpcServiceStubs {
7170
private final WorkflowAPIGrpc.WorkflowAPIBlockingStub workflowBlockingStub;
7271
private final WorkflowAPIGrpc.WorkflowAPIFutureStub workflowFutureStub;
7372

74-
GrpcServiceStubs(GrpcServiceStubsOptions options) {
75-
options = GrpcServiceStubsOptions.newBuilder(options).validateAndBuildWithDefaults();
76-
if (options.getChannel() != null) {
77-
this.channel = options.getChannel();
78-
channelNeedsShutdown = false;
79-
} else {
73+
GrpcServiceStubs(ClientOptions options) {
8074
this.channel =
81-
ManagedChannelBuilder.forTarget(options.getTarget())
75+
ManagedChannelBuilder.forAddress(options.getHost(), options.getPort())
8276
.defaultLoadBalancingPolicy("round_robin")
8377
.usePlaintext()
8478
.build();
85-
channelNeedsShutdown = true;
86-
}
79+
8780
ClientInterceptor deadlineInterceptor = new GrpcDeadlineInterceptor(options);
8881
ClientInterceptor tracingInterceptor = newTracingInterceptor();
8982
Metadata headers = new Metadata();
@@ -184,48 +177,35 @@ public WorkflowAPIFutureStub workflowFutureStub() {
184177
@Override
185178
public void shutdown() {
186179
shutdownRequested.set(true);
187-
if (channelNeedsShutdown) {
188180
channel.shutdown();
189-
}
190181
}
191182

192183
@Override
193184
public void shutdownNow() {
194185
shutdownRequested.set(true);
195-
if (channelNeedsShutdown) {
196186
channel.shutdownNow();
197-
}
198187
}
199188

200189
@Override
201190
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
202-
if (channelNeedsShutdown) {
203191
return channel.awaitTermination(timeout, unit);
204-
}
205-
return true;
206192
}
207193

208194
@Override
209195
public boolean isShutdown() {
210-
if (channelNeedsShutdown) {
211196
return channel.isShutdown();
212-
}
213-
return shutdownRequested.get();
214197
}
215198

216199
@Override
217200
public boolean isTerminated() {
218-
if (channelNeedsShutdown) {
219201
return channel.isTerminated();
220-
}
221-
return shutdownRequested.get();
222202
}
223203

224204
private static class GrpcDeadlineInterceptor implements ClientInterceptor {
225205

226-
private final GrpcServiceStubsOptions options;
206+
private final ClientOptions options;
227207

228-
public GrpcDeadlineInterceptor(GrpcServiceStubsOptions options) {
208+
public GrpcDeadlineInterceptor(ClientOptions options) {
229209
this.options = options;
230210
}
231211

src/main/java/com/uber/cadence/internal/compatibility/proto/serviceclient/GrpcServiceStubsOptions.java

Lines changed: 0 additions & 221 deletions
This file was deleted.

src/main/java/com/uber/cadence/internal/compatibility/proto/serviceclient/IGrpcServiceStubs.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
import com.uber.cadence.api.v1.VisibilityAPIGrpc;
2020
import com.uber.cadence.api.v1.WorkerAPIGrpc;
2121
import com.uber.cadence.api.v1.WorkflowAPIGrpc;
22+
import com.uber.cadence.serviceclient.ClientOptions;
2223
import java.util.concurrent.TimeUnit;
2324

2425
public interface IGrpcServiceStubs {
2526

2627
/** Returns gRPC stubs with default options domain service. */
2728
static IGrpcServiceStubs newInstance() {
28-
return new GrpcServiceStubs(GrpcServiceStubsOptions.getDefaultInstance());
29+
return new GrpcServiceStubs(ClientOptions.defaultInstance());
2930
}
3031

3132
/** Returns gRPC stubs with given options domain service. */
32-
static IGrpcServiceStubs newInstance(GrpcServiceStubsOptions options) {
33+
static IGrpcServiceStubs newInstance(ClientOptions options) {
3334
return new GrpcServiceStubs(options);
3435
}
3536

0 commit comments

Comments
 (0)