Skip to content

Commit a5def73

Browse files
authored
Converted @DonNotCompleteOnReturn to Activity.doNotCompleteOnReturn() (#112)
* Switched DonCompleteOnReturn to a method call from annotation * Converted Windows end of line to unix
1 parent 3304410 commit a5def73

19 files changed

+306
-351
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ A workflow must define an interface class. All its methods must have one of the
241241
parameters (like executionStartToCloseTimeoutSeconds) that are not specified through the annotation must be provided at runtime.
242242
- @Signal indicates a method that reacts to external signals. Must have a `void` return type.
243243
- @Query indicates a method that reacts to synchronous query requests.
244-
It is possible to have more than method with the same annotation.
244+
It is possible to have more than one method with the same annotation.
245245
```java
246246
public interface FileProcessingWorkflow {
247247

@@ -267,8 +267,8 @@ WorkflowClient workflowClient = WorkflowClient.newClient(cadenceServiceHost, cad
267267
// Create workflow stub
268268
FileProcessingWorkflow workflow = workflowClient.newWorkflowStub(FileProcessingWorkflow.class);
269269
```
270-
There are two ways to start workflow execution. Synchronously and asynchronously. Synchronous invocation starts a workflow
271-
and then waits for its completion. If process that started workflow crashes or stops waiting workflow continues execution.
270+
There are two ways to start workflow execution synchronously and asynchronously. Synchronous invocation starts a workflow
271+
and then waits for its completion. If process that started workflow crashes or stops the waiting workflow continues execution.
272272
As workflows are potentially long running and crashes of clients happen it is not very commonly found in production use.
273273
Asynchronous start initiates workflow execution and immediately returns to the caller. This is most common way to start
274274
workflows in production code.
@@ -316,7 +316,7 @@ It takes activity type and activity options as arguments. Activity options are n
316316
Calling a method on this interface invokes an activity that implements this method.
317317
An activity invocation synchronously blocks until the activity completes (or fails or times out). Even if activity
318318
execution takes a few months the workflow code still see it as a single synchronous invocation.
319-
Isn't it great? I doesn't matter what happens to the processes that host the worklfow. The business logic code
319+
Isn't it great? I doesn't matter what happens to the processes that host the workflow. The business logic code
320320
just sees a single method call.
321321
```java
322322
public class FileProcessingWorkflowImpl implements FileProcessingWorkflow {
@@ -501,8 +501,8 @@ Calling methods annotated with @QueryMethod is not allowed from within a workflo
501501

502502
Cadence uses [event sourcing](https://docs.microsoft.com/en-us/azure/architecture/patterns/event-sourcing) to recover
503503
the state of a workflow object including its threads and local variable values.
504-
. In essence every time a workflow state has to be restored its code is reexecuted from the beginning ignoring side
505-
effects (like activity invocations) which were already recorded in the workflow event history.
504+
. In essence every time a workflow state has to be restored its code is reexecuted from the beginning. When replaying side
505+
effects (like activity invocations) are ignored as they are already recorded in the workflow event history.
506506
Don't get confused, when writing workflow logic the replay is not visible,
507507
so the code should be written as it executes only once. But this design still puts the following constraints on the workflow
508508
implementation:

src/main/java/com/uber/cadence/activity/Activity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
*/
3232
public final class Activity {
3333

34+
/**
35+
* If this method is called during an activity execution then activity is not going to complete
36+
* when its method returns. It is expected to be completed asynchronously using
37+
* {@link com.uber.cadence.client.ActivityCompletionClient}.
38+
*/
39+
public static void doNotCompleteOnReturn() {
40+
ActivityInternal.doNotCompleteOnReturn();
41+
}
42+
3443
/**
3544
* @return task token that is required to report task completion when
3645
* manual activity completion is used.

src/main/java/com/uber/cadence/activity/DoNotCompleteOnReturn.java

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
package com.uber.cadence.client;
1919

2020
import com.uber.cadence.WorkflowExecution;
21+
import com.uber.cadence.activity.Activity;
2122

2223
import java.util.concurrent.CancellationException;
2324

2425
/**
25-
* Used to complete asynchronously activities that have their implementation method annotated with
26-
* {@link com.uber.cadence.activity.DoNotCompleteOnReturn}.
26+
* Used to complete asynchronously activities that called {@link Activity#doNotCompleteOnReturn()}.
2727
* <p>
2828
* Use {@link WorkflowClient#newActivityCompletionClient()} to create an instance.
2929
* </p>

src/main/java/com/uber/cadence/internal/external/GenericWorkflowClientExternal.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
import com.uber.cadence.internal.replay.SignalExternalWorkflowParameters;
2727

2828
public interface GenericWorkflowClientExternal {
29-
29+
3030
WorkflowExecution startWorkflow(StartWorkflowExecutionParameters startParameters) throws WorkflowExecutionAlreadyStartedError;
31-
31+
3232
void signalWorkflowExecution(SignalExternalWorkflowParameters signalParameters);
33-
33+
3434
void requestCancelWorkflowExecution(WorkflowExecution execution);
35-
35+
3636
byte[] queryWorkflow(QueryWorkflowParameters queryParameters);
37-
37+
3838
void terminateWorkflowExecution(TerminateWorkflowExecutionParameters terminateParameters);
3939

4040
String generateUniqueId();

src/main/java/com/uber/cadence/internal/external/ManualActivityCompletionClient.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
*/
1717

1818
package com.uber.cadence.internal.external;
19-
20-
import java.util.concurrent.CancellationException;
21-
22-
public abstract class ManualActivityCompletionClient {
23-
24-
public abstract void complete(Object result);
25-
26-
public abstract void fail(Throwable failure);
27-
28-
public abstract void recordHeartbeat(Object details) throws CancellationException;
29-
30-
public abstract void reportCancellation(Object details);
31-
}
19+
20+
import java.util.concurrent.CancellationException;
21+
22+
public abstract class ManualActivityCompletionClient {
23+
24+
public abstract void complete(Object result);
25+
26+
public abstract void fail(Throwable failure);
27+
28+
public abstract void recordHeartbeat(Object details) throws CancellationException;
29+
30+
public abstract void reportCancellation(Object details);
31+
}

src/main/java/com/uber/cadence/internal/external/ManualActivityCompletionClientFactory.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
*/
1717

1818
package com.uber.cadence.internal.external;
19-
20-
21-
import com.uber.cadence.WorkflowExecution;
22-
23-
public abstract class ManualActivityCompletionClientFactory {
24-
25-
public abstract ManualActivityCompletionClient getClient(byte[] taskToken);
26-
27-
public abstract ManualActivityCompletionClient getClient(WorkflowExecution execution, String activityId);
28-
}
19+
20+
21+
import com.uber.cadence.WorkflowExecution;
22+
23+
public abstract class ManualActivityCompletionClientFactory {
24+
25+
public abstract ManualActivityCompletionClient getClient(byte[] taskToken);
26+
27+
public abstract ManualActivityCompletionClient getClient(WorkflowExecution execution, String activityId);
28+
}

src/main/java/com/uber/cadence/internal/external/ManualActivityCompletionClientFactoryImpl.java

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,55 @@
1616
*/
1717

1818
package com.uber.cadence.internal.external;
19-
20-
import com.uber.cadence.WorkflowExecution;
21-
import com.uber.cadence.WorkflowService;
22-
import com.uber.cadence.converter.DataConverter;
23-
24-
public class ManualActivityCompletionClientFactoryImpl extends ManualActivityCompletionClientFactory {
25-
26-
private final WorkflowService.Iface service;
27-
28-
private final DataConverter dataConverter;
29-
private final String domain;
30-
31-
public ManualActivityCompletionClientFactoryImpl(WorkflowService.Iface service, String domain, DataConverter dataConverter) {
32-
this.service = service;
33-
this.domain = domain;
34-
this.dataConverter = dataConverter;
35-
}
36-
37-
public WorkflowService.Iface getService() {
38-
return service;
39-
}
40-
41-
public DataConverter getDataConverter() {
42-
return dataConverter;
43-
}
44-
45-
@Override
46-
public ManualActivityCompletionClient getClient(byte[] taskToken) {
47-
if (service == null) {
48-
throw new IllegalStateException("required property service is null");
49-
}
50-
if (dataConverter == null) {
51-
throw new IllegalStateException("required property dataConverter is null");
52-
}
53-
if (taskToken == null || taskToken.length == 0) {
54-
throw new IllegalArgumentException("null or empty task token");
55-
}
56-
return new ManualActivityCompletionClientImpl(service, taskToken, dataConverter);
57-
}
58-
59-
@Override
60-
public ManualActivityCompletionClient getClient(WorkflowExecution execution, String activityId) {
61-
if (execution == null) {
62-
throw new IllegalArgumentException("null execution");
63-
}
64-
if (activityId == null) {
65-
throw new IllegalArgumentException("null activityId");
66-
}
67-
return new ManualActivityCompletionClientImpl(service, domain, execution, activityId, dataConverter);
68-
}
69-
70-
}
19+
20+
import com.uber.cadence.WorkflowExecution;
21+
import com.uber.cadence.WorkflowService;
22+
import com.uber.cadence.converter.DataConverter;
23+
24+
public class ManualActivityCompletionClientFactoryImpl extends ManualActivityCompletionClientFactory {
25+
26+
private final WorkflowService.Iface service;
27+
28+
private final DataConverter dataConverter;
29+
private final String domain;
30+
31+
public ManualActivityCompletionClientFactoryImpl(WorkflowService.Iface service, String domain, DataConverter dataConverter) {
32+
this.service = service;
33+
this.domain = domain;
34+
this.dataConverter = dataConverter;
35+
}
36+
37+
public WorkflowService.Iface getService() {
38+
return service;
39+
}
40+
41+
public DataConverter getDataConverter() {
42+
return dataConverter;
43+
}
44+
45+
@Override
46+
public ManualActivityCompletionClient getClient(byte[] taskToken) {
47+
if (service == null) {
48+
throw new IllegalStateException("required property service is null");
49+
}
50+
if (dataConverter == null) {
51+
throw new IllegalStateException("required property dataConverter is null");
52+
}
53+
if (taskToken == null || taskToken.length == 0) {
54+
throw new IllegalArgumentException("null or empty task token");
55+
}
56+
return new ManualActivityCompletionClientImpl(service, taskToken, dataConverter);
57+
}
58+
59+
@Override
60+
public ManualActivityCompletionClient getClient(WorkflowExecution execution, String activityId) {
61+
if (execution == null) {
62+
throw new IllegalArgumentException("null execution");
63+
}
64+
if (activityId == null) {
65+
throw new IllegalArgumentException("null activityId");
66+
}
67+
return new ManualActivityCompletionClientImpl(service, domain, execution, activityId, dataConverter);
68+
}
69+
70+
}

0 commit comments

Comments
 (0)