@@ -327,19 +327,8 @@ public WorkflowServiceTChannel(String host, int port, ClientOptions options) {
327
327
throw new IllegalArgumentException ("0 or negative port" );
328
328
}
329
329
this .options = options ;
330
- String envUserName = System .getenv ("USER" );
331
- String envHostname ;
332
- try {
333
- envHostname = InetAddress .getLocalHost ().getHostName ();
334
- } catch (UnknownHostException e ) {
335
- envHostname = "localhost" ;
336
- }
337
- this .thriftHeaders =
338
- ImmutableMap .<String , String >builder ()
339
- .put ("user-name" , envUserName )
340
- .put ("host-name" , envHostname )
341
- .build ();
342
- // this.metricsReporter = new MetricsReporter(options.getMetricsClient());
330
+ this .thriftHeaders = getThriftHeaders ();
331
+ // this.metricsReporter = new MetricsReporter(options.getMetricsClient());
343
332
// Need to create tChannel last in order to prevent leaking when an exception is thrown
344
333
this .tChannel = new TChannel .Builder (options .getClientAppName ()).build ();
345
334
@@ -355,6 +344,35 @@ public WorkflowServiceTChannel(String host, int port, ClientOptions options) {
355
344
}
356
345
}
357
346
347
+ /**
348
+ * Creates Cadence client with specified sub channel and options.
349
+ *
350
+ * @param subChannel sub channel for communicating with cadence frontend service.
351
+ * @param options configuration options like rpc timeouts.
352
+ */
353
+ public WorkflowServiceTChannel (SubChannel subChannel , ClientOptions options ) {
354
+ this .options = options ;
355
+ this .thriftHeaders = getThriftHeaders ();
356
+ // this.metricsReporter = new MetricsReporter(options.getMetricsClient());
357
+ this .tChannel = null ;
358
+ this .subChannel = subChannel ;
359
+ }
360
+
361
+ private static Map <String , String > getThriftHeaders () {
362
+ String envUserName = System .getenv ("USER" );
363
+ String envHostname ;
364
+ try {
365
+ envHostname = InetAddress .getLocalHost ().getHostName ();
366
+ } catch (UnknownHostException e ) {
367
+ envHostname = "localhost" ;
368
+ }
369
+
370
+ return ImmutableMap .<String , String >builder ()
371
+ .put ("user-name" , envUserName )
372
+ .put ("host-name" , envHostname )
373
+ .build ();
374
+ }
375
+
358
376
/** Returns the endpoint in the format service::method" */
359
377
private static String getEndpoint (String service , String method ) {
360
378
return String .format ("%s::%s" , service , method );
0 commit comments