一个state的基本构造,processMessage 以及可选的enter exit 和getName。

processMessager是用于处理数据。 enter 和exit 则是类似于 面向编程的构造和析构方法。

* <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 are equivalent to the construction and destruction
* in Object Oriented programming and are used to perform initialization and
* cleanup of the state respectively


什么时候会调用exit这个方法。

当从一个state transitionTo 另一个State 的时候是否会调用exit方法?

如果按照面向对象的思想对应过去, 之后在这个state消失的时候才会调用exit

那么transitionTo 是否会导致state的销毁?理论上应该是会的, 因为StateMachine只能处于一个state,所以在转移到别的state的同时会销毁当前state

也就是会调用exit方法。

以上仅仅是自己的逻辑推理结构, 不保证正确, 有空的时候自己做个实验验证下。


构建hsm,利用setInitialState来设定初始状态。

When a state machine is created <code>addState</code> is used to build the
* hierarchy and <code>setInitialState</code> is used to identify which of these
* is the initial state.

 


使用obtainMessage 来创建消息, 使用sendMessage发送给StateMachine,  当StateMachine收到消息时会调用当前状态的processMessage。

After the state machine is created and started, messages are sent to a state
* machine using <code>sendMessage</code> and the messages are 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 will be invoked first. The state may use <code>transitionTo</code>
* to change the current state to a new state

 


如果子状态不能处理某个消息时,可以通过返回false或者NOT_HANDLED交给其父状态处理

* a child state is unable to handle a message it may have the message processed
* by its parent by returning false or NOT_HANDLED.

这个消息转为父类处理是自动的还是手动的?理论上来说应该有一个transitionTo的过程。

如果说不需要的话,那么说说明构造hsm的时候addState会建立其子状态和父状态之间的特殊关系。

那么有个deferMessage这个是处理什么消息的呢?

 


当消息处理完了之后, 会转移到Halting的状态

* <p>When all processing is completed a state machine may choose to call
* <code>transitionToHaltingState</code>. When the current <code>processingMessage</code>
* returns the state machine will transfer to an internal <code>HaltingState</code>
* and invoke <code>halting</code>. Any message subsequently received by the state
* machine will cause <code>haltedProcessMessage</code> to be invoked.</p>


停止stateMachine的方法,quit

* <p>If it is desirable to completely stop the state machine call <code>quit</code> or
* <code>quitNow</code>. These will call <code>exit</code> of the current state and its parents,
* call <code>onQuiting</code> and then exit Thread/Loopers.</p>

这个地方明确的说明了会调用当前State和其父类state的exit方法,有两个疑问:

1、其父类是指的其直系父类还是会迭代调用

2、这个地方直接说明了exit的调用条件,是否说明之前的推断是错误的:|

 

 

exit 方法是为了保证StateMachine的环境正确性,感觉其主要工作应该是清楚当前状态对于整个环境的改变,相当于复位功能。

这个机制就保证了各个状态之间的独立性, 也说明了为什么在退出的时候会迭代的调用父状态的exit方法。


介绍了状态之间的切换规则, 主要的标准是沿着HSM这条线进行切换。

 

* <p>Since the states are arranged in a hierarchy transitioning to a new state
* causes current states to be exited and new states to be entered. To determine
* the list of states to be 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 not including the common parent state and then enter all
* of the new states below the common parent down to the destination state.
* If there is no common parent all states are exited and then the new states
* are entered.</p>

