Uploaded image for project: 'Kogito'
  1. Kogito
  2. KOGITO-2766

Process and ProcessInstance refactoring

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major Major
    • None
    • None
    • Core Engine
    • None
    • 2020 Week 34-36 (from Aug 17), 2020 Week 37-39 (from Sep 7)

      Usage of constructor injection and field injection:

      In this case we can probably stick to constructor injection. Besides, java.util.Collection<org.kie.api.runtime.process.WorkItemHandler> handlers; is already available from application.config().processes() so the extra reference is redundant

      @org.springframework.stereotype.Component("Travelers")
      public class TravelersProcess extends org.kie.kogito.process.impl.AbstractProcess<org.kie.kogito.test.TravelersModel> {
      
          @org.springframework.beans.factory.annotation.Autowired(required = false)
          java.util.Collection<org.kie.api.runtime.process.WorkItemHandler> handlers;
      
          org.kie.kogito.app.Application app;
      
          @org.springframework.beans.factory.annotation.Autowired()
          org.kie.kogito.test.TravelersMessageProducer_7 producer_7;
      
          public TravelersProcess() {
          }
      
          @org.springframework.beans.factory.annotation.Autowired()
          public TravelersProcess(org.kie.kogito.app.Application app) {
              super(app.config().process());
              this.app = app;
          }
      

      Usage of PostConstruct

      This intialization style makes it harder to create an instance of ProcessInstance without DI – you have to be aware that the annotated method must be invoked.
      Besides our initializatoin process is in turn very complicated.

      Goal: Streamline this initialization, possibly promote to constructor injection / initialization, and remove all the other methods. Details follow:

      • instances are initialized through a call to an activate() via @PostCostruct which means that they cannot be constructed without DI (or without knowing that this method has to be called)
            @javax.annotation.PostConstruct()
            public void init() {
                this.activate();
            }
        
        
      • activate() invokes a configure() method; all it does is usually to register the workItemHandler to WorkItemManager – which (1) can be done in some other place (2) it's probably registering the same work item handler multiple times for each process !
          public HotelBookingProcess configure() {
              super.configure();
              handlers.forEach(h -> {
                  services.getWorkItemManager().registerWorkItemHandler(h.getName(), h);
              });
              return this;
          }
      
      
      
      • the {configure()}

        method default implementation (AbstractProcess) delegates to a third (!!) method registerListeners() that generated code may override; in which case it just registers super.completionEventListener

          protected void registerListeners() {
              services.getSignalManager().addEventListener("flightBooking", completionEventListener);
              services.getSignalManager().addEventListener("hotelBooking", completionEventListener);
          }
      

              ftirados Francisco Javier Tirado Sarti
              evacchi Edoardo Vacchi (Inactive)
              Marian Macik Marian Macik
              Marian Macik Marian Macik
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: