if (message instanceof Timeout) {
// timeout is special. Has only one specific saga state and
// saga id is already known
Timeout timeout = (Timeout) message;
Saga saga = createSagaForTimeoutHandling(timeout);
if (saga != null) {
sagaInstances.add(SagaInstanceDescription.define(saga, false));
}
} else {
// create and start a new saga if message has been flagged as such
Collection<Class<? extends Saga>> startingSagaTypes = messagesStartingSagas.get(message.getClass());
for (Class<? extends Saga> sagaType : startingSagaTypes) {
Saga newSaga = startNewSaga(sagaType);
sagaInstances.add(SagaInstanceDescription.define(newSaga, true));
}
// Search for existing saga states and attach them to created instances.
Collection <Class<? extends Saga>> existingSagaTypes = messagesToContinueSaga.get(message.getClass());