Example usage for org.apache.commons.scxml TriggerEvent SIGNAL_EVENT

List of usage examples for org.apache.commons.scxml TriggerEvent SIGNAL_EVENT

Introduction

In this page you can find the example usage for org.apache.commons.scxml TriggerEvent SIGNAL_EVENT.

Prototype

int SIGNAL_EVENT

To view the source code for org.apache.commons.scxml TriggerEvent SIGNAL_EVENT.

Click Source Link

Document

SIGNAL_EVENT.

Usage

From source file:de.dfki.iui.mmds.scxml.engine.customactions.Raise.java

@Override
public void execute(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Log appLog,
        Collection derivedEvents) throws ModelException, SCXMLExpressionException {
    // TODO Auto-generated method stub
    appLog.info("Raise Event " + event);
    TriggerEvent e = new TriggerEvent(event, TriggerEvent.SIGNAL_EVENT);
    derivedEvents.add(e);/*from  w  w  w .  ja  v a2  s  .  c  o  m*/
}

From source file:com.korwe.thecore.scxml.ScxmlMessageProcessor.java

@Override
public synchronized void processMessage(CoreMessage message) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Message = " + message);
        LOG.debug("State machine state = " + exec.getCurrentStatus().getStates());
    }//from www.  j a v  a2s  . c  o  m

    try {
        switch (message.getMessageType()) {
        case ServiceRequest:
            if (LOG.isDebugEnabled()) {
                LOG.debug("Triggering request event");
            }

            ServiceRequest req = (ServiceRequest) message;
            exec.triggerEvent(
                    new TriggerEvent("ServiceRequest." + req.getFunction(), TriggerEvent.SIGNAL_EVENT, req));
            break;
        default:
            if (LOG.isDebugEnabled()) {
                LOG.debug("Triggering default event");
            }

            exec.triggerEvent(
                    new TriggerEvent(message.getMessageType().name(), TriggerEvent.SIGNAL_EVENT, message));
            break;
        }
    } catch (ModelException e) {
        LOG.error("Unable to process message - state machine error", e);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Message processed");
    }

}

From source file:com.korwe.thecore.scxml.ScxmlMessageSender.java

@Override
public void run() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("message sender thread started");
    }//from w  ww. j a  v  a  2s  .  c o  m
    try {
        scInstance.getExecutor()
                .triggerEvent(new TriggerEvent(parentStateId + ".invoke.done", TriggerEvent.SIGNAL_EVENT));
    } catch (ModelException e) {
        LOG.error("Error triggering 'invoke.done' event", e);
    }

    if ("sendRequest".equals(method)) {
        sendRequest(params);
    } else if ("sendResponse".equals(method)) {
        sendResponse(params);
    } else if ("forwardRequest".equals(method)) {
        forwardRequest(params);
    } else if ("forwardResponse".equals(method)) {
        forwardResponse(params);
    }
}

From source file:ch.shaktipat.saraswati.internal.common.AbstractStateMachine.java

/**
 * Fire an event on the SCXML engine.//from  ww  w  .  ja va 2s  . c  o m
 *
 * @param event The event name.
 * @return Whether the state machine has reached a "final"
 *         configuration.
 */
public boolean fireEvent(final String event) {
    TriggerEvent[] evts = { new TriggerEvent(event, TriggerEvent.SIGNAL_EVENT, null) };
    try {
        engine.triggerEvents(evts);
    } catch (ModelException me) {
        logError(me);
    }
    return engine.getCurrentStatus().isFinal();
}

From source file:com.headstrong.fusion.statemachine.SCXMLStateMachine.java

public void triggerEvent(Event event) throws StateEventException {
    TriggerEvent triggerEvent = new TriggerEvent(event.getName(), TriggerEvent.SIGNAL_EVENT);
    // send the event
    try {/* ww  w.j a va 2  s. co  m*/
        scxmlExecutor.triggerEvent(triggerEvent);
    } catch (ModelException e) {
        logger.error(
                "Error sending trigger Event" + triggerEvent.getName() + " to state machine " + this.getId());
        throw new StateEventException("Error sending trigger Event to the state machine", e);
    }
}

From source file:alma.acs.nc.sm.generic.AcsScxmlEngine.java

