in src/main/java/org/opensearch/search/asynchronous/context/state/AsynchronousSearchStateMachine.java [83:113]
public AsynchronousSearchState trigger(AsynchronousSearchContextEvent event) throws AsynchronousSearchStateMachineClosedException {
AsynchronousSearchContext asynchronousSearchContext = event.asynchronousSearchContext();
synchronized (asynchronousSearchContext) {
AsynchronousSearchState currentState = asynchronousSearchContext.getAsynchronousSearchState();
if (getFinalStates().contains(currentState)) {
throw new AsynchronousSearchStateMachineClosedException(currentState, event);
}
String transitionId = getTransitionId(currentState, event.getClass());
if (transitionsMap.containsKey(transitionId)) {
AsynchronousSearchTransition<? extends AsynchronousSearchContextEvent> transition = transitionsMap.get(transitionId);
execute(transition.onEvent(), event, currentState);
asynchronousSearchContext.setState(transition.targetState());
logger.debug("Executed event [{}] for asynchronous search id [{}] ", event.getClass().getName(),
event.asynchronousSearchContext.getAsynchronousSearchId());
BiConsumer<AsynchronousSearchContextId, AsynchronousSearchContextEventListener> eventListener = transition.eventListener();
try {
eventListener.accept(event.asynchronousSearchContext().getContextId(), asynchronousSearchContextEventListener);
} catch (Exception ex) {
logger.error(() -> new ParameterizedMessage("Failed to execute listener for asynchronous search id : [{}]",
event.asynchronousSearchContext.getAsynchronousSearchId()), ex);
}
return asynchronousSearchContext.getAsynchronousSearchState();
} else {
String message = String.format(Locale.ROOT, "Invalid transition for " +
"asynchronous search context [%s] from source state [%s] on event [%s]",
asynchronousSearchContext.getAsynchronousSearchId(), currentState, event.getClass().getName());
logger.error(message);
throw new IllegalStateException(message);
}
}
}