Example usage for org.apache.commons.scxml2.env SimpleDispatcher SimpleDispatcher

List of usage examples for org.apache.commons.scxml2.env SimpleDispatcher SimpleDispatcher

Introduction

In this page you can find the example usage for org.apache.commons.scxml2.env SimpleDispatcher SimpleDispatcher.

Prototype

SimpleDispatcher

Source Link

Usage

From source file:it.polito.elite.dog.drivers.appliances.base.ApplianceDriverInstance.java

private void initializeDeviceStateMachine() {
    // check if all needed elements are initialized
    if ((this.deviceSerial != null) && (!this.deviceSerial.isEmpty()) && (this.stateMachineLocator != null)) {
        // get the device-specific state machine URL, if any available
        URL stateMachineURL = this.stateMachineLocator.getStateMachine(this.deviceSerial);

        // check not null
        if (stateMachineURL != null) {
            try {
                // get the SCXML state machine (SCXML root element)
                this.stateMachine = SCXMLReader.read(stateMachineURL);

                // build a new executor
                this.executor = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(),
                        new SimpleErrorReporter());

                //set a scheduler dispatcher to handle delayed events
                this.executor.setEventdispatcher(new SimpleScheduler(this.executor));

                // set the state machine
                this.executor.setStateMachine(this.stateMachine);

                // set the root context
                JexlContext context = new JexlContext();

                // set the executor context
                this.executor.setRootContext(context);

                // add this class as listener of the state machine changes
                this.executor.addListener(this.stateMachine, this);

                // start the engine
                this.executor.go();
            } catch (IOException | ModelException | XMLStreamException e) {
                // log the error and continue if possible
                this.logger.log(LogService.LOG_ERROR,
                        "Error while creating the state machine executor associated to this driver instance",
                        e);// w ww. ja  v  a 2 s.  co  m
            }

        }
    }

}

From source file:org.onehippo.repository.scxml.AbstractActionTest.java

@Before
public void before() throws Exception {
    evtDispatcher = new SimpleDispatcher();
    errRep = new SimpleErrorReporter();
    appLog = new SimpleLog(getClass().getName());

    state = new State();
    onEntry = new OnEntry();
    state.addOnEntry(onEntry);/*from   w w w  . j a va 2 s . c o  m*/

    context = new GroovyContext();
    Evaluator evaluator = new GroovyEvaluator();
    exctx = EasyMock.createNiceMock(ActionExecutionContext.class);
    EasyMock.expect(exctx.getEventDispatcher()).andReturn(evtDispatcher).anyTimes();
    EasyMock.expect(exctx.getErrorReporter()).andReturn(errRep).anyTimes();
    EasyMock.expect(exctx.getAppLog()).andReturn(appLog).anyTimes();
    EasyMock.expect(exctx.getContext(state)).andReturn(context).anyTimes();
    EasyMock.expect(exctx.getEvaluator()).andReturn(evaluator).anyTimes();
    EasyMock.replay(exctx);
}

From source file:org.onehippo.repository.scxml.AbstractWorkflowTaskActionTest.java

@Before
public void before() throws Exception {
    evtDispatcher = new SimpleDispatcher();
    errRep = new SimpleErrorReporter();
    appLog = new SimpleLog(getClass().getName());

    final State state = new State();
    onEntry = new OnEntry();
    state.addOnEntry(onEntry);/*from w  w w  . ja  va 2s. c o  m*/

    context = new GroovyContext();
    final Evaluator evaluator = new GroovyEvaluator();
    exctx = EasyMock.createNiceMock(ActionExecutionContext.class);
    EasyMock.expect(exctx.getEventDispatcher()).andReturn(evtDispatcher).anyTimes();
    EasyMock.expect(exctx.getErrorReporter()).andReturn(errRep).anyTimes();
    EasyMock.expect(exctx.getAppLog()).andReturn(appLog).anyTimes();
    EasyMock.expect(exctx.getContext(state)).andReturn(context).anyTimes();
    EasyMock.expect(exctx.getEvaluator()).andReturn(evaluator).anyTimes();
    EasyMock.replay(exctx);
}

From source file:org.onehippo.repository.scxml.RepositorySCXMLExecutorFactory.java

@Override
public SCXMLExecutor createSCXMLExecutor(SCXMLDefinition scxmlDef) throws SCXMLException {

    SCXMLExecutor executor = new SCXMLExecutor(scxmlDef.getEvaluator(), new SimpleDispatcher(),
            new SCXMLStrictErrorReporter(scxmlDef));
    executor.setRootContext(scxmlDef.getEvaluator().newContext(null));
    try {/*ww w .j  a v  a  2  s. c  o  m*/
        executor.setStateMachine(scxmlDef.getSCXML());
    } catch (ModelException me) {
        throw new SCXMLException(me);
    }
    return executor;
}