/**
 * Sends a signal (event) to the state machine.
 * //w  w  w  . j  a va  2s .  c  o m
 * The call is synchronous and returns only when the state machine has gone through all transitions/actions, 
 * where of course a /do activity would still continue to run asynchronously.
 * Note that the underlying SCXML engine also supports asynchronous sending of multiple events
 * at a time, but we do not expose this feature in ACS.
 * <p>
 * TODO: How can the client find out whether the signal was applicable 
 *       for the current state or was ignored?
 *       
 * @return True - if all the states are final and there are not events
 *         pending from the last step. False - otherwise.
 */
public synchronized boolean fireSignal(S signal) {
    TriggerEvent evnt = new TriggerEvent(signal.name(), TriggerEvent.SIGNAL_EVENT, null);
    try {
        exec.triggerEvent(evnt);
    } catch (ModelException e) {
        logger.info(e.getMessage());
    }
    return exec.getCurrentStatus().isFinal();
}

From source file:alma.acs.nc.sm.generic.AcsScxmlEngine.java

/**
 * Synchronous event handling as in {@link #fireSignal(Enum)}, 
 * but possibly with exceptions for the following cases:
 * <ul>/*www.j a  v a 2 s.  co m*/
 *   <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 {
            // either there was no action associated with the event,
            // or all actions executed without exception.
            return exec.getCurrentStatus().isFinal();
        }
    } finally {
        actionDispatcher.setActionExceptionHandler(null);
    }
}

From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java

/**
 * Fire an event on the SCXML engine./*from  ww  w.  j av  a  2  s  .  co m*/
 * 
 * @param event
 *            The event name.
 * @return Whether the state machine has reached a &quot;final&quot;
 *         configuration.
 */
@Override
public boolean fireEvent(final String event, final Object payload) {

    TriggerEvent evts = new TriggerEvent(event, TriggerEvent.SIGNAL_EVENT, payload);

    Set<TransitionTarget> lastLeafs = engine.getCurrentStatus().getStates();

    try {
        engine.triggerEvent(evts);
    } catch (ModelException me) {
        logError(me);
    }
    SCXMLEngineActivator.sendActiveStates(id, this.getActiveStates(), this.getAllActiveStates());

    // logInfo( "Send 'Scxml state'" );
    SCXMLEngineActivator.sendScxmlState(id, State.IDLE, getAvailableEventsStates());
    List<Set<String>> cfgHistory = new ArrayList<Set<String>>(configHistory);
    updateConfigHistory(lastLeafs);
    SCXMLEngineActivator.sendScxmlConfigHistory(id, cfgHistory);

    // if (cb!=null) {
    //
    // Set<TransitionTarget> targets =
    // engine.getCurrentStatus().getAllStates();
    // List<Set<String>> allEvents = new LinkedList<Set<String>>();
    // List<String> states = new ArrayList<String>(targets.size());
    // Set<String> events = null;
    //
    // for (TransitionTarget state : targets) {
    // states.add(state.getId());
    // events = new HashSet<String>();
    // for (Transition t : state.getTransitionsList()) {
    // if (t.getEvent() != null)
    // events.add(t.getEvent());
    // }
    // allEvents.add(events);
    //
    // }
    // cb.notifyEvents(this.getAllActiveStates(), allEvents);
    // }

    // SCXMLEngineComponent.sendActiveStates(scxmlDocument,
    // engine.getCurrentStatus().getAllStates());
    return engine.getCurrentStatus().isFinal();
}

From source file:org.dishevelled.piccolo.identify.StateMachineSupport.java

/**
 * Fire an event with the specified event name on the state machine for
 * this state machine support class (fails silently).
 *
 * @param eventName event name, must not be null
 *///from w w w  . j ava  2s.  c o m
void fireStateMachineEvent(final String eventName) {
    if (eventName == null) {
        throw new IllegalArgumentException("eventName must not be null");
    }
    try {
        TriggerEvent event = new TriggerEvent(eventName, TriggerEvent.SIGNAL_EVENT, null);
        executor.triggerEvents(new TriggerEvent[] { event });
    } catch (ModelException e) {
        // ignore
    }
}