use of org.apache.commons.scxml.TriggerEvent in project ACS by ACS-Community.
the class AcsScxmlEngine method fireSignalWithErrorFeedback.
/**
* Synchronous event handling as in {@link #fireSignal(Enum)},
* but possibly with exceptions for the following cases:
* <ul>
* <li> The <code>signal</code> gets checked if it can be handled by the current state(s);
* an <code>AcsJIllegalStateEventEx</code> exception is thrown if not.
* <li> If an executed action throws a AcsJStateMachineActionEx exception, that exception gets thrown here.
* Depending on the concrete state machine, an additional response to the error may be
* that the SM goes to an error state, due to an internal event triggered by the action.
* <li> <code>ModelException</code>, as thrown by {@link SCXMLExecutor#triggerEvent}, unlikely
* with our static use of the SCXML engine.
* </ul>
* @param signal
* @return True - if all the states are final and there are not events
* pending from the last step. False - otherwise.
* @throws AcsJIllegalStateEventEx
* @throws AcsJStateMachineActionEx
* @throws ModelException
*/
public synchronized boolean fireSignalWithErrorFeedback(S signal) throws AcsJIllegalStateEventEx, AcsJStateMachineActionEx, ModelException {
// check if signal is OK, throw exception if not.
Set<S> applicableSignals = getApplicableSignals();
if (!applicableSignals.contains(signal)) {
AcsJIllegalStateEventEx ex = new AcsJIllegalStateEventEx();
ex.setEvent(signal.name());
ex.setState(getCurrentState());
throw ex;
}
// Register error callback with action dispatcher.
// This is only thread safe because this method is synchronized and we
// execute only one event at a time.
MyActionExceptionHandler handler = new MyActionExceptionHandler();
actionDispatcher.setActionExceptionHandler(handler);
try {
TriggerEvent evnt = new TriggerEvent(signal.name(), TriggerEvent.SIGNAL_EVENT, null);
exec.triggerEvent(evnt);
if (handler.theEx != null) {
throw handler.theEx;
} else {
// or all actions executed without exception.
return exec.getCurrentStatus().isFinal();
}
} finally {
actionDispatcher.setActionExceptionHandler(null);
}
}
Aggregations