public class Statechart<T extends java.lang.Enum<T> & IStatechartState<?,T>>
implements java.io.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
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
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)
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.
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