Package org.apache.commons.scxml

Examples of org.apache.commons.scxml.TriggerEvent


     * @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);
View Full Code Here


            if (invokers.containsKey(tt)) {
                Invoker toCancel = (Invoker) invokers.get(tt);
                try {
                    toCancel.cancel();
                } catch (InvokerException ie) {
                    TriggerEvent te = new TriggerEvent(tt.getId()
                        + ".invoke.cancel.failed", TriggerEvent.ERROR_EVENT);
                    internalEvents.add(te);
                }
                // done here, don't wait for cancel response
                invokers.remove(tt);
            }
            nr.fireOnExit(tt, tt);
            nr.fireOnExit(stateMachine, tt);
            TriggerEvent te = new TriggerEvent(tt.getId() + ".exit",
                    TriggerEvent.CHANGE_EVENT);
            internalEvents.add(te);
        }
        // ExecutePhaseActions / Transitions
        for (Iterator i = step.getTransitList().iterator(); i.hasNext();) {
            Transition t = (Transition) i.next();
            try {
                for (Iterator transitIter = t.getActions().iterator();
                        transitIter.hasNext();) {
                    ((Action) transitIter.next()).execute(evtDispatcher,
                        errRep, scInstance, appLog, internalEvents);
                }
            } catch (SCXMLExpressionException e) {
                errRep.onError(ErrorReporter.EXPRESSION_ERROR,
                    e.getMessage(), t);
            }
            nr.fireOnTransition(t, t.getParent(), t.getRuntimeTarget(), t);
            nr.fireOnTransition(stateMachine, t.getParent(),
                t.getRuntimeTarget(), t);
        }
        // ExecutePhaseActions / OnEntry
        for (Iterator i = step.getEntryList().iterator(); i.hasNext();) {
            TransitionTarget tt = (TransitionTarget) i.next();
            OnEntry oe = tt.getOnEntry();
            try {
                for (Iterator onEntryIter = oe.getActions().iterator();
                        onEntryIter.hasNext();) {
                    ((Action) onEntryIter.next()).execute(evtDispatcher,
                        errRep, scInstance, appLog, internalEvents);
                }
            } catch (SCXMLExpressionException e) {
                errRep.onError(ErrorReporter.EXPRESSION_ERROR, e.getMessage(),
                        oe);
            }
            nr.fireOnEntry(tt, tt);
            nr.fireOnEntry(stateMachine, tt);
            TriggerEvent te = new TriggerEvent(tt.getId() + ".entry",
                    TriggerEvent.CHANGE_EVENT);
            internalEvents.add(te);
            //3.2.1 and 3.4 (.done events)
            if (tt instanceof State) {
                State ts = (State) tt;
                if (ts.getIsFinal()) {
                    State parent = (State) ts.getParent();
                    String prefix = "";
                    if (parent != null) {
                        prefix = parent.getId();
                    }
                    te = new TriggerEvent(prefix + ".done",
                            TriggerEvent.CHANGE_EVENT);
                    internalEvents.add(te);
                    if (parent != null) {
                        parent.setDone(true);
                    }
                    if (parent != null && parent.isRegion()) {
                        //3.4 we got a region, which is finalized
                        //let's check its siblings too
                        Parallel p = (Parallel) parent.getParent();
                        int finCount = 0;
                        int pCount = p.getStates().size();
                        for (Iterator regions = p.getStates().iterator();
                                regions.hasNext();) {
                            State reg = (State) regions.next();
                            if (reg.isDone()) {
                                finCount++;
                            }
                        }
                        if (finCount == pCount) {
                            te = new TriggerEvent(p.getId() + ".done",
                                        TriggerEvent.CHANGE_EVENT);
                            internalEvents.add(te);
                            te = new TriggerEvent(p.getParent().getId()
                                + ".done", TriggerEvent.CHANGE_EVENT);
                            internalEvents.add(te);
                            //this is not in the specs, but is makes sense
                            p.getParentState().setDone(true);
                        }
View Full Code Here

        Set allEvents = new HashSet(step.getBeforeStatus().getEvents().size()
            + step.getExternalEvents().size());
        //for now, we only match against event names
        for (Iterator ei = step.getBeforeStatus().getEvents().iterator();
                ei.hasNext();) {
            TriggerEvent te = (TriggerEvent) ei.next();
            allEvents.add(te.getName());
        }
        for (Iterator ei = step.getExternalEvents().iterator();
                ei.hasNext();) {
            TriggerEvent te = (TriggerEvent) ei.next();
            allEvents.add(te.getName());
        }
        // Finalize invokes, if applicable
        for (Iterator iter = scInstance.getInvokers().keySet().iterator();
                iter.hasNext();) {
            State s = (State) iter.next();
View Full Code Here

                String ttype = i.getTargettype();
                Invoker inv = null;
                try {
                    inv = scInstance.newInvoker(ttype);
                } catch (InvokerException ie) {
                    TriggerEvent te = new TriggerEvent(s.getId()
                        + ".invoke.failed", TriggerEvent.ERROR_EVENT);
                    internalEvents.add(te);
                    continue;
                }
                inv.setParentStateId(s.getId());
                inv.setSCInstance(scInstance);
                Map params = i.getParams();
                Map args = new HashMap();
                for (Iterator pIter = params.entrySet().iterator();
                        pIter.hasNext();) {
                    Map.Entry entry = (Map.Entry) pIter.next();
                    String argName = (String) entry.getKey();
                    String argExpr = (String) entry.getValue();
                    Object argValue = null;
                    if (argExpr != null && argExpr.trim().length() > 0) {
                        try {
                            argValue = eval.eval(ctx, argExpr);
                        } catch (SCXMLExpressionException see) {
                            errRep.onError(ErrorReporter.EXPRESSION_ERROR,
                                see.getMessage(), i);
                        }
                    }
                    args.put(argName, argValue);
                }
                try {
                    inv.invoke(source, args);
                } catch (InvokerException ie) {
                    TriggerEvent te = new TriggerEvent(s.getId()
                        + ".invoke.failed", TriggerEvent.ERROR_EVENT);
                    internalEvents.add(te);
                    continue;
                }
                scInstance.setInvoker(s, inv);
View Full Code Here

        if (appLog.isDebugEnabled()) {
            appLog.debug("<event>: Adding event named '" + name
                + "' to list of derived events.");
        }
        TriggerEvent ev = new TriggerEvent(name, TriggerEvent.SIGNAL_EVENT);
        derivedEvents.add(ev);

    }
View Full Code Here

     * @param event The event name.
     * @return Whether the state machine has reached a &quot;final&quot;
     *         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);
View Full Code Here

                // We know of no other target
                if (log.isWarnEnabled()) {
                    log.warn("<send>: Unavailable target - " + target);
                }
                try {
                    this.executor.triggerEvent(new TriggerEvent(
                        EVENT_ERR_SEND_TARGETUNAVAILABLE,
                        TriggerEvent.ERROR_EVENT));
                } catch (ModelException me) {
                    log.error(me.getMessage(), me);
                }
View Full Code Here

        /**
         * What to do when timer expires.
         */
        public void run() {
            try {
                executor.triggerEvent(new TriggerEvent(event,
                    TriggerEvent.SIGNAL_EVENT));
            } catch (ModelException me) {
                log.error(me.getMessage(), me);
            }
            timers.remove(sendId);
View Full Code Here

                    rootCtx.setLocal(name, value);
                    System.out.println("Set variable " + name + " to "
                        + value);
                } else if (SCXMLHelper.isStringEmpty(event)
                           || event.equalsIgnoreCase("null")) {
                    TriggerEvent[] evts = {new TriggerEvent(null,
                        TriggerEvent.SIGNAL_EVENT, null)};
                    exec.triggerEvents(evts);
                    if (exec.getCurrentStatus().isFinal()) {
                        System.out.println("A final configuration reached.");
                    }
                } else {
                    StringTokenizer st = new StringTokenizer(event);
                    int tkns = st.countTokens();
                    TriggerEvent[] evts = new TriggerEvent[tkns];
                    for (int i = 0; i < tkns; i++) {
                        evts[i] = new TriggerEvent(st.nextToken(),
                                TriggerEvent.SIGNAL_EVENT, null);
                    }
                    exec.triggerEvents(evts);
                    if (exec.getCurrentStatus().isFinal()) {
                        System.out.println("A final configuration reached.");
View Full Code Here

                if (wait == 0L) {
                    if (appLog.isDebugEnabled()) {
                        appLog.debug("<send>: Enqueued event '" + event
                            + "' with no delay");
                    }
                    derivedEvents.add(new TriggerEvent(event,
                        TriggerEvent.SIGNAL_EVENT, params));
                    return;
                }
            } else {
                // We know of no other
                if (appLog.isWarnEnabled()) {
                    appLog.warn("<send>: Unavailable target - "
                        + targetValue);
                }
                derivedEvents.add(new TriggerEvent(
                    EVENT_ERR_SEND_TARGETUNAVAILABLE,
                    TriggerEvent.ERROR_EVENT));
                // short-circuit the EventDispatcher
                return;
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.scxml.TriggerEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.