com.evelopers.unimod.runtime
Class AbstractEventProcessor

java.lang.Object
  extended bycom.evelopers.unimod.runtime.AbstractEventProcessor
All Implemented Interfaces:
EventProcessor
Direct Known Subclasses:
InterpretationEventProcessor

public abstract class AbstractEventProcessor
extends java.lang.Object
implements EventProcessor


Constructor Summary
AbstractEventProcessor()
           
 
Method Summary
 void addEventProcessorListener(EventProcessorListener eventProcessorListener)
          Adds eventProcessorListener to listeners list.
 void addExceptionHandler(ExceptionHandler handler)
          Add handler for exceptions raised during event processing.
protected  boolean configExists(StateMachineConfig config)
           
protected  void disposeConfig(StateMachinePath path, StateMachineContext context, StateMachineConfig config)
           
protected  void fireAfterInputActionExecution(StateMachineContext context, StateMachinePath path, java.lang.String transition, java.lang.String inputActionName, java.lang.Object value)
           
protected  void fireAfterOnEnterActionExecution(StateMachineContext context, StateMachinePath path, java.lang.String stateName, java.lang.String outputAction)
           
protected  void fireAfterOutputActionExecution(StateMachineContext context, StateMachinePath path, java.lang.String transition, java.lang.String outputAction)
           
protected  void fireAfterSubmachineExecution(StateMachineContext context, Event e, StateMachinePath path, java.lang.String state, java.lang.String subMachine)
           
protected  void fireBeforeInputActionExecution(StateMachineContext context, StateMachinePath path, java.lang.String transition, java.lang.String inputAction)
           
protected  void fireBeforeOnEnterActionExecution(StateMachineContext context, StateMachinePath path, java.lang.String stateName, java.lang.String outputAction)
           
protected  void fireBeforeOutputActionExecution(StateMachineContext context, StateMachinePath path, java.lang.String transition, java.lang.String outputAction)
           
protected  void fireBeforeSubmachineExecution(StateMachineContext context, Event e, StateMachinePath path, java.lang.String state, java.lang.String subMachine)
           
protected  void fireComeToState(StateMachineContext context, StateMachinePath path, java.lang.String state)
           
protected  void fireCompositeTargetState(StateMachineContext context, StateMachinePath path, java.lang.String state)
           
protected  void fireEventProcessingFinished(StateMachineContext context, Event e, StateMachinePath path, StateMachineConfig c)
           
protected  void fireEventProcessingStarted(StateMachineContext context, Event e, StateMachinePath path, StateMachineConfig c)
           
protected  void fireEventSkipped(StateMachineContext context, StateMachinePath path, java.lang.String state, Event event)
           
protected  void fireException(StateMachineContext context, com.evelopers.common.exception.SystemException e)
          Sends notification about exception to exception handlers
protected  void fireStateMachineCameToFinalState(StateMachineContext context, StateMachinePath path, StateMachineConfig config)
           
protected  void fireTransitionCandidate(StateMachineContext context, StateMachinePath path, java.lang.String state, Event event, java.lang.String transition)
           
protected  void fireTransitionFound(StateMachineContext context, StateMachinePath path, java.lang.String state, Event event, java.lang.String transition)
           
protected  void fireTransitionNotFound(StateMachineContext context, StateMachinePath path, java.lang.String state, Event event)
           
protected  void fireTransitionsOfSuperstate(StateMachineContext context, StateMachinePath path, java.lang.String superstate, Event event)
           
protected  ControlledObjectsMap getControlledObjectsMap()
          Returns map of controlled objects.
abstract  ModelStructure getModelStructure()
          Returns the structure of the model.
protected  StateMachineConfig initConfig(StateMachinePath path, StateMachineContext context)
           
protected  boolean isFinalConfig(StateMachinePath path, StateMachineConfig config)
           
protected  boolean isTopConfig(StateMachinePath path, StateMachineConfig config)
           
protected  StateMachineConfig loadConfig(StateMachinePath path, StateMachineContext context)
           
 void process(Event event, StateMachineContext context)
          Processes given event in the given context using root state machine instance.
protected  void process(Event event, StateMachineContext context, StateMachinePath path)
          Processes given event using state machine instance defined by the given path.
protected abstract  StateMachineConfig process(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig config)
          Processes given event using state machine instance defined by the given config.
 void removeEventProcessorListener(EventProcessorListener eventProcessorListener)
          Removess eventProcessorListener from listeners list.
 void removeExceptionHandler(ExceptionHandler handler)
          Remove handler for exceptions raised during event processing.
 void setControlledObjectsMap(ControlledObjectsMap controlledObjectsMap)
          Sets map of controlled objects.
protected  void storeConfig(StateMachinePath path, StateMachineContext context, StateMachineConfig config)
           
