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);
}
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;
}
Aggregations