in src/main/java/com/amazonaws/services/simpleworkflow/flow/WorkflowReplayer.java [213:251]
protected PollForDecisionTaskResponse getNextHistoryTask(String nextPageToken) {
Iterator<HistoryEvent> iterator = history.iterator();
if (!iterator.hasNext()) {
throw new IllegalStateException("empty history");
}
HistoryEvent startEvent = iterator.next();
WorkflowExecutionStartedEventAttributes startedAttributes = startEvent.workflowExecutionStartedEventAttributes();
if (startedAttributes == null) {
throw new IllegalStateException("first event is not WorkflowExecutionStarted: " + startEvent);
}
List<HistoryEvent> events = new ArrayList<HistoryEvent>();
events.add(startEvent);
EventType eventType = null;
int lastStartedIndex = 0;
int index = 1;
long previousStartedEventId = 0;
long startedEventId = 0;
while (iterator.hasNext()) {
HistoryEvent event = iterator.next();
eventType = EventType.fromValue(event.eventTypeAsString());
events.add(event);
if (eventType == EventType.DECISION_TASK_STARTED) {
previousStartedEventId = startedEventId;
startedEventId = event.eventId();
lastStartedIndex = index;
}
index++;
}
if (events.size() > lastStartedIndex + 1) {
events = events.subList(0, lastStartedIndex + 1);
}
return PollForDecisionTaskResponse.builder()
.events(events)
.previousStartedEventId(previousStartedEventId)
.startedEventId(startedEventId)
.workflowExecution(workflowExecution.toSdkType())
.workflowType(startedAttributes.workflowType())
.build();
}