protected abstract  StateMachineConfig transiteToStableState(StateMachineContext context, StateMachinePath path, StateMachineConfig config)
          Transites from initial state config to stable state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractEventProcessor

public AbstractEventProcessor()
Method Detail

process

public final void process(Event event,
                          StateMachineContext context)
Processes given event in the given context using root state machine instance.

This method is used by ModelEngine to notify event processor about events.

Specified by:
process in interface EventProcessor
Parameters:
event - triggered event to process
context - state machine context of the event

process

protected final void process(Event event,
                             StateMachineContext context,
                             StateMachinePath path)
Processes given event using state machine instance defined by the given path.

This method should be invoked for processing of event by included state machines.

Parameters:
event - triggered event to process
context - state machine context of the event
path - path that defines the state machine instance

initConfig

protected final StateMachineConfig initConfig(StateMachinePath path,
                                              StateMachineContext context)
                                       throws EventProcessorException
Throws:
EventProcessorException

loadConfig

protected final StateMachineConfig loadConfig(StateMachinePath path,
                                              StateMachineContext context)
                                       throws EventProcessorException
Throws:
EventProcessorException

storeConfig

protected final void storeConfig(StateMachinePath path,
                                 StateMachineContext context,
                                 StateMachineConfig config)
                          throws EventProcessorException
Throws:
EventProcessorException

disposeConfig

protected final void disposeConfig(StateMachinePath path,
                                   StateMachineContext context,
                                   StateMachineConfig config)
                            throws EventProcessorException
Throws:
EventProcessorException

configExists

protected final boolean configExists(StateMachineConfig config)

isTopConfig

protected final boolean isTopConfig(StateMachinePath path,
                                    StateMachineConfig config)
                             throws EventProcessorException
Throws:
EventProcessorException

isFinalConfig

protected final boolean isFinalConfig(StateMachinePath path,
                                      StateMachineConfig config)
                               throws EventProcessorException
Throws:
EventProcessorException

process

protected abstract StateMachineConfig process(Event event,
                                              StateMachineContext context,
                                              StateMachinePath path,
                                              StateMachineConfig config)
                                       throws com.evelopers.common.exception.SystemException
Processes given event using state machine instance defined by the given config.

Implementation of this method depends on approach. For instance it may be an interpretator of the in-memory state machine model or a precompiled switch-operator.

Implementations of this method should fire event processing events during execution.

Parameters:
event - triggered event to process
context - state machine context of the event
path - path to state machine instance
config - state machine config that defines the state machine instance
Returns:
state machine config after event processing
Throws:
com.evelopers.common.exception.SystemException - if some input or output action throws an exception. This exception will be handled by added ExceptionHandlers
See Also:
addExceptionHandler(ExceptionHandler), removeExceptionHandler(ExceptionHandler), addEventProcessorListener(EventProcessorListener), removeEventProcessorListener(EventProcessorListener)

transiteToStableState

protected abstract StateMachineConfig transiteToStableState(StateMachineContext context,
                                                            StateMachinePath path,
                                                            StateMachineConfig config)
                                                     throws com.evelopers.common.exception.SystemException
Transites from initial state config to stable state. This method should:
  1. Get transition from current initial state
  2. Transite using this transition
  3. If target state is composite then
    1. fireCompositeTargetState(com.evelopers.unimod.runtime.context.StateMachineContext, com.evelopers.unimod.runtime.StateMachinePath, java.lang.String)
    2. Get initial state from the composite state
    3. fireComeToState(com.evelopers.unimod.runtime.context.StateMachineContext, com.evelopers.unimod.runtime.StateMachinePath, java.lang.String) for new initial state
    4. Repeat transiteToStableState(com.evelopers.unimod.runtime.context.StateMachineContext, com.evelopers.unimod.runtime.StateMachinePath, com.evelopers.unimod.runtime.StateMachineConfig) with new initial state

Parameters:
context - state machine context of the event
path - path that defines the state machine instance
config - initial state to transite from
Returns:
stable state reached from the given initial
Throws:
com.evelopers.common.exception.SystemException

getModelStructure

public abstract ModelStructure getModelStructure()
Returns the structure of the model.

Specified by:
getModelStructure in interface EventProcessor
Returns:
the structure of the model

setControlledObjectsMap

public void setControlledObjectsMap(ControlledObjectsMap controlledObjectsMap)
Sets map of controlled objects. This method is invoked by ModelEngine from either stand alone and build-in factory methods.

Specified by:
setControlledObjectsMap in interface EventProcessor
Parameters:
controlledObjectsMap - map of controlled objects

getControlledObjectsMap

protected ControlledObjectsMap getControlledObjectsMap()
Returns map of controlled objects.

Returns:
map of controlled objects

