`
barryzhong
  • 浏览: 21245 次
  • 性别: Icon_minigender_1
社区版块
存档分类

生命周期组件框架:带有多状态机的单实现类

阅读更多

 ServiceOrder生命周期元数据

 

@StateMachine
public interface ServiceOrderLifecycleMeta extends OrderLifecycleMeta {

    @StateSet
    public static class States extends OrderLifecycleMeta.States {

        @InboundWhiles({
                @InboundWhile(relation = SummaryPlan.class, on = { ServiceSummaryPlanLifecycleMeta.States.Ongoing.class }, otherwise = {
                        @ErrorMessage(states = { ServiceSummaryPlanLifecycleMeta.States.VolumeLeftEmpty.class }, bundle = Consts.BUNDLE_NAME,
                                code = ErrorCodes.SUMMARY_PLAN__SHOULD_BE_ONGOING_THAN_VOLUME_EMPTY),
                        @ErrorMessage(states = { ServiceSummaryPlanLifecycleMeta.States.Done.class }, bundle = Consts.BUNDLE_NAME,
                                code = ErrorCodes.SUMMARY_PLAN__SHOULD_BE_ONGOING_THAN_DONE) }),
                @InboundWhile(relation = PlantResource.class,
                        on = { PlantResourceLifecycleMeta.States.Idle.class, PlantResourceLifecycleMeta.States.Busy.class }, otherwise = { @ErrorMessage(
                                bundle = Consts.BUNDLE_NAME, code = ErrorCodes.MIXING_PLANT_RESOURCE_INOT_IN_IDLE_OR_BUSY_STATE,
                                states = { PlantResourceLifecycleMeta.States.Maintaining.class }) }),
                @InboundWhile(relation = ConcreteTruckResource.class, on = { ConcreteTruckResourceLifecycleMeta.States.Idle.class,
                        ConcreteTruckResourceLifecycleMeta.States.Busy.class }, otherwise = { @ErrorMessage(bundle = Consts.BUNDLE_NAME,
                        code = ErrorCodes.TRUCK_RESOURCE_NOT_IN_IDLE_OR_BUSY_STATE, states = { ConcreteTruckResourceLifecycleMeta.States.Detached.class }) }) })
        public static class Ongoing extends OrderLifecycleMeta.States.Ongoing {}
    }
    @TransitionSet
    public static class Transitions extends OrderLifecycleMeta.Transitions {}
    @RelationSet
    public static class Relations {

        @Parent
        @RelateTo(ServiceSummaryPlanLifecycleMeta.class)
        public static class SummaryPlan {}
        @RelateTo(ConcreteTruckResourceLifecycleMeta.class)
        public static class ConcreteTruckResource {}
        @RelateTo(PlantResourceLifecycleMeta.class)
        public static class PlantResource {}
    }
}

 VehicleScheduleOrder生命周期元数据

@StateMachine
public interface VehicleScheduleOrderLifecycleMeta extends OrderLifecycleMeta {

    @StateSet
    public static class States {

        @LifecycleOverride
        @CompositeState
        @InboundWhile(relation = Relations.ConcreteTruckResource.class, on = { ConcreteTruckResourceLifecycleMeta.States.Idle.class },
                otherwise = { @ErrorMessage(bundle = Consts.BUNDLE_NAME, code = ErrorCodes.TRUCK_RESOURCE_NOT_IN_IDLE_OR_BUSY_STATE,
                        states = { ConcreteTruckResourceLifecycleMeta.States.Detached.class }) })
        public static class Ongoing extends OrderLifecycleMeta.States.Ongoing {

            @StateSet
            public static class CStates {

                @Initial
                @Function(transition = CTransitions.DoTransport.class, value = { OnPassage.class })
                public static class Loading {}
                @Function(transition = CTransitions.DoConstruct.class, value = { Constructing.class })
                public static class OnPassage {}
                @Function(transition = CTransitions.DoFinish.class, value = { Exit.class })
                public static class Constructing {}
                @End
                @ShortCut(value = Finished.class)
                public static class Exit {}
            }
            @TransitionSet
            public static class CTransitions {

                public static class DoFinish {}
                public static class DoTransport {}
                public static class DoConstruct {}
            }
        }
    }
    @TransitionSet
    public static class Transitions extends OrderLifecycleMeta.Transitions {}
    @RelationSet
    public static class Relations {

        @Parent
        @RelateTo(ServiceOrderLifecycleMeta.class)
        public static class ServiceOrder {}
        @RelateTo(ConcreteTruckResourceLifecycleMeta.class)
        public static class ConcreteTruckResource {}
    }
}

 

ConcreteTruckResource生命周期元数据

 

@StateMachine
public interface ConcreteTruckResourceLifecycleMeta extends SchedulableResourceLifecycleMeta {

    @StateSet
    public static class States extends SchedulableResourceLifecycleMeta.States {}
    @TransitionSet
    public static class Transitions extends SchedulableResourceLifecycleMeta.Transitions {}
}

 

IServiceOrder 业务接口

 

@LifecycleMeta(value = ServiceOrderLifecycleMeta.class)
public interface IServiceOrder {

    long getId();

    /** Transition methods **/
    @Transition(ServiceOrderLifecycleMeta.Transitions.Start.class)
    void configureResources(@Relation(ServiceOrderLifecycleMeta.Relations.PlantResource.class) MixingPlantResource plantResource,
            @Relation(ServiceOrderLifecycleMeta.Relations.ConcreteTruckResource.class) ConcreteTruckResource truckResource, double volume);

    @Transition(Finish.class)
    void confirmFinish();

    @Transition(Cancel.class)
    void cancel();

    @StateIndicator("serviceOrderState")
    String getState();

    @Relation(ServiceOrderLifecycleMeta.Relations.ConcreteTruckResource.class)
    ConcreteTruckResource getConcreteTruckResource();

    @Relation(ServiceOrderLifecycleMeta.Relations.SummaryPlan.class)
    ServiceSummaryPlan getSummaryPlan();

    @Relation(ServiceOrderLifecycleMeta.Relations.PlantResource.class)
    MixingPlantResource getMixingPlantResource();
}

 

 

IPlantScheduleOrder业务接口

 

@LifecycleMeta(value = PlantScheduleOrderLifecycleMeta.class)
public interface IPlantScheduleOrder {

    long getId();

    /* NON-TRANSITION Methods */
    String getPlantName();

    String getOperatorName();

    Date getProductionFinishedOn();

    Date getCreatedOn();

    /** Transition methods **/
    @Transition(PlantScheduleOrderLifecycleMeta.Transitions.Start.class)
    void doStartPlantOrder();

    @Transition(PlantScheduleOrderLifecycleMeta.Transitions.Finish.class)
    void doFinishPlantOrder();

    @Transition(PlantScheduleOrderLifecycleMeta.Transitions.Cancel.class)
    void cancelPlantOrder();

    @StateIndicator
    String getPlantScheduleOrderState();
    
    @Relation(PlantScheduleOrderLifecycleMeta.Relations.ServiceOrder.class)
    IServiceOrder getServiceOrder();
} 

 

IVehicleScheduleOrder业务接口 

 

@LifecycleMeta(value = VehicleScheduleOrderLifecycleMeta.class)
public interface IVehicleScheduleOrder {

    long getId();

    String getConcretePlantName();

    String getUnitProjectName();

    Address getAddress();

    Contact getContact();

    String getPouringPartName();

    String getMixtureStrengthGrade();

    String[] getAdditiveNames();

    double getTransportVolume();

    Date getCreatedOn();

    Date getTransportFinishedOn();

    /** Transition methods **/
    @Transition(VehicleScheduleOrderLifecycleMeta.Transitions.Start.class)
    void doLoad();

    @Transition(VehicleScheduleOrderLifecycleMeta.States.Ongoing.CTransitions.DoTransport.class)
    void doTransport();

    @Transition(VehicleScheduleOrderLifecycleMeta.States.Ongoing.CTransitions.DoConstruct.class)
    void doConstruct();

    @Transition(VehicleScheduleOrderLifecycleMeta.States.Ongoing.CTransitions.DoFinish.class)
    void doComplete();

    @Transition(VehicleScheduleOrderLifecycleMeta.Transitions.Finish.class)
    void doFinishVehicalOrder();

    @Transition(VehicleScheduleOrderLifecycleMeta.Transitions.Cancel.class)
    void doAbortOnVehicleScheduleOrder();

    @StateIndicator
    String getVehicleScheduleOrderState();

    @Relation(VehicleScheduleOrderLifecycleMeta.Relations.ServiceOrder.class)
    IServiceOrder getServiceOrder();

    @Relation(VehicleScheduleOrderLifecycleMeta.Relations.ConcreteTruckResource.class)
    ConcreteTruckResource getConcreteTruckResource();
}

 

 ServiceOrder业务实体——实现多个业务接口,同时具体化了多个状态机

 

@Entity
@Table(name = "service_order")
@ReactiveObject
public class ServiceOrder extends ServiceOrderBase implements IServiceOrder, IPlantScheduleOrder, IVehicleScheduleOrder {

    protected static final long serialVersionUID = -6118079224654228286L;

    protected ServiceOrder() {}

    public ServiceOrder(ServiceSummaryPlan parent) {
        parent.addResourceAllocatedTask(this);
        this.summaryPlan = parent;
    }

    @Transition(ServiceOrderLifecycleMeta.Transitions.Start.class)
    public void configureResources(@Relation(ServiceOrderLifecycleMeta.Relations.PlantResource.class) MixingPlantResource plantResource,
            @Relation(ServiceOrderLifecycleMeta.Relations.ConcreteTruckResource.class) ConcreteTruckResource truckResource, double volume) {
        {
            this.spec = summaryPlan.getSpec();
            this.truckResource = truckResource;
            this.mixingPlantResource = plantResource;
            this.plannedVolume = volume;
        }
        this.mixingPlantResource.assignOrder(this);
        this.truckResource.assignOrder(this);
    }

    @Transition(ServiceOrderLifecycleMeta.Transitions.Finish.class)
    public void confirmFinish() {
        this.finishedOn = new Date();
    }

    @Transition(ServiceOrderLifecycleMeta.Transitions.Cancel.class)
    public void cancel() {
        this.canceledOn = new Date();
    }

    @Override
    @Transition(VehicleScheduleOrderLifecycleMeta.Transitions.Start.class)
    public void doLoad() {
        this.vehicleLoadOn = new Date();
    }

    @Override
    @Transition(VehicleScheduleOrderLifecycleMeta.States.Ongoing.CTransitions.DoTransport.class)
    public void doTransport() {
        this.vehicleTransportOn = new Date();
    }

    @Override
    @Transition(VehicleScheduleOrderLifecycleMeta.States.Ongoing.CTransitions.DoConstruct.class)
    public void doConstruct() {
        this.vehicleConstructOn = new Date();
    }

    @Override
    @Transition(VehicleScheduleOrderLifecycleMeta.Transitions.Finish.class)
    public void doComplete() {
        this.vehicleCompletedOn = new Date();
    }

    @Override
    @Transition(VehicleScheduleOrderLifecycleMeta.Transitions.Cancel.class)
    public void doAbortOnVehicleScheduleOrder() {
        this.vehicleAbortedOn = new Date();
    }

    @Override
    @Transition(VehicleScheduleOrderLifecycleMeta.States.Ongoing.CTransitions.DoFinish.class)
    public void doFinishVehicalOrder() {}

    @Override
    @Transition(PlantScheduleOrderLifecycleMeta.Transitions.Start.class)
    public void doStartPlantOrder() {
        this.plantStartedOn = new Date();
    }

    @Override
    @Transition(PlantScheduleOrderLifecycleMeta.Transitions.Finish.class)
    public void doFinishPlantOrder() {
        this.plantFinishOn = new Date();
    }

    @Override
    @Transition(PlantScheduleOrderLifecycleMeta.Transitions.Cancel.class)
    public void cancelPlantOrder() {
        this.plantCanceledOn = new Date();
    }

    @Override
    @Relation
    public IServiceOrder getServiceOrder() {
        return this;
    }

    @Override
    @Relation
    public ConcreteTruckResource getConcreteTruckResource() {
        return this.truckResource;
    }

    @Override
    public String getConcretePlantName() {
        return this.mixingPlantResource.getMixingPlant().getName();
    }

    @Override
    public String getUnitProjectName() {
        return this.spec.getUnitProject().getName();
    }

    @Override
    public Address getAddress() {
        return this.spec.getUnitProject().getAddress();
    }

    @Override
    public Contact getContact() {
        return this.spec.getUnitProject().getContact();
    }

    @Override
    public String getPouringPartName() {
        return this.spec.getPouringPart().getName();
    }

    @Override
    public String getMixtureStrengthGrade() {
        return this.spec.getMixture().getGradeName();
    }

    @Override
    public String[] getAdditiveNames() {
        final ArrayList<String> additiveNames = new ArrayList<String>();
        final List<Additive> additives = this.spec.getAdditives();
        for ( Additive additive : additives ) {
            additiveNames.add(additive.getName());
        }
        return additiveNames.toArray(new String[0]);
    }

    @Override
    public double getTransportVolume() {
        return this.plannedVolume;
    }

    @Override
    public Date getTransportFinishedOn() {
        return this.transportFinishedOn;
    }

    @Override
    public String getPlantName() {
        return this.mixingPlantResource.getMixingPlant().getName();
    }

    @Override
    public String getOperatorName() {
        return this.mixingPlantResource.getMixingPlant().getOperator().getFullName();
    }

    @Override
    public Date getProductionFinishedOn() {
        return this.productionFinishedOn;
    }
}

 

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

分享到:
评论

相关推荐

    Fragment框架DEMO

    TabHost是早期用于创建带有标签页的应用界面的组件,而BottomNavigationView则是在Material Design指南中推荐的底部导航栏,适用于Android 5.0(API级别21)及以上版本。 在自定义Fragment框架时,开发者需要考虑...

    软件工程 - UML统一建模语言参考手册

    - **状态机图**:展示对象在其生命周期内的状态变化。 - **活动图**:展示业务流程或算法的控制流。 4. **交互视图**: - **通信图**:展示对象之间的交互,侧重于对象间的链接。 - **定时图**:展示对象间消息...

    Android 自带应用相机(Camera)源代码

    `SurfaceHolder`接口用于管理`SurfaceView`的生命周期,获取预览数据流并传递给相机服务。 4. **拍照回调机制**:`Camera.PictureCallback`接口定义了拍照后的回调函数,如`onPictureTaken()`。当用户触发拍照后,...

    安卓面试题

    - **生命周期**:类似于Activity,有自己的生命周期方法。 - **管理**:通过FragmentManager管理Fragment。 #### 70. 缓存实现 - **LruCache**:内存缓存。 - **DiskLruCache**:磁盘缓存。 #### 71. XML解析 - **...

    Hosting the .NET Composition Primitives

    它利用自定义属性来标记类、方法或属性,以便于框架自动识别它们作为组件的一部分。 - **消费属性编程模型**:一旦组件被标记,就可以通过读取这些标记来实例化和配置组件。这种机制简化了组件的创建过程,并增强了...

    基于AKKA的后台应用开发手册.pdf

    手册涵盖了从基础的Actor创建到复杂的生命周期管理、消息处理和错误恢复等主题,适合初学者和有一定经验的开发者参考。 1.4 术语和缩写语 - Actor:AKKA的核心概念,代表并发执行的基本单元。 - Supervision:Actor...

    Android应用开发期末考试题.docx

    - **缺失的方法**:`onResume()`是Activity生命周期中的一个重要方法,它标志着Activity重新变为活动状态。 - **其他关键方法**:还包括`onCreate()`、`onStart()`、`onPause()`、`onStop()`、`onDestroy()`等。 ##...

    akka java document

    - **Lambda 表达式与故障容忍:** 如何在带有 Lambda 支持的 Actor 中实现故障容忍。 - **Lambda 支持下的监督策略:** 如何配置监督策略。 **4.3 FSM(带有 Lambda 支持)** - **Lambda 表达式与 FSM:** 如何使用...

    jade 开发多agent

    - **FSMBehaviour类**:基于有限状态机的行为模式,适用于复杂的决策逻辑。 - **SenderBehaviour类**:负责发送消息的行为。 - **ReceiverBehaviour类**:处理接收到的消息的行为。 - **WakerBehaviour类**:...

    超级有影响力霸气的Java面试题大全文档

     SessionBean: Stateless Session Bean 的生命周期是由容器决定的,当客户机发出请求要建立一个Bean的实例时,EJB容器不一定要创建一个新的Bean的实例供客户机调用,而是随便找一个现有的实例提供给客户机。...

    UML Distilled(UML精粹,带书签)

    - **模板(参数化)类**:类图中可以定义带有类型参数的通用类。 - **枚举**:一种特殊的类型,用于表示有限的值集合。 - **活动类**:能够主动执行操作的类。 - **可见性**:定义了类图中元素的访问级别。 - **消息...

    月光宝盒游戏机源码Demo

    2. **安卓应用开发**:源码Demo基于安卓平台,所以开发者需要熟悉Java或Kotlin语言,理解安卓应用的生命周期管理和组件模型。 3. **图形编程**:游戏中的画面效果可能涉及到OpenGL ES或 Vulkan等图形库,用于实现2D...

    android相关知识总结

    总结,Android开发涵盖了从平台理解到具体应用开发的各个方面,开发者需要熟悉平台组件、开发环境配置、应用结构和组件生命周期,同时解决实际开发中遇到的问题,以创建高效、用户友好的应用程序。

    安卓Android源码——毕设作品妹子版记事本程序.zip

    - **Android生命周期**: Activity、Service等组件有自己的生命周期,开发者需要了解并适当地处理各个状态,以确保应用的正常运行。 通过对这个毕设作品的学习,你可以深入理解Android应用开发的基本流程,包括UI...

    Java 手机程序设计入门与应用

    3. **MIDlet生命周期**: - MIDlet有四个状态:初始化、暂停、恢复和删除。理解这些状态及其转换对于编写健壮的程序至关重要。 - `startApp()`、`pauseApp()`、`resumeApp()` 和 `destroyApp()` 是MIDlet的关键...

    Android应用开发期末考试题(完整版).docx (带答案)

    - **知识点**: `onResume()`实际上是Activity生命周期的一个重要方法,它在活动变为活动状态前被调用。这里可能是题目出错。Activity的生命周期方法包括但不限于`onCreate()`、`onStart()`、`onResume()`、`onPause...

Global site tag (gtag.js) - Google Analytics