Search in sources :

Example 1 with StartTimerDecisionAttributes

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

the class ClockDecisionContext method createTimer.

Consumer<Exception> createTimer(long delaySeconds, Consumer<Exception> callback) {
    if (delaySeconds < 0) {
        throw new IllegalArgumentException("Negative delaySeconds: " + delaySeconds);
    }
    if (delaySeconds == 0) {
        callback.accept(null);
        return null;
    }
    long firingTime = currentTimeMillis() + TimeUnit.SECONDS.toMillis(delaySeconds);
    final OpenRequestInfo<?, Long> context = new OpenRequestInfo<>(firingTime);
    final StartTimerDecisionAttributes timer = new StartTimerDecisionAttributes();
    timer.setStartToFireTimeoutSeconds(delaySeconds);
    final String timerId = decisions.getNextId();
    timer.setTimerId(timerId);
    decisions.startTimer(timer, null);
    context.setCompletionHandle((ctx, e) -> callback.accept(e));
    scheduledTimers.put(timerId, context);
    return new ClockDecisionContext.TimerCancellationHandler(timerId);
}
Also used : StartTimerDecisionAttributes(com.uber.cadence.StartTimerDecisionAttributes)

Example 2 with StartTimerDecisionAttributes

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

the class DecisionsHelper method getDecisions.

List<Decision> getDecisions() {
    List<Decision> result = new ArrayList<>(MAXIMUM_DECISIONS_PER_COMPLETION + 1);
    for (DecisionStateMachine decisionStateMachine : decisions.values()) {
        Decision decision = decisionStateMachine.getDecision();
        if (decision != null) {
            result.add(decision);
        }
    }
    // Include FORCE_IMMEDIATE_DECISION timer only if there are more then 100 events
    int size = result.size();
    if (size > MAXIMUM_DECISIONS_PER_COMPLETION && !isCompletionEvent(result.get(MAXIMUM_DECISIONS_PER_COMPLETION - 2))) {
        result = result.subList(0, MAXIMUM_DECISIONS_PER_COMPLETION - 1);
        StartTimerDecisionAttributes attributes = new StartTimerDecisionAttributes();
        attributes.setStartToFireTimeoutSeconds(0);
        attributes.setTimerId(FORCE_IMMEDIATE_DECISION_TIMER);
        Decision d = new Decision();
        d.setStartTimerDecisionAttributes(attributes);
        d.setDecisionType(DecisionType.StartTimer);
        result.add(d);
    }
    return result;
}
Also used : StartTimerDecisionAttributes(com.uber.cadence.StartTimerDecisionAttributes) ArrayList(java.util.ArrayList) Decision(com.uber.cadence.Decision)

Aggregations

StartTimerDecisionAttributes (com.uber.cadence.StartTimerDecisionAttributes)2 Decision (com.uber.cadence.Decision)1 ArrayList (java.util.ArrayList)1