- java.lang.Object
- com.anylogic.engine.Statechart<T>
- All Implemented Interfaces:
- com.anylogic.engine.internal.Child,- Serializable
public class Statechart<T extends Enum<T> & IStatechartState<?,T>> extends Object implements Serializable, com.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
 agent.
There are two ways to send a message to the statechart:
- call
- call
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.
fireEvent() supports queuing for incoming messages. 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)
There are two ways to send a message to the statechart:
- call
receiveMessage(Object) or receiveMessage(int) method, and- call
fireEvent(Object) 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.
fireEvent() supports queuing for incoming messages. 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:
- AnyLogic North America, LLC https://anylogic.com
- See Also:
- Serialized Form
| Constructor | Description | 
|---|---|
| Statechart | Constructs the statechart object. | 
| Modifier and Type | Method | Description | 
|---|---|---|
| void | fireEvent | Adds a message to the statechart queue. | 
| Agent | getActiveObject() | Deprecated.
 | 
| T | getActiveSimpleState() | Returns the currently active simple state of the statechart | 
| Agent | getAgent() | Returns the agent that owns the statechart. | 
| String | getFullName() | Returns the name of the statechart prefixed by the full name of its agent. | 
| Set<T> | getFullState() | Returns the currently active composite states of the statechart,
 including the current simple state. | 
| String | getName() | Returns the name of the statechart as specified by the user | 
| T | getState() | Returns the currently active simple state of the statechart. Please note that this function doesn't return composite states | 
| boolean | isStateActive | Returns  trueif the statechart is at the specified state, i.e. | 
| void | onChange() | Should be called if the statechart has at least one transition of type
 Condition or Rate when something changes in the agent and
 probably rate changes or condition becomes  true. | 
| void | onDestroy() | Should be called when the statechart is destroyed, e.g. | 
| boolean | receiveMessage | Same as  receiveMessage(Object)but with an integer as message. | 
| boolean | receiveMessage | 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 | Deprecated. | 
| void | setActiveState_xjal | This method is shouldn't be called by user
 (is public due to technical reasons) | 
| void | start() | Should be called when the agent starts. | 
| String | toString() | 
public Statechart(Agent ao, short maxat) 
Constructs the statechart object. Does not start the statechart.
- Parameters:
- ao- agent where this statechart belongs to
- maxat- maximum possible number of concurrently active transitions
public String getName()
Returns the name of the statechart as specified by the user
- Returns:
- The name of the statechart.
public String getFullName()
Returns the name of the statechart prefixed by the full name of its agent.
- Returns:
- The full name of the statechart.
public String toString()
public Agent getAgent()
Returns the agent that owns the statechart.
- Returns:
- The agent owning this statechart.
@Deprecated public Agent getActiveObject()
Deprecated.
Use 
getAgent() insteadpublic boolean receiveMessage(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:
- trueif the message matched at least one trigger
public boolean receiveMessage(int msg) 
Same as 
receiveMessage(Object) but with an integer as message.- Parameters:
- msg- the integer posted to the statechart
- Returns:
- trueif the message matched at least one trigger
public boolean isStateActive(IStatechartState 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:
- trueif state is currently active
public T getState()
Returns the currently active simple state of the statechart.
Please note that this function doesn't return composite states
Please note that this function doesn't return composite states
- Returns:
- the current simple state
- Since:
- 7.3.7
- See Also:
public T getActiveSimpleState()
Returns the currently active simple state of the statechart
- Returns:
- the current simple state
public Set<T> getFullState()
Returns the currently active composite states of the statechart,
 including the current simple state. The returned set is unordered.
- Since:
- 8.0
public void fireEvent(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
@AnyLogicInternalCodegenAPI public void start()
Should be called when the agent starts. Activates the statechart:
 starts the initially active transitions, performs the entry actions, etc.
@AnyLogicInternalCodegenAPI public void setActiveState_xjal(T st) 
This method is shouldn't be called by user
 (is public due to technical reasons)
public void onChange()
Should be called if the statechart has at least one transition of type
 Condition or Rate when something changes in the agent and
 probably rate changes or condition becomes 
true.@AnyLogicInternalCodegenAPI public void onDestroy()
Should be called when the statechart is destroyed, e.g. when the owner agent 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
Deletes all events scheduled by the currently active statechart transitions and unsubmits all their conditions from the numeric engine
@AnyLogicInternalCodegenAPI @Deprecated public void restoreOwner(Object owner) 
Deprecated.
This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading
This method restores owner of this object
The method is used in snapshot saving/loading
- Specified by:
- restoreOwnerin interface- com.anylogic.engine.internal.Child
- Parameters:
- owner- owner of this object, usually- Agent,- Experimentor- ShapeGroup
getAgent()instead