|
22 | 22 | import com.uber.cadence.internal.sync.WorkflowInternal;
|
23 | 23 | import com.uber.cadence.workflow.ActivityException;
|
24 | 24 | import com.uber.cadence.workflow.ActivityTimeoutException;
|
25 |
| - |
26 | 25 | import java.util.concurrent.CancellationException;
|
27 | 26 |
|
28 | 27 | /**
|
29 |
| - * Use this method from within activity implementation to get information about activity task |
30 |
| - * and heartbeat. |
| 28 | + * Use this method from within activity implementation to get information about activity task and |
| 29 | + * heartbeat. |
31 | 30 | */
|
32 | 31 | public final class Activity {
|
33 | 32 |
|
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 |
| - } |
| 33 | + /** |
| 34 | + * If this method is called during an activity execution then activity is not going to complete |
| 35 | + * when its method returns. It is expected to be completed asynchronously using {@link |
| 36 | + * com.uber.cadence.client.ActivityCompletionClient}. |
| 37 | + */ |
| 38 | + public static void doNotCompleteOnReturn() { |
| 39 | + ActivityInternal.doNotCompleteOnReturn(); |
| 40 | + } |
42 | 41 |
|
43 |
| - /** |
44 |
| - * @return task token that is required to report task completion when |
45 |
| - * manual activity completion is used. |
46 |
| - */ |
47 |
| - public static byte[] getTaskToken() { |
48 |
| - return ActivityInternal.getTask().getTaskToken(); |
49 |
| - } |
| 42 | + /** |
| 43 | + * @return task token that is required to report task completion when manual activity completion |
| 44 | + * is used. |
| 45 | + */ |
| 46 | + public static byte[] getTaskToken() { |
| 47 | + return ActivityInternal.getTask().getTaskToken(); |
| 48 | + } |
50 | 49 |
|
51 |
| - /** |
52 |
| - * @return workfow execution that requested the activity execution |
53 |
| - */ |
54 |
| - public static com.uber.cadence.WorkflowExecution getWorkflowExecution() { |
55 |
| - return ActivityInternal.getTask().getWorkflowExecution(); |
56 |
| - } |
| 50 | + /** @return workfow execution that requested the activity execution */ |
| 51 | + public static com.uber.cadence.WorkflowExecution getWorkflowExecution() { |
| 52 | + return ActivityInternal.getTask().getWorkflowExecution(); |
| 53 | + } |
57 | 54 |
|
58 |
| - /** |
59 |
| - * @return task that caused activity execution |
60 |
| - */ |
61 |
| - public static ActivityTask getTask() { |
62 |
| - return ActivityInternal.getTask(); |
63 |
| - } |
| 55 | + /** @return task that caused activity execution */ |
| 56 | + public static ActivityTask getTask() { |
| 57 | + return ActivityInternal.getTask(); |
| 58 | + } |
64 | 59 |
|
65 |
| - /** |
66 |
| - * Use to notify Cadence service that activity execution is alive. |
67 |
| - * |
68 |
| - * @param details In case of activity timeout can be accessed through |
69 |
| - * {@link ActivityTimeoutException#getDetails(Class)} method. |
70 |
| - * @throws CancellationException Indicates that activity cancellation was requested by the |
71 |
| - * workflow.Should be rethrown from activity implementation to |
72 |
| - * indicate successful cancellation. |
73 |
| - */ |
74 |
| - public static void heartbeat(Object details) throws CancellationException { |
75 |
| - ActivityInternal.recordActivityHeartbeat(details); |
76 |
| - } |
| 60 | + /** |
| 61 | + * Use to notify Cadence service that activity execution is alive. |
| 62 | + * |
| 63 | + * @param details In case of activity timeout can be accessed through {@link |
| 64 | + * ActivityTimeoutException#getDetails(Class)} method. |
| 65 | + * @throws CancellationException Indicates that activity cancellation was requested by the |
| 66 | + * workflow.Should be rethrown from activity implementation to indicate successful |
| 67 | + * cancellation. |
| 68 | + */ |
| 69 | + public static void heartbeat(Object details) throws CancellationException { |
| 70 | + ActivityInternal.recordActivityHeartbeat(details); |
| 71 | + } |
77 | 72 |
|
78 |
| - /** |
79 |
| - * @return an instance of the Simple Workflow Java client that is the same |
80 |
| - * used by the invoked activity worker. It can be useful if activity wants to use WorkflowClient for |
81 |
| - * some operations like sending signal to its parent workflow. |
82 |
| - * @TODO getWorkflowClient method to hide the service. |
83 |
| - */ |
84 |
| - public static WorkflowService.Iface getService() { |
85 |
| - return ActivityInternal.getService(); |
86 |
| - } |
| 73 | + /** |
| 74 | + * @return an instance of the Simple Workflow Java client that is the same used by the invoked |
| 75 | + * activity worker. It can be useful if activity wants to use WorkflowClient for some |
| 76 | + * operations like sending signal to its parent workflow. @TODO getWorkflowClient method to |
| 77 | + * hide the service. |
| 78 | + */ |
| 79 | + public static WorkflowService.Iface getService() { |
| 80 | + return ActivityInternal.getService(); |
| 81 | + } |
87 | 82 |
|
88 |
| - public static String getDomain() { |
89 |
| - return ActivityInternal.getDomain(); |
90 |
| - } |
| 83 | + public static String getDomain() { |
| 84 | + return ActivityInternal.getDomain(); |
| 85 | + } |
91 | 86 |
|
92 |
| - /** |
93 |
| - * If there is a need to return a checked exception from an activity |
94 |
| - * do not add the exception to a method signature but rethrow it using this method. |
95 |
| - * The library code will unwrap it automatically when propagating exception to the caller. |
96 |
| - * There is no need to wrap unchecked exceptions, but it is safe to call this method on them. |
97 |
| - * <p> |
98 |
| - * The reason for such design is that returning originally thrown exception from a remote call |
99 |
| - * (which child workflow and activity invocations are ) would not allow adding context information about |
100 |
| - * a failure, like activity and child workflow id. So stubs always throw a subclass of |
101 |
| - * {@link ActivityException} from calls to an activity and subclass of |
102 |
| - * {@link com.uber.cadence.workflow.ChildWorkflowException} from calls to a child workflow. |
103 |
| - * The original exception is attached as a cause to these wrapper exceptions. So as exceptions are always wrapped |
104 |
| - * adding checked ones to method signature causes more pain than benefit. |
105 |
| - * </p> |
106 |
| - * Throws original exception if e is {@link RuntimeException} or {@link Error}. |
107 |
| - * Never returns. But return type is not empty to be able to use it as: |
108 |
| - * <pre> |
109 |
| - * try { |
110 |
| - * return someCall(); |
111 |
| - * } catch (Exception e) { |
112 |
| - * throw CheckedExceptionWrapper.throwWrapped(e); |
113 |
| - * } |
114 |
| - * </pre> |
115 |
| - * If throwWrapped returned void it wouldn't be possible to write <code>throw CheckedExceptionWrapper.throwWrapped</code> |
116 |
| - * and compiler would complain about missing return. |
117 |
| - * |
118 |
| - * @return never returns as always throws. |
119 |
| - */ |
120 |
| - public static RuntimeException wrap(Exception e) { |
121 |
| - return WorkflowInternal.wrap(e); |
122 |
| - } |
| 87 | + /** |
| 88 | + * If there is a need to return a checked exception from an activity do not add the exception to a |
| 89 | + * method signature but rethrow it using this method. The library code will unwrap it |
| 90 | + * automatically when propagating exception to the caller. There is no need to wrap unchecked |
| 91 | + * exceptions, but it is safe to call this method on them. |
| 92 | + * |
| 93 | + * <p>The reason for such design is that returning originally thrown exception from a remote call |
| 94 | + * (which child workflow and activity invocations are ) would not allow adding context information |
| 95 | + * about a failure, like activity and child workflow id. So stubs always throw a subclass of |
| 96 | + * {@link ActivityException} from calls to an activity and subclass of {@link |
| 97 | + * com.uber.cadence.workflow.ChildWorkflowException} from calls to a child workflow. The original |
| 98 | + * exception is attached as a cause to these wrapper exceptions. So as exceptions are always |
| 99 | + * wrapped adding checked ones to method signature causes more pain than benefit. |
| 100 | + * |
| 101 | + * <p>Throws original exception if e is {@link RuntimeException} or {@link Error}. Never returns. |
| 102 | + * But return type is not empty to be able to use it as: |
| 103 | + * |
| 104 | + * <pre> |
| 105 | + * try { |
| 106 | + * return someCall(); |
| 107 | + * } catch (Exception e) { |
| 108 | + * throw CheckedExceptionWrapper.throwWrapped(e); |
| 109 | + * } |
| 110 | + * </pre> |
| 111 | + * |
| 112 | + * If throwWrapped returned void it wouldn't be possible to write <code> |
| 113 | + * throw CheckedExceptionWrapper.throwWrapped</code> and compiler would complain about missing |
| 114 | + * return. |
| 115 | + * |
| 116 | + * @return never returns as always throws. |
| 117 | + */ |
| 118 | + public static RuntimeException wrap(Exception e) { |
| 119 | + return WorkflowInternal.wrap(e); |
| 120 | + } |
123 | 121 |
|
124 |
| - /** |
125 |
| - * Prohibit instantiation |
126 |
| - */ |
127 |
| - private Activity() { |
128 |
| - } |
| 122 | + /** Prohibit instantiation */ |
| 123 | + private Activity() {} |
129 | 124 | }
|
0 commit comments