public class SCXMLExecutor extends Object implements SCXMLIOProcessor
The SCXML "engine" that executes SCXML documents. The particular semantics used by this engine for executing the SCXML are encapsulated in the SCXMLSemantics implementation that it uses.
The default implementation is
org.apache.commons.scxml2.semantics.SCXMLSemanticsImpl
The executor uses SCXMLExecutionContext to manage the state and provide all the services to the SCXMLSemantics implementation.
SCXMLSemantics
DEFAULT_EVENT_PROCESSOR, EVENT_PROCESSOR_ALIAS_PREFIX, INTERNAL_EVENT_PROCESSOR, PARENT_EVENT_PROCESSOR, SCXML_EVENT_PROCESSOR, SCXML_SESSION_EVENT_PROCESSOR_PREFIX
Constructor and Description |
---|
SCXMLExecutor()
Convenience constructor.
|
SCXMLExecutor(Evaluator expEvaluator,
EventDispatcher evtDisp,
ErrorReporter errRep)
Constructor.
|
SCXMLExecutor(Evaluator expEvaluator,
EventDispatcher evtDisp,
ErrorReporter errRep,
SCXMLSemantics semantics)
Constructor.
|
SCXMLExecutor(SCXMLExecutor parentSCXMLExecutor)
Constructor using a parent SCXMLExecutor
|
Modifier and Type | Method and Description |
---|---|
void |
addEvent(TriggerEvent evt)
Add a new external event, which may be done concurrently, and even when the current SCInstance is detached.
|
void |
addListener(Observable observable,
SCXMLListener listener)
Add a listener to the
Observable . |
void |
attachInstance(SCInstance instance)
Re-attach a previously detached SCInstance.
|
SCInstance |
detachInstance()
Detach the current SCInstance to allow external serialization.
|
protected void |
eventStep(TriggerEvent event) |
ErrorReporter |
getErrorReporter()
Get the environment specific error reporter.
|
Evaluator |
getEvaluator()
Get the expression evaluator in use.
|
EventDispatcher |
getEventdispatcher()
Get the event dispatcher.
|
Context |
getGlobalContext()
Get the global context for the state machine execution.
|
NotificationRegistry |
getNotificationRegistry()
Get the notification registry.
|
protected SCXMLExecutor |
getParentSCXMLExecutor() |
int |
getPendingEvents() |
Context |
getRootContext()
Get the root context for the state machine execution.
|
protected SCInstance |
getSCInstance()
Get the state chart instance for this executor.
|
SCXML |
getStateMachine()
Get the state machine that is being executed.
|
Status |
getStatus()
Get the current state machine instance status.
|
void |
go()
Initiate state machine execution.
|
boolean |
hasPendingEvents() |
boolean |
isCheckLegalConfiguration() |
boolean |
isRunning() |
boolean |
isSingleContext() |
protected void |
logState()
Log the current set of active states.
|
void |
registerInvokerClass(String type,
Class<? extends Invoker> invokerClass)
Register an Invoker for this target type.
|
void |
removeListener(Observable observable,
SCXMLListener listener)
Remove this listener from the
Observable . |
void |
reset()
Clear all state and begin executing the state machine
|
void |
setCheckLegalConfiguration(boolean checkLegalConfiguration)
Set if the SCXML configuration should be checked before execution (default = true)
|
void |
setConfiguration(Set<String> atomicStateIds)
Initializes the state machine with a specific active configuration
This will first (re)initialize the current state machine: clearing all variable contexts, histories and current
status, and clones the SCXML root datamodel into the root context.
|
void |
setErrorReporter(ErrorReporter errorReporter)
Set or replace the error reporter
|
void |
setEvaluator(Evaluator evaluator)
Set or replace the expression evaluator
If the state machine instance has been initialized before, it will be initialized again, destroying all existing
state!
|
void |
setEventdispatcher(EventDispatcher eventdispatcher)
Set or replace the event dispatch
|
void |
setRootContext(Context rootContext)
Set the root context for the state machine execution.
|
void |
setSingleContext(boolean singleContext) |
void |
setStateMachine(SCXML stateMachine)
Set or replace the state machine to be executed
If the state machine instance has been initialized before, it will be initialized again, destroying all existing
state!
|
void |
triggerEvent(TriggerEvent evt)
Convenience method when only one event needs to be triggered.
|
void |
triggerEvents()
Trigger all pending and incoming events, until there are no more pending events
|
void |
triggerEvents(TriggerEvent[] evts)
The worker method.
|
void |
unregisterInvokerClass(String type)
Remove the Invoker registered for this target type (if there is one registered).
|
public SCXMLExecutor()
public SCXMLExecutor(Evaluator expEvaluator, EventDispatcher evtDisp, ErrorReporter errRep)
expEvaluator
- The expression evaluatorevtDisp
- The event dispatchererrRep
- The error reporterpublic SCXMLExecutor(Evaluator expEvaluator, EventDispatcher evtDisp, ErrorReporter errRep, SCXMLSemantics semantics)
expEvaluator
- The expression evaluatorevtDisp
- The event dispatchererrRep
- The error reportersemantics
- The SCXML semanticspublic SCXMLExecutor(SCXMLExecutor parentSCXMLExecutor)
parentSCXMLExecutor
- the parent SCXMLExecutorprotected SCXMLExecutor getParentSCXMLExecutor()
public Status getStatus()
public void setConfiguration(Set<String> atomicStateIds) throws ModelException
This will first (re)initialize the current state machine: clearing all variable contexts, histories and current status, and clones the SCXML root datamodel into the root context.
atomicStateIds
- The set of atomic state ids for the state machineModelException
- when the state machine hasn't been properly configured yet, when an unknown or illegal
stateId is specified, or when the specified active configuration does not represent a legal configuration.SCInstance#initialize()}
,
SCXMLSemantics#isLegalConfiguration(java.util.Set, ErrorReporter)}
public void setEvaluator(Evaluator evaluator) throws ModelException
If the state machine instance has been initialized before, it will be initialized again, destroying all existing state!
Also the external event queue will be cleared.
evaluator
- The evaluator to setModelException
- if attempting to set a null value or the state machine instance failed to re-initializepublic Evaluator getEvaluator()
public Context getRootContext()
The root context can be used for providing external data to the state machine
public Context getGlobalContext()
The global context is the top level context within the state machine itself and should be regarded and treated "read-only" from external usage.
public void setRootContext(Context rootContext)
rootContext
- The Context that ties to the host environment.public void setSingleContext(boolean singleContext) throws ModelException
ModelException
public boolean isSingleContext()
public SCXML getStateMachine()
Datamodel
s associated with this state
machine definition.public void setStateMachine(SCXML stateMachine) throws ModelException
If the state machine instance has been initialized before, it will be initialized again, destroying all existing state!
Also the external event queue will be cleared.
stateMachine
- The state machine to setModelException
- if attempting to set a null value or the state machine instance failed to re-initializepublic ErrorReporter getErrorReporter()
public void setErrorReporter(ErrorReporter errorReporter)
errorReporter
- The error reporter to set, if null a SimpleErrorReporter instance will be used insteadpublic EventDispatcher getEventdispatcher()
public void setEventdispatcher(EventDispatcher eventdispatcher)
eventdispatcher
- The event dispatcher to set, if null a SimpleDispatcher instance will be used insteadpublic void setCheckLegalConfiguration(boolean checkLegalConfiguration)
checkLegalConfiguration
- flag to setpublic boolean isCheckLegalConfiguration()
public NotificationRegistry getNotificationRegistry()
public void addListener(Observable observable, SCXMLListener listener)
Observable
.observable
- The Observable
to attach the listener to.listener
- The SCXMLListener.public void removeListener(Observable observable, SCXMLListener listener)
Observable
.observable
- The Observable
.listener
- The SCXMLListener to be removed.public void registerInvokerClass(String type, Class<? extends Invoker> invokerClass)
type
- The target type (specified by "type" attribute of the invoke element).invokerClass
- The Invoker class.public void unregisterInvokerClass(String type)
type
- The target type (specified by "type" attribute of the invoke element).public SCInstance detachInstance()
attachInstance(SCInstance)
can be used to re-attach a previously detached instance
Note: until an instance is re-attached, no operations are allowed (and probably throw exceptions) except
for addEvent(TriggerEvent)
which might still be used (concurrently) by running Invokers, or
hasPendingEvents()
to check for possible pending events.
public void attachInstance(SCInstance instance)
Note: an already attached instance will get overwritten (and thus lost).
instance
- An previously detached SCInstancepublic boolean isRunning()
public void go() throws ModelException
ModelException
- in case there is a fatal SCXML object
model problem.public void reset() throws ModelException
ModelException
- if the state machine instance failed to initializepublic void addEvent(TriggerEvent evt)
No processing of the vent will be done, until the next triggerEvent methods is invoked.
addEvent
in interface SCXMLIOProcessor
evt
- an external eventpublic boolean hasPendingEvents()
public int getPendingEvents()
public void triggerEvent(TriggerEvent evt) throws ModelException
evt
- the external events which triggered during the last
time quantumModelException
- in case there is a fatal SCXML object
model problem.public void triggerEvents(TriggerEvent[] evts) throws ModelException
evts
- an array of external events which triggered during the last
time quantumModelException
- in case there is a fatal SCXML object
model problem.public void triggerEvents() throws ModelException
ModelException
- in case there is a fatal SCXML object model problem.protected void eventStep(TriggerEvent event) throws ModelException
ModelException
protected SCInstance getSCInstance()
protected void logState()
Copyright © 2005–2015 The Apache Software Foundation. All rights reserved.