com.xj.anylogic.engine
Class Statechart

java.lang.Object
  extended by com.xj.anylogic.engine.Statechart
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, java.io.Serializable

public class Statechart
extends java.lang.Object
implements java.io.Serializable, com.xj.anylogic.engine.internal.Child

Statechart - the most advanced construct to describe event- and time-driven behavior. Statechart has states and transitions. Transitions may be triggered by timeouts or rates, messages received by the statechart, and conditions. Transition execution may lead to a state change where a new set of transitions becomes active. States in the statechart may be hierarchical, i.e. contain other states and transitions. The actual structure of state diagram is stored in the active object.
There are two ways to send a message to the statechart:
- call receiveMessage() method, and
- call fireEvent() method.
receiveMessage() assumes no queuing for incoming messages. If the received message cannot immediately cause scheduling of a transition, it is discarded. Therefore, if, for example, there are two transitions: one (from state S0 to S1) triggered by message A, and another (from S1 to S2) triggered by message B, and the statechart receives messages A and B at the same time while in the state S0, only first transition will be taken, and message B will be discarded. This is different to AnyLogic 5.
fireEvent() supports queuing for incoming messages and has exactly same semantics as in AnyLogic 5. The message added to the queue by fireEvent() can be consumed either immediately or after a number of zero-time steps of the statechart, otherwise it will be discarded. In the example above both transitions will be taken if the messages A and B are received via fireEvent() method.
Using fireEvent() is less efficient than using receiveMessage() both time and memory-wise, so if you do care and are sure that no "chains" of zero-time message-triggered transitions can happen, use receiveMessage().
Memory: sizeof(Object) + 18 bytes + sizeof(array with concurrently active transitions) + sizeof(message queue)

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

Constructor Summary
Statechart(ActiveObject ao, short maxat)
          Constructs the statechart object.
 
Method Summary
 void fireEvent(java.lang.Object msg)
          Adds a message to the statechart queue.
 ActiveObject getActiveObject()
          Returns the active object that owns the statechart.
 short getActiveSimpleState()
          Returns the currenly active simple state of the statechart
 java.lang.String getFullName()
          Returns the name of the statechart prefixed by the full name of its active object.
 java.lang.String getName()
          Returns the name of the statechart as specified by the user
 boolean isStateActive(short state)
          Returns true if the statechart is at the specified state, i.e. exactly in the state for a simple state and in one of its inner states for a composite state.
 void onChange()
          Should be called if the statechart has at least one transition of type Condition or Rate when something changes in the active object and probably rate changes or condition becomes true.
 void onDestroy()
          Should be called when the statechart is destroyed, e.g. when the owner active object is destroyed or when statechart comes to final state.
 boolean receiveMessage(int msg)
          Same as receiveMessage(Object) but with an integer as message.
 boolean receiveMessage(java.lang.Object msg)
          Posts a message to the statechart without queueing: the message is either immediately consumed (if there is a matching transition active) or is discarded.
 void restoreOwner(java.lang.Object owner)
          This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading
 void setActiveState_xjal(short st)
          This method is shouldn't be called by user (is public due to technical reasons)
 void start()
          Should be called when the active object starts.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Statechart

public Statechart(ActiveObject ao,
                  short maxat)
Constructs the statechart object. Does not start the statechart.

Parameters:
ao - active object where this statechart belongs to
maxat - maximum possible number of concurrently active transitions
Method Detail

getName

public java.lang.String getName()
Returns the name of the statechart as specified by the user

Returns:
The name of the statechart.

getFullName

public java.lang.String getFullName()
Returns the name of the statechart prefixed by the full name of its active object.

Returns:
The full name of the statechart.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getActiveObject

public ActiveObject getActiveObject()
Returns the active object that owns the statechart.

Returns:
The active object owning this statechart.

receiveMessage

public boolean receiveMessage(java.lang.Object msg)
Posts a message to the statechart without queueing: the message is either immediately consumed (if there is a matching transition active) or is discarded. If a message matches two or more transitions, they will be able to execute independently (subject to the statechart structure), thus consuming the same message. If two or more messages arrive simultaneously and both match the trigger of a transition, the second message will be ignored.

Parameters:
msg - the message posted to the statechart
Returns:
true if the message matched at least one trigger

receiveMessage

public boolean receiveMessage(int msg)
Same as receiveMessage(Object) but with an integer as message.

Parameters:
msg - the integer posted to the statechart
Returns:
true if the message matched at least one trigger

isStateActive

public boolean isStateActive(short state)
Returns true if the statechart is at the specified state, i.e. exactly in the state for a simple state and in one of its inner states for a composite state.

Parameters:
state - the state
Returns:
true if state is currently active

getActiveSimpleState

public short getActiveSimpleState()
Returns the currenly active simple state of the statechart

Returns:
the current simple state

fireEvent

public void fireEvent(java.lang.Object msg)
Adds a message to the statechart queue. It will be consumed either immediately or after a number of zero-time steps of the statechart, otherwise it will be discarded.

Parameters:
msg - the message received by the statechart

start

public void start()
Should be called when the active object starts. Activates the statechart: starts the initially active transitions, performs the entry actions, etc.


setActiveState_xjal

public void setActiveState_xjal(short st)
This method is shouldn't be called by user (is public due to technical reasons)


onChange

public void onChange()
Should be called if the statechart has at least one transition of type Condition or Rate when something changes in the active object and probably rate changes or condition becomes true.


onDestroy

public void onDestroy()
Should be called when the statechart is destroyed, e.g. when the owner active object is destroyed or when statechart comes to final state.
Deletes all events scheduled by the currently active statechart transitions and unsubmits all their conditions from the numeric engine


restoreOwner

public void restoreOwner(java.lang.Object owner)
This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading

Specified by:
restoreOwner in interface com.xj.anylogic.engine.internal.Child
Parameters:
owner - owner of this object, usually ActiveObject, Experiment or ShapeGroup


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.