addExceptionHandler

public void addExceptionHandler(ExceptionHandler handler)
Add handler for exceptions raised during event processing.

Specified by:
addExceptionHandler in interface EventProcessor
Parameters:
handler - handler for exceptions raised during event processing

removeExceptionHandler

public void removeExceptionHandler(ExceptionHandler handler)
Remove handler for exceptions raised during event processing.

Specified by:
removeExceptionHandler in interface EventProcessor
Parameters:
handler - handler for exceptions raised during event processing

fireException

protected void fireException(StateMachineContext context,
                             com.evelopers.common.exception.SystemException e)
Sends notification about exception to exception handlers

Parameters:
context - of event that led to exception
e - raised exception

addEventProcessorListener

public void addEventProcessorListener(EventProcessorListener eventProcessorListener)
Adds eventProcessorListener to listeners list.

Specified by:
addEventProcessorListener in interface EventProcessor
Parameters:
eventProcessorListener - eventProcessorListener to add

removeEventProcessorListener

public void removeEventProcessorListener(EventProcessorListener eventProcessorListener)
Removess eventProcessorListener from listeners list.

Specified by:
removeEventProcessorListener in interface EventProcessor
Parameters:
eventProcessorListener - eventProcessorListener to remove

fireEventProcessingStarted

protected void fireEventProcessingStarted(StateMachineContext context,
                                          Event e,
                                          StateMachinePath path,
                                          StateMachineConfig c)

fireEventProcessingFinished

protected void fireEventProcessingFinished(StateMachineContext context,
                                           Event e,
                                           StateMachinePath path,
                                           StateMachineConfig c)

fireStateMachineCameToFinalState

protected void fireStateMachineCameToFinalState(StateMachineContext context,
                                                StateMachinePath path,
                                                StateMachineConfig config)

fireBeforeSubmachineExecution

protected void fireBeforeSubmachineExecution(StateMachineContext context,
                                             Event e,
                                             StateMachinePath path,
                                             java.lang.String state,
                                             java.lang.String subMachine)

fireAfterSubmachineExecution

protected void fireAfterSubmachineExecution(StateMachineContext context,
                                            Event e,
                                            StateMachinePath path,
                                            java.lang.String state,
                                            java.lang.String subMachine)

fireBeforeOnEnterActionExecution

protected void fireBeforeOnEnterActionExecution(StateMachineContext context,
                                                StateMachinePath path,
                                                java.lang.String stateName,
                                                java.lang.String outputAction)

fireAfterOnEnterActionExecution

protected void fireAfterOnEnterActionExecution(StateMachineContext context,
                                               StateMachinePath path,
                                               java.lang.String stateName,
                                               java.lang.String outputAction)

fireBeforeOutputActionExecution

protected void fireBeforeOutputActionExecution(StateMachineContext context,
                                               StateMachinePath path,
                                               java.lang.String transition,
                                               java.lang.String outputAction)

fireAfterOutputActionExecution

protected void fireAfterOutputActionExecution(StateMachineContext context,
                                              StateMachinePath path,
                                              java.lang.String transition,
                                              java.lang.String outputAction)

fireBeforeInputActionExecution

protected void fireBeforeInputActionExecution(StateMachineContext context,
                                              StateMachinePath path,
                                              java.lang.String transition,
                                              java.lang.String inputAction)

fireAfterInputActionExecution

protected void fireAfterInputActionExecution(StateMachineContext context,
                                             StateMachinePath path,
                                             java.lang.String transition,
                                             java.lang.String inputActionName,
                                             java.lang.Object value)

fireTransitionCandidate

protected void fireTransitionCandidate(StateMachineContext context,
                                       StateMachinePath path,
                                       java.lang.String state,
                                       Event event,
                                       java.lang.String transition)

fireTransitionsOfSuperstate

protected void fireTransitionsOfSuperstate(StateMachineContext context,
                                           StateMachinePath path,
                                           java.lang.String superstate,
                                           Event event)

fireTransitionFound

protected void fireTransitionFound(StateMachineContext context,
                                   StateMachinePath path,
                                   java.lang.String state,
                                   Event event,
                                   java.lang.String transition)

fireTransitionNotFound

protected void fireTransitionNotFound(StateMachineContext context,
                                      StateMachinePath path,
                                      java.lang.String state,
                                      Event event)

fireEventSkipped

protected void fireEventSkipped(StateMachineContext context,
                                StateMachinePath path,
                                java.lang.String state,
                                Event event)

fireCompositeTargetState

protected void fireCompositeTargetState(StateMachineContext context,
                                        StateMachinePath path,
                                        java.lang.String state)

fireComeToState

protected void fireComeToState(StateMachineContext context,
                               StateMachinePath path,
                               java.lang.String state)