2626import com .uber .cadence .api .v1 .WorkflowAPIGrpc .WorkflowAPIBlockingStub ;
2727import com .uber .cadence .api .v1 .WorkflowAPIGrpc .WorkflowAPIFutureStub ;
2828import com .uber .cadence .internal .Version ;
29+ import com .uber .cadence .serviceclient .ClientOptions ;
2930import io .grpc .CallOptions ;
3031import io .grpc .Channel ;
3132import io .grpc .ClientCall ;
4748final 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
0 commit comments