@StateMachine static interface InformativeStateMachine { @StateSet static interface States { @Initial @Functions({ @Function(transition = Transitions.LogicalDelete.class, value = Recycled.class), @Function(transition = Transitions.Confirm.class, value = Confirmed.class) }) static interface Draft {} @Function(transition = Transitions.Finish.class, value = Finished.class) static interface Confirmed {} @End static interface Finished {} @Functions({ @Function(transition = Transitions.PutBack.class, value = Draft.class), @Function(transition = Transitions.PhysicalDelete.class, value = Vanished.class) }) static interface Recycled {} @End static interface Vanished {} } @TransitionSet static interface Transitions { static interface Confirm {} static interface LogicalDelete {} static interface PutBack {} static interface PhysicalDelete {} static interface File {} static interface Finish {} } } @StateMachine static interface CustomerStateMachine extends InformativeStateMachine { @StateSet static interface States extends InformativeStateMachine.States { @CompositeState @LifecycleOverride static interface Confirmed extends InformativeStateMachine.States.Confirmed { @StateSet static interface ConfirmedStates { @Initial @Functions({ @Function(transition = Transitions.Suspend.class, value = ServiceSuspended.class), @Function(transition = Transitions.TerminateService.class, value = ServiceExpired.class), @Function(transition = Transitions.Cancel.class, value = Canceled.class) }) static interface InService {} @Function(transition = Transitions.Resume.class, value = InService.class) static interface ServiceSuspended {} @Functions({ @Function(transition = Transitions.Renew.class, value = InService.class), @Function(transition = Transitions.Disconnect.class, value = Disconnected.class), @Function(transition = Transitions.Abandon.class, value = Abandoned.class) }) static interface ServiceExpired {} @Functions({ @Function(transition = Transitions.Abandon.class, value = Abandoned.class), @Function(transition = Transitions.Disconnect.class, value = Disconnected.class) }) static interface Canceled {} @End @ShortCut(InformativeStateMachine.States.Finished.class) static interface Disconnected {} @End @ShortCut(InformativeStateMachine.States.Recycled.class) static interface Abandoned {} } @TransitionSet static interface Transitions { static interface Abandon {} static interface Suspend {} static interface Resume {} static interface Renew {} static interface Cancel {} static interface TerminateService {} static interface Disconnect {} } } } } @StateMachine static interface ContractStateMachine extends InformativeStateMachine { @StateSet static interface States extends InformativeStateMachine.States { @CompositeState @LifecycleOverride static interface Confirmed extends InformativeStateMachine.States.Confirmed { @StateSet static interface ConfirmedStates { @Initial @Functions({ @Function(transition = Transitions.StartService.class, value = ServiceStarted.class), @Function(transition = Transitions.TerminateService.class, value = Terminated.class) }) @InboundWhile(on = { InformativeStateMachine.States.Draft.class, CustomerStateMachine.States.Confirmed.ConfirmedStates.InService.class }, relation = Relations.Customer.class) @ValidWhile(on = { CustomerStateMachine.States.Confirmed.ConfirmedStates.InService.class }, relation = Relations.Customer.class) static interface Effective {} @Function(transition = Transitions.AbortService.class, value = ServiceAborted.class) @ValidWhile(on = { CustomerStateMachine.States.Confirmed.ConfirmedStates.InService.class }, relation = Relations.Customer.class) @InboundWhile(on = { CustomerStateMachine.States.Confirmed.ConfirmedStates.InService.class }, relation = Relations.Customer.class) static interface ServiceStarted {} @Function(transition = Transitions.Invalidate.class, value = Uneffective.class) @InboundWhile(on = { CustomerStateMachine.States.Confirmed.ConfirmedStates.InService.class }, relation = Relations.Customer.class) static interface ServiceAborted {} @End @ShortCut(InformativeStateMachine.States.Finished.class) static interface Terminated {} @End @ShortCut(InformativeStateMachine.States.Draft.class) static interface Uneffective {} } @TransitionSet static interface Transitions { static interface Invalidate {} static interface StartService {} static interface AbortService {} static interface TerminateService {} } @RelationSet static interface Relations { @Parent @RelateTo(CustomerStateMachine.class) static interface Customer {} } } } } @StateMachine static interface OrderStateMachine extends InformativeStateMachine { @StateSet static interface States extends InformativeStateMachine.States { @CompositeState @LifecycleOverride static interface Confirmed extends InformativeStateMachine.States.Confirmed { @StateSet static interface ConfirmedStates { @Initial @InboundWhile(on = { ContractStateMachine.States.Confirmed.ConfirmedStates.ServiceStarted.class }, relation = Relations.Contract.class) @ValidWhile(on = { ContractStateMachine.States.Confirmed.ConfirmedStates.ServiceStarted.class }, relation = Relations.Contract.class) @Functions({ @Function(transition = Transitions.StartProduce.class, value = Manufactoring.class), @Function(transition = Transitions.Dequeue.class, value = Dequeued.class) }) static interface Queued {} @InboundWhiles({ @InboundWhile(on = { ContractStateMachine.States.Confirmed.ConfirmedStates.ServiceStarted.class }, relation = Relations.Contract.class), @InboundWhile(on = { ResourceStateMachine.States.OfficialRunning.RunningStates.Idle.class }, relation = Relations.Resource.class) }) @ValidWhiles({ @ValidWhile(on = { ContractStateMachine.States.Confirmed.ConfirmedStates.ServiceStarted.class }, relation = Relations.Contract.class) }) @Function(transition = Transitions.StartPackage.class, value = Packaging.class) static interface Manufactoring {} @InboundWhile(on = { ContractStateMachine.States.Confirmed.ConfirmedStates.ServiceStarted.class }, relation = Relations.Contract.class) @ValidWhile(on = { ContractStateMachine.States.Confirmed.ConfirmedStates.ServiceStarted.class }, relation = Relations.Contract.class) @Function(transition = Transitions.Deliver.class, value = { Delivering.class }) static interface Packaging {} @InboundWhile(on = { ContractStateMachine.States.Confirmed.ConfirmedStates.ServiceStarted.class }, relation = Relations.Contract.class) @ValidWhile(on = { ContractStateMachine.States.Confirmed.ConfirmedStates.ServiceStarted.class }, relation = Relations.Contract.class) @Function(transition = Transitions.Complete.class, value = Completed.class) static interface Delivering {} @End @ShortCut(InformativeStateMachine.States.Finished.class) static interface Completed {} @End @ShortCut(InformativeStateMachine.States.Draft.class) static interface Dequeued {} } @TransitionSet static interface Transitions { static interface Deliver {} static interface Dequeue {} static interface StartProduce {} static interface StartPackage {} static interface Complete {} } @RelationSet static interface Relations { @Parent @RelateTo(ContractStateMachine.class) static interface Contract {} @RelateTo(ResourceStateMachine.class) static interface Resource {} } } } } @StateMachine static interface ResourceStateMachine { @StateSet static interface States { @Initial @Function(transition = Transitions.Test.class, value = TestRunning.class) static interface New {} @Functions({ @Function(transition = Transitions.GoLive.class, value = OfficialRunning.class), @Function(transition = Transitions.ConfirmMalfunction.class, value = Malfunctioning.class) }) static interface TestRunning {} @Functions({ @Function(transition = Transitions.Repair.class, value = Repairing.class), @Function(transition = Transitions.Deprecate.class, value = Deprecated.class) }) static interface Malfunctioning {} @Function(transition = Transitions.ConfirmMalfunction.class, value = Malfunctioning.class) @CompositeState static interface OfficialRunning { @StateSet static interface RunningStates { @Initial @Function(transition = RunningTransitions.Acquire.class, value = Busy.class) static interface Idle {} @Functions({ @Function(transition = RunningTransitions.Fail.class, value = Failing.class), @Function(transition = RunningTransitions.Release.class, value = Idle.class) }) static interface Busy {} @End @ShortCut(Malfunctioning.class) static interface Failing {} } @TransitionSet static interface RunningTransitions { static interface Acquire {} static interface Release {} static interface Fail {} } } @Function(transition = Transitions.Test.class, value = TestRunning.class) static interface Repairing {} @End static interface Deprecated {} } @TransitionSet static interface Transitions { static interface Test {} static interface ConfirmMalfunction {} static interface Repair {} static interface GoLive {} static interface Deprecate {} } } @LifecycleMeta(InformativeStateMachine.class) @LifecycleLock(SimpleLock.class) static class InformativeObject extends ReactiveObject { public InformativeObject() { initialState(InformativeStateMachine.States.Draft.class.getSimpleName()); } @Transition public void confirm() {} @Transition public void logicalDelete() {} @Transition public void putBack() {} @Transition public void physicalDelete() {} @Transition public void file() {} @Transition public void finish() {} } @LifecycleMeta(CustomerStateMachine.class) @LifecycleLock(SimpleLock.class) static class CustomerObject extends InformativeObject { @Transition public void abandon() {} @Transition public void suspend() {} @Transition public void resume() {} @Transition public void renew() {} @Transition public void cancel() {} @Transition public void terminateService() {} @Transition public void disconnect() {} } @LifecycleMeta(ContractStateMachine.class) @LifecycleLock(SimpleLock.class) static class ContractObject extends InformativeObject { @Relation(ContractStateMachine.States.Confirmed.Relations.Customer.class) private CustomerObject customer; public ContractObject(final CustomerObject customer) { super(); this.customer = customer; } @Transition public void invalidate() {} @Transition public void startService() {} @Transition public void abortService() {} @Transition public void terminateService() {} } @LifecycleMeta(OrderStateMachine.class) @LifecycleLock(SimpleLock.class) static class OrderObject extends InformativeObject { @Relation private ContractObject contract; public OrderObject(ContractObject contract) { this.contract = contract; } @Transition public void deliver() {} @Transition public void dequeue() {} @Transition public void startProduce(@Relation(OrderStateMachine.States.Confirmed.Relations.Resource.class) ResourceObject resource) {} @Transition public void startPackage() {} @Transition public void complete() {} } @LifecycleMeta(ResourceStateMachine.class) @LifecycleLock(SimpleLock.class) static class ResourceObject extends ReactiveObject { public ResourceObject() { initialState(ResourceStateMachine.States.New.class.getName()); } @Transition public void test() {} @Transition public void confirmMalfunction() {} @Transition public void repair() {} @Transition public void goLive() {} @Transition public void deprecate() {} @Transition public void acquire() {} @Transition public void release() {} @Transition public void fail() {} }
@Test public void test_relational_locking() { final CustomerObject customer = new CustomerObject(); final ContractObject contract = new ContractObject(customer); final OrderObject order = new OrderObject(contract); final ResourceObject resource = new ResourceObject(); customer.confirm(); contract.confirm(); contract.startService(); order.confirm(); resource.test(); resource.goLive(); order.startProduce(resource); order.startPackage(); order.deliver(); order.complete(); assertState(OrderStateMachine.States.Finished.class, order); }
带有关系约束的状态机引擎执行过程中读写锁的使用日志
相关推荐
在C++中,还可以使用智能指针(如`std::unique_lock`或`std::shared_lock`)与读写锁配合,以实现RAII(Resource Acquisition Is Initialization)风格的代码,这样可以更安全地管理锁的生命周期。 总的来说,...
6. **Services**:Service是在后台运行的组件,用于执行长时间运行的操作而不与用户交互。示例可能展示如何启动、绑定服务,以及服务的生命周期管理。 7. **Notification**:通知是向用户显示非中断性消息的重要...
10. **ASP.NET**:构建Web应用程序,包括页面生命周期、控件事件处理、会话管理等。 11. **ADO.NET**:数据库访问技术,包括连接数据库、执行SQL语句、数据适配器、数据集和数据视图等。 通过这些示例,开发者可以...
5. **生命周期管理**:COS允许设置对象的生命周期策略,例如自动删除过期文件,节省存储成本。 6. **API调用**:除了SDK,COS还提供了丰富的RESTful API,开发者可以直接通过HTTP请求来操作对象,如列举文件、获取...
《利用.NET框架开发应用系统》一书的示例代码提供了丰富的实践指导,涵盖了.NET框架在构建实际应用系统过程中的各种技术细节。这本书旨在帮助开发者深入理解.NET框架,并将其有效地应用于项目开发中。以下是对示例...
- 组件生命周期包括初始化、渲染和销毁三个主要阶段,每个阶段都有相应的事件和处理方法。 - 初始化:处理配置选项、创建组件事件、注册组件等。 - 渲染:设置容器、应用样式、触发渲染事件等。 - 销毁:释放...
4. **协议文档**:描述了模块与ID卡之间的通信协议,有助于理解数据交换过程。 5. **示例代码**:演示如何通过编程控制读写模块的实例代码。 了解这些知识后,无论是系统集成商还是开发者,都能更好地利用ID卡读写...
6. **生命周期回调**: JPA允许在实体的生命周期事件(如`prePersist`, `postLoad`等)上定义回调方法,使得在特定时刻执行特定逻辑成为可能。 7. **懒加载(Lazy Loading)与急加载(Eager Loading)**: JPA支持...
- 实践示例:通过编写简单的代码片段来理解和应用所有权与生命周期的概念。 - **并发编程**: - **线程**:创建和管理线程。 - **锁机制**:使用互斥锁(Mutex)、读写锁(RWLock)等同步原语来保护共享数据。 - **...
书中会解释如何创建和使用类,理解对象的生命周期,以及如何通过接口实现多态性。 3. **异常处理**:Java中的异常处理机制是程序健壮性的重要部分,读者将学习如何使用try-catch-finally语句块捕获和处理异常。 4....
1. 生命周期钩子函数:如beforeCreate、created、beforeMount、mounted等,用于在不同阶段执行初始化任务,例如数据预处理、API调用等。 2. 双向数据绑定原理:通过“依赖追踪”系统和数据劫持实现,数据变化时触发...
- 使用短生命周期的局部变量,避免在锁保护的代码块内创建长生命周期的对象。 - 使用带缓冲的通道或者RWMutex优化并发性能。 通过这个示例,你可以学习到如何在实际项目中使用Mutex来保护共享资源,确保并发安全...
此外,"Android四大基本组件介绍与生命周期 - bravestarr - 博客园_files"可能包含了相关博客的辅助材料,如图片或示例代码,帮助你更直观地理解这些概念。深入学习和实践这些知识,将有助于提升你的Android开发技能...
这个名为"安卓Android源码——安卓AndroidAppCodeFramework-master.zip"的压缩包文件,很可能是为了帮助开发者们了解和学习Android应用代码框架而提供的资源。让我们一起探索其中可能包含的知识点。 首先,Android...
EXT JS 是一种强大的JavaScript框架,主要用于构建富...组件的生命周期、渲染、事件处理和Component与Container的理解是EXT JS开发的关键。通过深入学习EXT JS的组件体系,可以构建出高效且用户体验良好的Web应用。
在安卓应用开发中,`Service` 是一个非常重要的组件,它用于在后台执行长时间运行的操作,即使用户与应用程序没有交互。本篇将深入探讨 `ServiceSample` 示例代码,帮助你理解如何在 Android 中有效地使用 `Service`...
- 控件的生命周期管理; - 设计时与运行时的行为差异; - 控件的注册与部署; - 与宿主应用程序的交互。 #### 五、互联网编程 **知识点18:网络编程** - **描述**:讲解基于Socket的网络编程以及MAPI与...