Search in sources :

Example 1 with ActivityTaskCanceledEventAttributes

use of com.uber.cadence.ActivityTaskCanceledEventAttributes in project cadence-client by uber-java.

the class DecisionsHelper method handleActivityTaskCanceled.

public boolean handleActivityTaskCanceled(HistoryEvent event) {
    ActivityTaskCanceledEventAttributes attributes = event.getActivityTaskCanceledEventAttributes();
    String activityId = getActivityId(attributes);
    DecisionStateMachine decision = getDecision(new DecisionId(DecisionTarget.ACTIVITY, activityId));
    decision.handleCancellationEvent();
    return decision.isDone();
}
Also used : ActivityTaskCanceledEventAttributes(com.uber.cadence.ActivityTaskCanceledEventAttributes)

Example 2 with ActivityTaskCanceledEventAttributes

use of com.uber.cadence.ActivityTaskCanceledEventAttributes in project cadence-client by uber-java.

the class StateMachines method reportActivityTaskCancellation.

private static void reportActivityTaskCancellation(RequestContext ctx, ActivityTaskData data, Object request, long notUsed) {
    byte[] details = null;
    if (request instanceof RespondActivityTaskCanceledRequest) {
        details = ((RespondActivityTaskCanceledRequest) request).getDetails();
    } else if (request instanceof RespondActivityTaskCanceledByIDRequest) {
        details = ((RespondActivityTaskCanceledByIDRequest) request).getDetails();
    }
    ActivityTaskCanceledEventAttributes a = new ActivityTaskCanceledEventAttributes().setScheduledEventId(data.scheduledEventId).setStartedEventId(data.startedEventId);
    if (details != null) {
        a.setDetails(details);
    }
    HistoryEvent event = new HistoryEvent().setEventType(EventType.ActivityTaskCanceled).setActivityTaskCanceledEventAttributes(a);
    ctx.addEvent(event);
}
Also used : RespondActivityTaskCanceledByIDRequest(com.uber.cadence.RespondActivityTaskCanceledByIDRequest) ActivityTaskCanceledEventAttributes(com.uber.cadence.ActivityTaskCanceledEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent) RespondActivityTaskCanceledRequest(com.uber.cadence.RespondActivityTaskCanceledRequest)

Example 3 with ActivityTaskCanceledEventAttributes

use of com.uber.cadence.ActivityTaskCanceledEventAttributes in project cadence-client by uber-java.

the class ActivityDecisionContext method handleActivityTaskCanceled.

void handleActivityTaskCanceled(HistoryEvent event) {
    ActivityTaskCanceledEventAttributes attributes = event.getActivityTaskCanceledEventAttributes();
    String activityId = decisions.getActivityId(attributes);
    if (decisions.handleActivityTaskCanceled(event)) {
        CancellationException e = new CancellationException();
        OpenRequestInfo<byte[], ActivityType> scheduled = scheduledActivities.remove(activityId);
        if (scheduled != null) {
            BiConsumer<byte[], Exception> completionHandle = scheduled.getCompletionCallback();
            // It is OK to fail with subclass of CancellationException when cancellation requested.
            // It allows passing information about cancellation (details in this case) to the surrounding doCatch block
            completionHandle.accept(null, e);
        }
    }
}
Also used : ActivityTaskCanceledEventAttributes(com.uber.cadence.ActivityTaskCanceledEventAttributes) CancellationException(java.util.concurrent.CancellationException) ActivityType(com.uber.cadence.ActivityType) CancellationException(java.util.concurrent.CancellationException)

Aggregations

ActivityTaskCanceledEventAttributes (com.uber.cadence.ActivityTaskCanceledEventAttributes)3 ActivityType (com.uber.cadence.ActivityType)1 HistoryEvent (com.uber.cadence.HistoryEvent)1 RespondActivityTaskCanceledByIDRequest (com.uber.cadence.RespondActivityTaskCanceledByIDRequest)1 RespondActivityTaskCanceledRequest (com.uber.cadence.RespondActivityTaskCanceledRequest)1 CancellationException (java.util.concurrent.CancellationException)1