Skip to content

Commit 7912a84

Browse files
author
Liang Mei
authored
Add a close method for workflow client (#345)
1 parent 95f5828 commit 7912a84

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/java/com/uber/cadence/client/WorkflowClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* and then calling a method annotated with {@literal @}{@link WorkflowMethod}.
4747
*
4848
* <pre><code>
49-
* WorkflowClient workflowClient = WorkflowClient.newClient(cadenceServiceHost, cadenceServicePort, domain);
49+
* WorkflowClient workflowClient = WorkflowClient.newInstance(cadenceServiceHost, cadenceServicePort, domain);
5050
* // Create a workflow stub.
5151
* FileProcessingWorkflow workflow = workflowClient.newWorkflowStub(FileProcessingWorkflow.class);
5252
* </code></pre>
@@ -728,4 +728,9 @@ static <A1, A2, A3, A4, A5, A6, R> CompletableFuture<R> execute(
728728
A6 arg6) {
729729
return WorkflowClientInternal.execute(workflow, arg1, arg2, arg3, arg4, arg5, arg6);
730730
}
731+
732+
/**
733+
* Closes the workflow client and the underlying IWorkflowService when this method is called.
734+
*/
735+
void close();
731736
}

src/main/java/com/uber/cadence/internal/sync/WorkflowClientInternal.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class WorkflowClientInternal implements WorkflowClient {
5050
private final ManualActivityCompletionClientFactory manualActivityCompletionClientFactory;
5151
private final DataConverter dataConverter;
5252
private final WorkflowClientInterceptor[] interceptors;
53+
private final IWorkflowService workflowService;
5354

5455
/**
5556
* Creates worker that connects to the local instance of the Cadence Service that listens on a
@@ -130,6 +131,7 @@ private WorkflowClientInternal(
130131
if (options == null) {
131132
options = new WorkflowClientOptions.Builder().build();
132133
}
134+
this.workflowService = service;
133135
this.genericClient =
134136
new GenericWorkflowClientExternalImpl(service, domain, options.getMetricsScope());
135137
this.dataConverter = options.getDataConverter();
@@ -449,4 +451,9 @@ public static <A1, A2, A3, A4, A5, A6, R> CompletableFuture<R> execute(
449451
A6 arg6) {
450452
return execute(() -> workflow.apply(arg1, arg2, arg3, arg4, arg5, arg6));
451453
}
454+
455+
@Override
456+
public void close() {
457+
this.workflowService.close();
458+
}
452459
}

0 commit comments

Comments
 (0)