|
| 1 | +/* |
| 2 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not |
| 7 | + * use this file except in compliance with the License. A copy of the License is |
| 8 | + * located at |
| 9 | + * |
| 10 | + * http://aws.amazon.com/apache2.0 |
| 11 | + * |
| 12 | + * or in the "license" file accompanying this file. This file is distributed on |
| 13 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 14 | + * express or implied. See the License for the specific language governing |
| 15 | + * permissions and limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.uber.cadence.activity; |
| 19 | + |
| 20 | +import com.uber.cadence.WorkflowExecution; |
| 21 | +import com.uber.cadence.client.ActivityCompletionClient; |
| 22 | +import com.uber.cadence.client.ActivityCompletionException; |
| 23 | +import com.uber.cadence.serviceclient.IWorkflowService; |
| 24 | +import java.lang.reflect.Type; |
| 25 | +import java.util.Optional; |
| 26 | + |
| 27 | +/** |
| 28 | + * Context object passed to an activity implementation. Use {@link Activity#getExecutionContext()} |
| 29 | + * from an activity implementation to access. |
| 30 | + */ |
| 31 | +public interface ActivityExecutionContext { |
| 32 | + |
| 33 | + /** Information about activity invocation and the caller workflow */ |
| 34 | + ActivityTask getInfo(); |
| 35 | + |
| 36 | + /** |
| 37 | + * Use to notify Cadence service that activity execution is alive. |
| 38 | + * |
| 39 | + * @param details In case of activity timeout details are returned as a field of the exception |
| 40 | + * thrown. |
| 41 | + * @throws ActivityCompletionException Indicates that activity cancellation was requested by the |
| 42 | + * workflow or any other reason for activity to stop execution. Should be rethrown from |
| 43 | + * activity implementation to indicate successful cancellation. |
| 44 | + */ |
| 45 | + <V> void heartbeat(V details) throws ActivityCompletionException; |
| 46 | + |
| 47 | + /** |
| 48 | + * Extracts heartbeat details from the last failed attempt. This is used in combination with retry |
| 49 | + * options. An activity could be scheduled with an optional {@link |
| 50 | + * com.uber.cadence.common.RetryOptions} on {@link ActivityOptions}. If an activity failed then |
| 51 | + * the server would attempt to dispatch another activity task to retry according to the retry |
| 52 | + * options. If there was heartbeat details reported by the activity from the failed attempt, the |
| 53 | + * details would be delivered along with the activity task for the retry attempt. The activity |
| 54 | + * could extract the details by {@link #getHeartbeatDetails(Class)}() and resume from the |
| 55 | + * progress. |
| 56 | + * |
| 57 | + * @param detailsClass type of the heartbeat details |
| 58 | + */ |
| 59 | + <V> Optional<V> getHeartbeatDetails(Class<V> detailsClass); |
| 60 | + |
| 61 | + /** |
| 62 | + * Extracts heartbeat details from the last failed attempt. This is used in combination with retry |
| 63 | + * options. An activity could be scheduled with an optional {@link |
| 64 | + * com.uber.cadence.common.RetryOptions} on {@link ActivityOptions}. If an activity failed then |
| 65 | + * the server would attempt to dispatch another activity task to retry according to the retry |
| 66 | + * options. If there was heartbeat details reported by the activity from the failed attempt, the |
| 67 | + * details would be delivered along with the activity task for the retry attempt. The activity |
| 68 | + * could extract the details by {@link #getHeartbeatDetails(Class)}() and resume from the |
| 69 | + * progress. |
| 70 | + * |
| 71 | + * @param detailsClass type of the heartbeat details |
| 72 | + * @param detailsType type including generic information of the heartbeat details |
| 73 | + */ |
| 74 | + <V> Optional<V> getHeartbeatDetails(Class<V> detailsClass, Type detailsType); |
| 75 | + |
| 76 | + /** |
| 77 | + * A correlation token that can be used to complete the activity asynchronously through {@link |
| 78 | + * com.uber.cadence.client.ActivityCompletionClient#complete(byte[], Object)}. |
| 79 | + */ |
| 80 | + byte[] getTaskToken(); |
| 81 | + |
| 82 | + /** |
| 83 | + * If this method is called during an activity execution then activity is not going to complete |
| 84 | + * when its method returns. It is expected to be completed asynchronously using {@link |
| 85 | + * com.uber.cadence.client.ActivityCompletionClient}. |
| 86 | + */ |
| 87 | + void doNotCompleteOnReturn(); |
| 88 | + |
| 89 | + boolean isDoNotCompleteOnReturn(); |
| 90 | + |
| 91 | + /** |
| 92 | + * Use for asynchronous completion within the activity worker process. Calling this method |
| 93 | + * prevents automatic activity completion on return and returns a client that can be used to |
| 94 | + * complete the activity asynchronously. |
| 95 | + */ |
| 96 | + ActivityCompletionClient useLocalManualCompletion(); |
| 97 | + |
| 98 | + boolean isUseLocalManualCompletion(); |
| 99 | + |
| 100 | + /** @return workfow execution that requested the activity execution */ |
| 101 | + WorkflowExecution getWorkflowExecution(); |
| 102 | + |
| 103 | + /** |
| 104 | + * @return an instance of the Cadence service client that is the same used by the invoked activity |
| 105 | + * worker. |
| 106 | + */ |
| 107 | + IWorkflowService getService(); |
| 108 | + |
| 109 | + /** @return the domain of the activity execution */ |
| 110 | + String getDomain(); |
| 111 | +} |
0 commit comments