//状态机元数据描述 @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)
##################################################################################
相关推荐
近期,我深入研究了一个名为“生命周期组件框架——关系型状态机服务”的框架,其旨在简化这一过程,并通过关系型状态机来管理组件的生命周期。接下来,我将详细介绍这个框架的核心概念、源码实现以及其作为工具的...
1. **ASP.NET框架**:ASP.NET提供了许多开箱即用的功能,如页面生命周期管理、状态管理、错误处理、安全性和身份验证机制。它使用控件模型,允许开发者通过拖放方式创建Web页面,并通过事件驱动模型处理用户交互。 ...
5. **第五章:工作流生命周期管理** —— 讨论了如何管理和控制工作流的状态转换过程。 6. **第六章:异常处理与事务管理** —— 深入讲解了如何在工作流中处理异常情况以及如何利用事务来确保数据的一致性。 7. **...
1. **ASP.NET架构**:ASP.NET的核心包括页面生命周期管理、控件模型、状态管理、缓存机制等。在这个项目中,开发者可能使用了ASP.NET MVC(Model-View-Controller)或Web Forms模式来构建后端逻辑。 2. **...
3. **生命周期**:Android组件(如Activity、Service)有自己的生命周期,需要理解并适当地处理各个状态。 以上就是Android系统入门的一些基本知识点,"main.rar"中的内容可能会涵盖这些方面,并提供更详细的教程、...
5. **页面生命周期**:了解ASP.NET页面从请求到响应的生命周期是必要的,包括初始化、加载、回发、验证和卸载等阶段。源码可以帮助我们理解每个阶段如何处理事件和执行代码。 6. **数据库操作**:源码可能使用ADO...
在本项目中,“前端经典——vue实现登录页面开屏广告+校验demo”是一个使用Vue.js框架构建的示例应用,旨在展示如何在前端开发中创建一个包含登录页面、开屏广告以及用户输入校验功能的应用。Vue.js是当前非常流行的...
- **最小架构**:描述最简单的 Hibernate 应用程序架构,仅包含核心组件。 - **全面架构**:详细介绍一个完整的 Hibernate 应用程序可能包含的所有组件及交互。 - **基本 API**:概述 Hibernate 提供的主要 API 接口...
- **Activity生命周期**:解释Activity的生命周期状态变化,以及如何正确处理各个阶段的事件。 **2. 数据管理和调试** - **存储选项**:探讨Android提供的多种数据存储方式,如SharedPreferences、SQLite数据库等...
- **Activity生命周期:** 解释了Activity从创建到销毁的过程中的不同状态。 - **布局文件:** 如何使用XML文件定义UI布局。 - **事件处理:** 如何处理用户输入和其他事件。 **3.2 使用视图** - **基本控件:** ...
### 基于J2ME的Java手机软件开发 #### 当前手机软件状况与发展趋势 ...最后,通过具体的示例代码展示了如何创建具有基本功能的MIDlet程序,旨在帮助读者更好地理解和掌握这一领域的核心概念和技术实践。
- **生命周期**:说明变量何时被创建、何时被销毁。 - **5.2 常量** - **声明**:使用`const`关键字声明常量,例如`const int MaxSize = 100;`。 - **特性**:常量一旦被赋值后,在程序运行期间不能更改。 - **...
- ASP.NET页面有一个生命周期,其中包括多个阶段,如初始化、加载视图状态、预渲染、渲染等。 - 理解页面生命周期对于编写高效和可靠的ASP.NET应用至关重要。 #### 四、ASP.NET与经典ASP的区别 1. **经典ASP与...
4. **第3章:创建应用程序和活动**(Creating Applications and Activities):讲述了如何设计和构建应用程序的基本结构,包括Activity生命周期的概念及其管理方法。 5. **第4章:创建用户界面**(Creating User ...
Android SDK包括编译工具、模拟器、文档和示例代码,是每一个Android开发者入门必备的工具集。 #### 开发环境搭建 - **下载和安装Eclipse**:虽然现在Android Studio更为流行,但在早期,Eclipse是最主要的集成...
- **应用程序生命周期管理**:介绍了应用程序从启动到退出的整个生命周期,以及在这个过程中可能遇到的各种状态转换。 - **传感器数据获取**:讲解了如何获取设备上的传感器数据,如加速度计、陀螺仪等,为应用程序...
3.4 Android应用程序生命周期 48 3.5 理解应用程序的优先级和进程状态 49 3.6 分离资源 50 3.6.1 创建资源 50 3.6.2 使用资源 57 3.6.3 To-Do List资源示例 60 3.6.4 为不同的语言和硬件创建资源 61 3.6.5 ...
3.2.4对象的生命周期106 3.2.5对象的创建106 3.2.6对象的使用108 3.2.7对象的释放和垃圾收集机制108 3.3成员变量的定义与使用109 3.3.1成员变量的定义109 3.3.2成员变量的访问权限110 3.3.3实例成员变量和...