Search in sources :

Example 1 with Timer

use of com.uber.cadence.internal.testservice.RequestContext.Timer in project cadence-client by uber-java.

the class TestWorkflowStoreImpl method save.

@Override
public long save(RequestContext ctx) throws InternalServiceError, EntityNotExistsError {
    long result;
    lock.lock();
    boolean historiesEmpty = histories.isEmpty();
    try {
        ExecutionId executionId = ctx.getExecutionId();
        HistoryStore history = histories.get(executionId);
        List<HistoryEvent> events = ctx.getEvents();
        if (history == null) {
            if (events.isEmpty() || events.get(0).getEventType() != EventType.WorkflowExecutionStarted) {
                throw new IllegalStateException("No history found for " + executionId);
            }
            history = new HistoryStore(executionId, lock);
            histories.put(executionId, history);
        }
        history.checkNextEventId(ctx.getInitialEventId());
        history.addAllLocked(events, ctx.currentTimeInNanoseconds());
        result = history.getNextEventIdLocked();
        timerService.updateLocks(ctx.getTimerLocks());
        ctx.fireCallbacks(history.getEventsLocked().size());
    } finally {
        if (historiesEmpty && !histories.isEmpty()) {
            // Initially locked in the constructor
            timerService.unlockTimeSkipping();
        }
        lock.unlock();
    }
    // Push tasks to the queues out of locks
    DecisionTask decisionTask = ctx.getDecisionTask();
    if (decisionTask != null) {
        BlockingQueue<PollForDecisionTaskResponse> decisionsQueue = getDecisionTaskListQueue(decisionTask.getTaskListId());
        decisionsQueue.add(decisionTask.getTask());
    }
    List<ActivityTask> activityTasks = ctx.getActivityTasks();
    if (activityTasks != null) {
        for (ActivityTask activityTask : activityTasks) {
            BlockingQueue<PollForActivityTaskResponse> activitiesQueue = getActivityTaskListQueue(activityTask.getTaskListId());
            activitiesQueue.add(activityTask.getTask());
        }
    }
    List<Timer> timers = ctx.getTimers();
    if (timers != null) {
        for (Timer t : timers) {
            timerService.schedule(Duration.ofSeconds(t.getDelaySeconds()), t.getCallback());
        }
    }
    return result;
}
Also used : PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) HistoryEvent(com.uber.cadence.HistoryEvent) Timer(com.uber.cadence.internal.testservice.RequestContext.Timer) PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse)

Aggregations

HistoryEvent (com.uber.cadence.HistoryEvent)1 PollForActivityTaskResponse (com.uber.cadence.PollForActivityTaskResponse)1 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)1 Timer (com.uber.cadence.internal.testservice.RequestContext.Timer)1