生命周期组件框架:生命周期描述语言——复合状态机示例

    @StateMachine
    static interface OrderLifecycle {

        @StateSet
        static interface States {

            @Initial
            @Function(transition = Transitions.Start.class, value = Started.class)
            static interface Created {}
            @CompositeState
            @Function(transition = Transitions.Cancel.class, value = Canceled.class)
            static interface Started {

                @StateSet
                static interface SubStates {

                    @Initial
                    @Function(transition = OrderLifecycle.States.Started.SubTransitions.DoProduce.class, value = Producing.class)
                    static interface OrderCreated {}
                    @Function(transition = OrderLifecycle.States.Started.SubTransitions.DoDeliver.class, value = Delivering.class)
                    static interface Producing {}
                    @Function(transition = OrderLifecycle.States.Started.SubTransitions.ConfirmComplete.class, value = Done.class)
                    static interface Delivering {}
                    @End
                    @ShortCut(OrderLifecycle.States.Finished.class)
                    static interface Done {}
                }
                @TransitionSet
                static interface SubTransitions {

                    static interface DoProduce {}
                    static interface DoDeliver {}
                    static interface ConfirmComplete {}
                }
            }
            @End
            static interface Finished {}
            @End
            static interface Canceled {}
        }
        @TransitionSet
        static interface Transitions {

            static interface Start {}
            static interface Cancel {}
        }
    }
    public abstract static class ProductBase extends ReactiveObject {}
    @LifecycleMeta(OrderLifecycle.class)
    public static class ProductOrder extends ProductBase {

        public ProductOrder() {
            initialState(OrderLifecycle.States.Created.class.getSimpleName());
        }

        @Transition
        public void start() {}

        @Transition
        public void cancel() {}

        @Transition
        public void doProduce() {}

        @Transition
        public void doDeliver() {}

        @Transition
        public void confirmComplete() {}
    }

 前文:生命周期组件框架——关系型状态及服务

猜你喜欢

转载自barryzhong.iteye.com/blog/1979715