Class DefaultPlatformRuleEngineService

  • All Implemented Interfaces:
    RuleEngineService

    public class DefaultPlatformRuleEngineService
    extends java.lang.Object
    implements RuleEngineService
    The DefaultDroolsRuleEngineService allows initialization and evaluation of rules modules.
    • Field Detail

      • MODULE_MVN_VERSION_NONE

        public static final java.lang.String MODULE_MVN_VERSION_NONE
        See Also:
        Constant Field Values
      • SWAPPING_IS_BLOCKING

        public static final java.lang.String SWAPPING_IS_BLOCKING
        See Also:
        Constant Field Values
    • Constructor Detail

      • DefaultPlatformRuleEngineService

        public DefaultPlatformRuleEngineService()
    • Method Detail

      • evaluate

        public RuleEvaluationResult evaluate​(RuleEvaluationContext context)
        Description copied from interface: RuleEngineService
        Since 6.0 Executes rule evaluation for given RuleEvaluationContext. Executes all rules contained within the context
        Specified by:
        evaluate in interface RuleEngineService
        Parameters:
        context - the rule engine context containing data about rule engine execution
        Returns:
        results of rule engine execution
      • executionResultsSupplierWithStatefulSession

        protected java.util.function.Supplier<org.kie.api.runtime.ExecutionResults> executionResultsSupplierWithStatefulSession​(org.kie.api.runtime.KieContainer kContainer,
                                                                                                                                org.kie.api.command.BatchExecutionCommand command,
                                                                                                                                RuleEvaluationContext context)
      • executionResultsSupplierWithStatelessSession

        protected java.util.function.Supplier<org.kie.api.runtime.ExecutionResults> executionResultsSupplierWithStatelessSession​(org.kie.api.runtime.KieContainer kContainer,
                                                                                                                                 org.kie.api.command.BatchExecutionCommand command,
                                                                                                                                 RuleEvaluationContext context)
      • initialize

        public InitializationFuture initialize​(java.util.List<AbstractRulesModuleModel> modules,
                                               boolean propagateToOtherNodes,
                                               boolean enableIncrementalUpdate)
        Description copied from interface: RuleEngineService
        Since 6.4 Initializes the given rules module in blocking/async mode (depending on blocking param) (and if propagateToOtherNodes is set to true propagates a RuleEngineInitializedEvent to other nodes).
        Specified by:
        initialize in interface RuleEngineService
        Parameters:
        modules - the modules to be initialized
        propagateToOtherNodes - if true propagates a RuleEngineInitializedEvent to other nodes.
        enableIncrementalUpdate - flag, if true, enables for incremental updates of the rule engine kie module
        Returns:
        instance of InitializationFuture to be used for eventual blocking on multiple parallel swapping
      • initialize

        public InitializationFuture initialize​(java.util.List<AbstractRulesModuleModel> modules,
                                               boolean propagateToOtherNodes,
                                               boolean enableIncrementalUpdate,
                                               ExecutionContext executionContext)
        Description copied from interface: RuleEngineService
        Since 6.7 Initializes the given rules module in blocking/async mode (depending on blocking param) (and if propagateToOtherNodes is set to true propagates a RuleEngineInitializedEvent to other nodes).
        Specified by:
        initialize in interface RuleEngineService
        Parameters:
        modules - the modules to be initialized
        propagateToOtherNodes - if true propagates a RuleEngineInitializedEvent to other nodes.
        enableIncrementalUpdate - flag, if true, enables for incremental updates of the rule engine kie module
        executionContext - instance of ExecutionContext that serves as a storage for initialization related data
        Returns:
        instance of InitializationFuture to be used for eventual blocking on multiple parallel swapping
      • initializeNonBlocking

        public void initializeNonBlocking​(AbstractRulesModuleModel abstractModule,
                                          java.lang.String deployedMvnVersion,
                                          boolean propagateToOtherNodes,
                                          boolean enableIncrementalUpdate,
                                          RuleEngineActionResult result)
        Description copied from interface: RuleEngineService
        Since 6.4 Asynchronously initializes the given rules module (and if propagateToOtherNodes is set to true propagates a RuleEngineInitializedEvent to other nodes).
        Specified by:
        initializeNonBlocking in interface RuleEngineService
        Parameters:
        abstractModule - the module to be initialized
        deployedMvnVersion - currently deployed version of the Kie Module
        propagateToOtherNodes - if true propagates a RuleEngineInitializedEvent to other nodes.
        enableIncrementalUpdate - flag, if true, enables for incremental updates of the rule engine kie module
        result - the instance of RuleEngineActionResult accumulating the results of initialization
      • initialize

        public void initialize​(AbstractRulesModuleModel abstractModule,
                               java.lang.String deployedMvnVersion,
                               boolean propagateToOtherNodes,
                               boolean enableIncrementalUpdate,
                               RuleEngineActionResult result)
        Description copied from interface: RuleEngineService
        Since 6.4 Initializes the given rules module (and if propagateToOtherNodes is set to true propagates a RuleEngineInitializedEvent to other nodes).
        Specified by:
        initialize in interface RuleEngineService
        Parameters:
        abstractModule - the module to be initialized
        deployedMvnVersion - currently deployed mvn version of the rule engine module
        propagateToOtherNodes - if true propagates a RuleEngineInitializedEvent to other nodes.
        enableIncrementalUpdate - flag, if true, enables for incremental updates of the rule engine kie module
        result - the instance of RuleEngineActionResult accumulating the results of initialization
      • deactivateRulesModuleEngineRules

        public <T extends AbstractRuleEngineRuleModel> void deactivateRulesModuleEngineRules​(java.lang.String moduleName,
                                                                                             java.util.Collection<T> engineRules)
        Description copied from interface: RuleEngineService
        make the specified collection of engine rules belonging to a specified module inactive, so that the engine wouln't take them in consideration during init
        Specified by:
        deactivateRulesModuleEngineRules in interface RuleEngineService
        Type Parameters:
        T - a type of engine rules
        Parameters:
        moduleName - Name of the module the rules should refer to when applying changes
        engineRules - A collection of AbstractRuleEngineRuleModel to be deactivated
      • isBlocking

        protected boolean isBlocking()
      • switchKieModule

        protected void switchKieModule​(DroolsKIEModuleModel module,
                                       KieContainerListener listener,
                                       boolean propagateToOtherNodes,
                                       boolean enableIncrementalUpdate,
                                       RuleEngineActionResult result,
                                       java.util.Collection<java.util.function.Supplier<java.lang.Object>> chainOfPostTasks)
        Switches the Kie modules in the rule execution context
        Parameters:
        module - instance of the DroolsKIEModuleModel module
        listener - instance of KieContainerListener that implements the switching logic
        propagateToOtherNodes - flag, if true, enables the module swap/initialization event be propagated in the cluster
        enableIncrementalUpdate - flag, if true, enables for incremental updates of the rule engine kie module
        result - instance of RuleEngineActionResult to be used for cluster nodes notification
        chainOfPostTasks - chain of suppliers to be used as a sequence of post-swapping tasks
      • notifyOtherNodesAboutKieModuleSwapping

        protected void notifyOtherNodesAboutKieModuleSwapping​(java.lang.String moduleName,
                                                              java.lang.String deployedReleaseIdVersion)
      • isRuleEngineActive

        protected boolean isRuleEngineActive()
      • initializeAllRulesModules

        public java.util.List<RuleEngineActionResult> initializeAllRulesModules​(boolean propagateToOtherNodes)
        Description copied from interface: RuleEngineService
        Initializes all AbstractRulesModuleModels that are marked as active.
        Specified by:
        initializeAllRulesModules in interface RuleEngineService
        Parameters:
        propagateToOtherNodes - if true on all the nodes of cluster
        Returns:
        the activation results
      • getRuleForCodeAndModule

        public AbstractRuleEngineRuleModel getRuleForCodeAndModule​(java.lang.String code,
                                                                   java.lang.String moduleName)
        Description copied from interface: RuleEngineService
        Finds AbstractRuleEngineRuleModel for given code and module.
        Specified by:
        getRuleForCodeAndModule in interface RuleEngineService
        Parameters:
        code - the rule code
        moduleName - the rules module name
        Returns:
        AbstractRuleEngineRuleModel for given code.
      • getEventService

        protected EventService getEventService()
      • setEventService

        public void setEventService​(EventService eventService)
      • setConfigurationService

        public void setConfigurationService​(ConfigurationService configurationService)
      • createRuleEngineActionResult

        protected RuleEngineActionResult createRuleEngineActionResult​(java.lang.String message,
                                                                      java.lang.String moduleName,
                                                                      boolean success,
                                                                      MessageLevel level)
        creates a RuleEngineActionResult object with the given parameters. The result contains one ResultItem object with the given message and level.
        Parameters:
        message - the message
        moduleName - the module's name
        success - whether the operation of this result was successful or not (sets RuleEngineActionResult.setActionFailed(boolean) with the negated value of success
        level - the message level of the ResultItem
        Returns:
        a new RuleEngineActionResult object
      • populateRuleEngineActionResult

        protected void populateRuleEngineActionResult​(RuleEngineActionResult result,
                                                      java.lang.String message,
                                                      java.lang.String moduleName,
                                                      boolean success,
                                                      MessageLevel level)
        populates a RuleEngineActionResult object with the given parameters. Changes the state of RuleEngineActionResult and should be used with care
        Parameters:
        result - the RuleEngineActionResult instance to be populated with given fields
        message - the message
        moduleName - the module's name
        success - whether the operation of this result was successful or not (sets RuleEngineActionResult.setActionFailed(boolean) with the negated value of success
        level - the message level of the ResultItem
      • setup

        @PostConstruct
        public void setup()
        The method is used to set the date format and KIEServices before the class is put into service(dependency injection).
      • setEngineRuleDao

        public void setEngineRuleDao​(EngineRuleDao engineRuleDao)
      • setRulesModuleDao

        public void setRulesModuleDao​(RulesModuleDao rulesModuleDao)
      • getModelService

        protected ModelService getModelService()
      • setModelService

        public void setModelService​(ModelService modelService)
      • setRuleEngineKieModuleSwapper

        public void setRuleEngineKieModuleSwapper​(RuleEngineKieModuleSwapper ruleEngineKieModuleSwapper)
      • setDroolsKIEBaseFinderStrategy

        public void setDroolsKIEBaseFinderStrategy​(DroolsKIEBaseFinderStrategy droolsKIEBaseFinderStrategy)
      • setRuleEngineCacheService

        public void setRuleEngineCacheService​(RuleEngineCacheService ruleEngineCacheService)
      • setConcurrentMapFactory

        public void setConcurrentMapFactory​(ConcurrentMapFactory concurrentMapFactory)
      • getInitializationMultiFlag

        protected MultiFlag getInitializationMultiFlag()
      • setKieSessionHelper

        public void setKieSessionHelper​(KieSessionHelper kieSessionHelper)
      • getRuleEngineContainerRegistry

        protected RuleEngineContainerRegistry<org.kie.api.builder.ReleaseId,​org.kie.api.runtime.KieContainer> getRuleEngineContainerRegistry()
      • setRuleEngineContainerRegistry

        public void setRuleEngineContainerRegistry​(RuleEngineContainerRegistry<org.kie.api.builder.ReleaseId,​org.kie.api.runtime.KieContainer> ruleEngineContainerRegistry)
      • setEngineRulesRepository

        public void setEngineRulesRepository​(EngineRulesRepository engineRulesRepository)