Skip to content

Commit 0db052d

Browse files
authored
Wrap error fixes and doNotCompleteOnReturn (#7)
* Wrap fixes and doNotCompleteOnReturn * Comment fixed
1 parent 8030d62 commit 0db052d

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/main/java/com/uber/cadence/samples/fileprocessing/StoreActivitiesImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public TaskListFileNamePair download(URL url) {
5151
System.out.println("download activity: downloaded from " + url + " to " + destination.getAbsolutePath());
5252
return new TaskListFileNamePair(hostSpecificTaskList, destination.getAbsolutePath());
5353
} catch (IOException e) {
54-
throw Workflow.throwWrapped(e);
54+
throw Workflow.wrap(e);
5555
}
5656
}
5757

@@ -63,7 +63,7 @@ public String process(String sourceFile) {
6363
System.out.println("process activity: processed file: " + processedName);
6464
return processedName;
6565
} catch (IOException e) {
66-
throw Activity.throwWrapped(e);
66+
throw Activity.wrap(e);
6767
}
6868
}
6969

src/main/java/com/uber/cadence/samples/hello/HelloAsyncActivityCompletion.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.uber.cadence.activity.Activity;
2020
import com.uber.cadence.activity.ActivityMethod;
21-
import com.uber.cadence.activity.DoNotCompleteOnReturn;
2221
import com.uber.cadence.client.ActivityCompletionClient;
2322
import com.uber.cadence.client.WorkflowClient;
2423
import com.uber.cadence.worker.Worker;
@@ -76,17 +75,17 @@ private static class GreetingActivitiesImpl implements GreetingActivities {
7675

7776
/**
7877
* Demonstrates how implement an activity asynchronously.
79-
* When @DoNotCompleteOnReturn is present activity implementation function returning doesn't complete
80-
* the activity.
78+
* When {@link Activity#doNotCompleteOnReturn()} is called the activity implementation function returning
79+
* doesn't complete the activity.
8180
*/
82-
@DoNotCompleteOnReturn
8381
@Override
8482
public String composeGreeting(String greeting, String name) {
8583
// TaskToken is a correlation token used to match activity task with completion
8684
byte[] taskToken = Activity.getTaskToken();
8785
// In real life this request can be executed anywhere. By external service for example.
8886
ForkJoinPool.commonPool().execute(() -> composeGreetingAsync(taskToken, greeting, name));
89-
// When @DoNotCompleteOnReturn is specified the return value is ignored.
87+
Activity.doNotCompleteOnReturn();
88+
// When doNotCompleteOnReturn() is invoked the return value is ignored.
9089
return "ignored";
9190
}
9291

src/main/java/com/uber/cadence/samples/hello/HelloException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
* activity, child and workflow interfaces is not going to help. It is because at all levels it is never received directly, but
8989
* in wrapped form. Propagating it without wrapping would not allow adding additional context information
9090
* like activity, child workflow and parent workflow types and IDs. The Cadence library solution is to provide special
91-
* wrapper method {@link Workflow#throwWrapped(Throwable)} which wraps a checked exception in a special runtime exception.
91+
* wrapper method {@link Workflow#wrap(Exception)} which wraps a checked exception in a special runtime exception.
9292
* It is special because framework strips it when chaining exception across logical process boundaries. In this example
9393
* IOException is directly attached to ActivityFailureException besides being wrapped when rethrown.
9494
* </p>
@@ -147,7 +147,9 @@ public String composeGreeting(String greeting, String name) {
147147
try {
148148
throw new IOException(greeting + " " + name + "!");
149149
} catch (IOException e) {
150-
throw Workflow.throwWrapped(e);
150+
// Wrap it as checked exceptions in activity and workflow interface methods are prohibited.
151+
// It will be unwrapped and attached as a cause to the ActivityFailureException.
152+
throw Workflow.wrap(e);
151153
}
152154
}
153155
}

0 commit comments

Comments
 (0)