//状态机元数据描述 @StateMachine protected static interface CustomerLifecycleMeta{ @StateSet static interface States { @Initial @Transition(event = CustomerLifecycleMeta.Events.Activate.class, value = {Active.class}) static interface Draft{} @Transitions({@Transition(event = CustomerLifecycleMeta.Events.Suspend.class, value = Suspended.class), @Transition(event = CustomerLifecycleMeta.Events.Cancel.class, value = Cancelled.class)}) static interface Active {} @Transition(event = CustomerLifecycleMeta.Events.Resume.class, value = Active.class) static interface Suspended {} @Final static interface Cancelled {} } @EventSet static interface Events { static interface Activate {} static interface Suspend {} static interface Resume {} static interface Cancel {} } }
public abstract static class ReactiveObject { @StateIndicator private String state = null; protected void initialState(String stateName) { if ( null == state ) { this.state = stateName; } else { throw new IllegalStateException("Cannot call initialState method after state had been intialized."); } } public String getState() { return state; } }
// 标记生命周期元数据引用的业务对象(反应型对象)
@LifecycleMeta(CustomerLifecycleMeta.class) public static class Customer extends ReactiveObject { protected Customer() { initialState(Draft.class.getSimpleName()); } @Event public void activate() {} @Event public void suspend() {} @Event public void resume() {} @Event public void cancel() {} }
// 测试用例
@Test public void test_standalone_object_without_relation_lifecycle() throws VerificationException { Customer customer = new Customer(); customer.activate(); assertEquals(CustomerLifecycleMeta.States.Active.class.getSimpleName(), customer.getState()); customer.suspend(); assertEquals(CustomerLifecycleMeta.States.Suspended.class.getSimpleName(), customer.getState()); customer.resume(); assertEquals(CustomerLifecycleMeta.States.Active.class.getSimpleName(), customer.getState()); customer.cancel(); assertEquals(CustomerLifecycleMeta.States.Canceled.class.getSimpleName(), customer.getState()); }
正确配置执行环境参数后可以获得下面的引擎执行Log
//开始执行测试方法
Processing test: test_standalone_object_with_definite_relation(net.madz.lifecycle.engine.EngineCoreFunctionPositiveTests)
//状态机引擎拦截到标记有@Transition的方法执行,开始执行生命周期相关工作
[FINE]: Found Intercept Point: class net.madz.lifecycle.engine.CoreFuntionTestMetadata$Customer.activate( )
[FINE]: Intercepting....instatiating InterceptContext ...
[FINE]: Intercepting....InterceptorController is doing exec ...
[FINE]: Intercepting....instantiating LifecycleInterceptor
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @preExec
[FINE]: intercepting [net.madz.lifecycle.engine.CoreFuntionTestMetadata$Customer@67bba966]
from state: [Draft]
[FINE]: Step 1. start validating State [Draft]
[FINE]: Step 2. start validating transition: [Activate] on state: [Draft]
[FINE]: Step 3. start validating inbound relation constraint is next state is predictable before method invocation.
[FINE]: Step 4. start callback before state change from : Draft => to : Active
[FINE]: intercepting with: net.madz.bcel.intercept.CallableInterceptor @intercept
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @postExec
[FINE]: Step 5. start validating inbound relation constraint is next state after method invocation.
[FINE]: Step 6. Set next state to reactiveObject.
[FINE]: Step 6. ReactiveObject is tranisited to state: [Active]
[FINE]: Step 7. Start Callback after state change from : Draft => to : Active
[FINE]: Step 8. Start fire state change event.
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @cleanup
[FINE]: Intercepting....LifecycleInterceptor is doing cleanup ...
[FINE]: Found Intercept Point: class net.madz.lifecycle.engine.CoreFuntionTestMetadata$InternetServiceOrder.start( )
[FINE]: Intercepting....instatiating InterceptContext ...
[FINE]: Intercepting....InterceptorController is doing exec ...
[FINE]: Intercepting....instantiating LifecycleInterceptor
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @preExec
[FINE]: intercepting [net.madz.lifecycle.engine.CoreFuntionTestMetadata$InternetServiceOrder@3033e3e0]
from state: [New]
[FINE]: Step 1. start validating State [New]
[FINE]: Step 2. start validating transition: [Start] on state: [New]
[FINE]: Step 3. start validating inbound relation constraint is next state is predictable before method invocation.
[FINE]: Step 4. start callback before state change from : New => to : InService
[FINE]: intercepting with: net.madz.bcel.intercept.CallableInterceptor @intercept
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @postExec
[FINE]: Step 5. start validating inbound relation constraint is next state after method invocation.
[FINE]: Step 6. Set next state to reactiveObject.
[FINE]: Step 6. ReactiveObject is tranisited to state: [InService]
[FINE]: Step 7. Start Callback after state change from : New => to : InService
[FINE]: Step 8. Start fire state change event.
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @cleanup
[FINE]: Intercepting....LifecycleInterceptor is doing cleanup ...
Finish test: test_standalone_object_with_definite_relation(net.madz.lifecycle.engine.EngineCoreFunctionPositiveTests)
##################################################################################
//状态机引擎拦截到标记有@Transition的方法执行,开始执行生命周期相关工作
[FINE]: Found Intercept Point: class net.madz.lifecycle.engine.CoreFuntionTestMetadata$Customer.activate( )
[FINE]: Intercepting....instatiating InterceptContext ...
[FINE]: Intercepting....InterceptorController is doing exec ...
[FINE]: Intercepting....instantiating LifecycleInterceptor
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @preExec
[FINE]: intercepting [net.madz.lifecycle.engine.CoreFuntionTestMetadata$Customer@67bba966]
from state: [Draft]
[FINE]: Step 1. start validating State [Draft]
[FINE]: Step 2. start validating transition: [Activate] on state: [Draft]
[FINE]: Step 3. start validating inbound relation constraint is next state is predictable before method invocation.
[FINE]: Step 4. start callback before state change from : Draft => to : Active
[FINE]: intercepting with: net.madz.bcel.intercept.CallableInterceptor @intercept
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @postExec
[FINE]: Step 5. start validating inbound relation constraint is next state after method invocation.
[FINE]: Step 6. Set next state to reactiveObject.
[FINE]: Step 6. ReactiveObject is tranisited to state: [Active]
[FINE]: Step 7. Start Callback after state change from : Draft => to : Active
[FINE]: Step 8. Start fire state change event.
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @cleanup
[FINE]: Intercepting....LifecycleInterceptor is doing cleanup ...
[FINE]: Found Intercept Point: class net.madz.lifecycle.engine.CoreFuntionTestMetadata$InternetServiceOrder.start( )
[FINE]: Intercepting....instatiating InterceptContext ...
[FINE]: Intercepting....InterceptorController is doing exec ...
[FINE]: Intercepting....instantiating LifecycleInterceptor
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @preExec
[FINE]: intercepting [net.madz.lifecycle.engine.CoreFuntionTestMetadata$InternetServiceOrder@3033e3e0]
from state: [New]
[FINE]: Step 1. start validating State [New]
[FINE]: Step 2. start validating transition: [Start] on state: [New]
[FINE]: Step 3. start validating inbound relation constraint is next state is predictable before method invocation.
[FINE]: Step 4. start callback before state change from : New => to : InService
[FINE]: intercepting with: net.madz.bcel.intercept.CallableInterceptor @intercept
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @postExec
[FINE]: Step 5. start validating inbound relation constraint is next state after method invocation.
[FINE]: Step 6. Set next state to reactiveObject.
[FINE]: Step 6. ReactiveObject is tranisited to state: [InService]
[FINE]: Step 7. Start Callback after state change from : New => to : InService
[FINE]: Step 8. Start fire state change event.
[FINE]: intercepting with :net.madz.bcel.intercept.LifecycleInterceptor @cleanup
[FINE]: Intercepting....LifecycleInterceptor is doing cleanup ...
Finish test: test_standalone_object_with_definite_relation(net.madz.lifecycle.engine.EngineCoreFunctionPositiveTests)
##################################################################################
相关推荐
NULL 博文链接:https://barryzhong.iteye.com/blog/1979706
9.2 将语言表述转变为动画——示例 9.2.1 IMPROV(纽约大学媒体研究实验室) 9.2.2 PAR体系结构(宾夕法尼亚大学人体建模和仿真中心) 9.2.3 具体化的对话界面代理(MIT媒体实验室) 9.2.4 游戏结论 9.3 面部动画、视觉...
9.2 将语言表述转变为动画——示例 9.2.1 IMPROV(纽约大学媒体研究实验室) 9.2.2 PAR体系结构(宾夕法尼亚大学人体建模和仿真中心) 9.2.3 具体化的对话界面代理(MIT媒体实验室) 9.2.4 游戏结论 9.3 面部动画、视觉...
有限状态机有限状态机有限状态机有限状态机有限状态机有限状态机
——第 1 部分:总则 ... ... ... ... ...——第 7 部分:就诊信息交互服务;...——第 8 部分:医嘱信息交互服务;...——第 9 部分:申请单信息交互服务;...——第 10 部分:预约信息交互服务;...——第 11 部分:结果、状态信息交互服务。
Python有限状态机——transitions https://xercis.blog.csdn.net/article/details/124127799
1、资源内容:Java工程示例的SMC - 状态机的基本格式说明及使用示例; 2、应用场景:SMC可以通过一个配置文件,生成有限状态机所需的所有状态类以及状态机类,同时还包括了所有的状态间的转换逻辑。 3、参考链接:...
EDA技术的应用——状态机 EDA技术的应用——状态机
日志追踪(完成以下六步、明白android的四种状态的生命周期和相互切换): 1、启动app、查看控制台输出,发现依次触发onCreate、onStart、onResume这三个方法 2、点击按钮(弹窗风格的Activity),控制台输出onPause...
Android应用程序组件中有一个生命周期,贯穿于创建到结束的整个周期。周期里面含有各种状态,这些状态对组件的生命周期起着至关重要的影响。
为了便于分类汇总和统计各种生命周期模型的指标和数据,结合公司软件开发过程的实际,我们选择了常用的几种基本模型进行了描述,项目开发小组在进行项目策划时,可以根据模型的适用前提、优缺点和项目的实际需要进行...
Acitvity 生命周期代码示例,详细描述activity三种状态变化
针对目前采煤机全生命周期管理存在的信息采集实时性和准确性偏低、无法进行唯一身份识别等问题,提出了一种基于射频识别(RFID)的采煤机全生命周期服务系统设计方案。该系统将统一的电子产品代码(EPC)写入RFID标签中,...
可编程硬件描述语言VHDL Quartus moore状态机源代码.rar
这里有状态机设计的指导,其中包含了一些经典的状态机设计例子,希望会对大家有所帮助!
2020版高三化学一轮复习试题调研:-化学基本理论——平衡状态和平衡移动.pdf
第4章 ASP.NET的网页代码模型及生命周期 从本章开始,就进入了ASP.NET应用程序开发的世界。在了解了C#的结构,以及面向对象的概念后,就可以从面向对象的思想开发ASP.NET应用程序。在ASP.NET中,能够使用面向对象的...
技术架构 Spring Boot Spring、Spring MVC、MyBatis Redis、Kafka、Elasticsearch Spring Security、Spring Actuator ...HTTP是无状态,有会话的: ——HTTP是简单的。 ——HTTP是可扩展的。 ——HTTP是无状态的,有会
activity生命周期详解,http://blog.csdn.net/huiblog/article/details/53292490
四种典型C语言状态机源代码