Skip to content

Commit 5669b01

Browse files
meiliang86mfateev
authored andcommitted
add a new workflow service constructor that takes sub channel as input (#143)
1 parent 55dd0b0 commit 5669b01

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

src/main/java/com/uber/cadence/serviceclient/WorkflowServiceTChannel.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,19 +327,8 @@ public WorkflowServiceTChannel(String host, int port, ClientOptions options) {
327327
throw new IllegalArgumentException("0 or negative port");
328328
}
329329
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());
343332
// Need to create tChannel last in order to prevent leaking when an exception is thrown
344333
this.tChannel = new TChannel.Builder(options.getClientAppName()).build();
345334

@@ -355,6 +344,35 @@ public WorkflowServiceTChannel(String host, int port, ClientOptions options) {
355344
}
356345
}
357346

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+
358376
/** Returns the endpoint in the format service::method" */
359377
private static String getEndpoint(String service, String method) {
360378
return String.format("%s::%s", service, method);

0 commit comments

Comments
 (0)