StateMachine Related knowledge

Source: Internet
Author: User

The basic structure of a state, processmessage and optional enter exit and GetName.

Processmessager is used to process data. Enter and exit are similar to programming-oriented construction and destructor methods.

* <p>a state is A <code>State</code> object and must implement
* <code>processMessage</code> and optionally <code>enter/exit/getname</code>.
* The enter/exit methods is equivalent to the construction and destruction
* In Object oriented programming and is used to perform initialization and
* Cleanup of the state respectively

When to call the Exit method.

Will you call the Exit method when you transitionto another state from one state?

If the past is mapped according to object-oriented thinking, then exit is called when the state disappears

So will Transitionto lead to the destruction of state? Theoretically it should be, because statemachine can only be in one state, so the current state is destroyed while moving to another state

That is, the exit method is called.

The above is only their own logical reasoning structure, not guaranteed to be correct, when there is time to do an experimental verification.

Build the HSM and use Setinitialstate to set the initial state.

When a state machine is created <code>addState</code> was used to build the
* Hierarchy and <code>setinitialstate</code> is used to identify which of these
* is the initialstate.

Use Obtainmessage to create a message, send it to StateMachine using SendMessage, and invoke ProcessMessage of the current state when StateMachine receives the message.

After the created and started, messages was sent to a state
* Machine using <code>sendMessage</code> and the messages is created using
* <code>obtainmessage</code> When the state machine receives a message the
* Current state ' s <code>processmessage</code> is invoked. In the above example
* Ms1.processmessage'll be invoked first. The state could use <code>transitionTo</code>
* To change the current state to a new state

If a child state cannot process a message, it can be handled by returning false or not_handled to its parent state

* A unable to handle a message it may have the message processed
* by it parent by returning false or not_handled.

Will this message be automatic or manual for parent class processing? Theoretically, there should be a transitionto process.

If that is not necessary, then the addstate will establish a special relationship between its child state and the parent state when constructing the HSM.

So what's the deal with a defermessage?

When the message is processed, it is transferred to the state of halting

* <p>when All processing are completed a state machine could choose to call
* <code>transitiontohaltingstate</code> When the current <code>processingMessage</code>
* Returns the state machine would transfer to an internal <code>haltingstate</code>
* and invoke <code>halting</code>. Any message subsequently received by the State
* Machine'll cause <code>haltedprocessmessage</code> to be invoked.</p>

Stop the StateMachine method, quit

* <P>IF It is desirable-completely stop the state machine call <code>quit</code> or
* <CODE>QUITNOW</CODE>. These'll call <code>exit</code> of the parents,
* Call <code>onQuiting</code> and then exit thread/loopers.</p>

This place explicitly illustrates the exit method that invokes the current state and its parent class, with two questions:

1. Whether the parent class refers to its immediate parent class or iterates over the call

2. This place directly illustrates the invocation condition of exit, whether the previous inference is wrong: |

The exit method is to ensure that the statemachine environment is correct, the main work should be clear the current state for the entire environment, equivalent to the Reset function.

This mechanism guarantees the independence of each state, and also explains why the exit method that calls the parent state is iterated when exiting.

Describes the switching rules between States, the main criterion is to switch along the HSM line.

* <p>since the states is arranged in a hierarchy transitioning to a new state
* Causes current states to is exited and new states to be entered. To determine
* The list of States to being entered/exited the common parent closest to
* The current state is found. We then exit from the current state and its
* Parent's up-to-but-including the common parent state and then enter all
* The new states below the common parent down to the destination state.
* If There is no common parent all States be exited and then the new states
* Is entered.</p>

StateMachine Related knowledge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.