stateMachine 相关知识的更多相关文章

  1. 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸

    类的继承案例解析,python相关知识延伸 作者:白宁超 2016年10月10日22:36:57 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给 ...

  2. 移动WEB像素相关知识

    了解移动web像素的知识,主要是为了切图时心中有数.本文主要围绕一个问题:怎样根据设备厂商提供的屏幕尺寸和物理像素得到我们切图需要的逻辑像素?围绕这个问题以iphone5为例讲解涉及到的web像素相关 ...

  3. listener监听器的相关知识

    从别人的博客上我学习了listener的相关知识现在分享给大家 1.概念: 监听器就是一个实现特定接口的普通java程序,这个程序专门用于监听另一个java对象的方法调用或属性改变,当被监听对象发生上 ...

  4. UIViewController相关知识

    title: UIViewController 相关知识date: 2015-12-13 11:50categories: IOS tags: UIViewController 小小程序猿我的博客:h ...

  5. 【转】java NIO 相关知识

    原文地址:http://www.iteye.com/magazines/132-Java-NIO Java NIO(New IO)是从Java 1.4版本开始引入的一个新的IO API,可以替代标准的 ...

  6. NSString使用stringWithFormat拼接的相关知识

    NSString使用stringWithFormat拼接的相关知识 保留2位小数点 1 2 3 4 //.2代表小数点后面保留2位(2代表保留的数量) NSString *string = [NSSt ...

  7. iOS网络相关知识总结

    iOS网络相关知识总结 1.关于请求NSURLRequest? 我们经常讲的GET/POST/PUT等请求是指我们要向服务器发出的NSMutableURLRequest的类型; 我们可以设置Reque ...

  8. 电路相关知识--读<<继电器是如何成为CPU的>>

    电路相关知识–读<<继电器是如何成为CPU的>> */--> *///--> *///--> 电路相关知识–读<<继电器是如何成为CPU的> ...

  9. 地址标记,SpringMVC转发与调用相关知识存档

    1.mytest_mavenprj1中,index的 <a href="login/login.html">点击登录</a> 与 <a href=&q ...

随机推荐

  1. MongoDB学习-->Spring Data Mongodb-->MongodbTemplate

    配置文件application-dev.yml: server: port: 8888 mongo: host: localhost port: 27017 timeout: 60000 db: ma ...

  2. ES6 异步编程之一:Generator

    Generator 生成器是es6原生提供的异步编程方案,其语法行为和传统函数完全不同,阮大的<ECMAScript 6 入门>一书中对生成器有比较详尽的介绍,还有一些其他的文章可以参考, ...

  3. log4net配置分析

    appender   附加器 RollingFileAppender      滚动文件appender MaxSizeRollBackups      最大尺寸回滚 ConversionPatter ...

  4. Java生产者消费者模式

    为什么要使用生产者和消费者模式 在线程世界里,生产者就是生产数据的线程,消费者就是消费数据的线程.在多线程开发当中,如果生产者处理速度很快,而消费者处理速度很慢,那么生产者就必须等待消费者处理完,才能 ...

  5. 备忘 CSS字体中英文名称对照表

    转载自:http://www.jb51.net/css/67658.html 在CSS文件中,我们常看到有些字体名称变成了乱码,这是由于编写者将中文字体的名字直接写成了中文,并且再上传或者拷贝复制的时 ...

  6. 以Java 8 为基准

    1.以Java 8 为基准 Spring Boot 2.0 要求Java 版本必须8以上, Java 6 和 7 不再支持. 2.内嵌容器包结构调整 为了支持reactive使用场景,内嵌的容器包结构 ...

  7. 基于openstack stable queens版本阅读解析

    基于openstack stable queens版本阅读解析 基于 centos7.5 的linux系统 架构 如下所示,为cinder的官方架构说明: 这里写图片描述 各个组件介绍如下: - DB ...

  8. bzoj3210 花神的浇花集会 坐标

    题目大意:给定平面上的n个点,求一个点到这n个点的切比雪夫距离之和最小 与3170不同的是这次选择的点无需是n个点中的一个 首先将每个点(x,y)变为(x+y,x-y) 这样新点之间的曼哈顿距离的一半 ...

  9. bzoj 1185 [HNOI2007]最小矩形覆盖 凸包+旋转卡壳

    题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...

  10. Java基础加强-(注解,动态代理,类加载器,servlet3.0新特性)

    1.   Annotation注解 1.1.  Annotation概述 Annotation是JDK 5.0以后提供对元数据的支持,可以在编译.加载和运行时被读取,并执行相应的处理.所谓Annota ...