Class DefaultPlatformRuleEngineService
java.lang.Object
de.hybris.platform.ruleengine.impl.DefaultPlatformRuleEngineService
- All Implemented Interfaces:
RuleEngineService
The DefaultDroolsRuleEngineService allows initialization and evaluation of rules modules.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends DroolsRuleModel>
Optional<InitializationFuture>archiveRules(Collection<T> engineRules) Archive a collection of rulesprotected RuleEngineActionResultcreateRuleEngineActionResult(String message, String moduleName, boolean success, MessageLevel level) creates a RuleEngineActionResult object with the given parameters.<T extends AbstractRuleEngineRuleModel>
voiddeactivateRulesModuleEngineRules(String moduleName, Collection<T> engineRules) make the specified collection of engine rules belonging to a specified module inactive, so that the engine wouln't take them in consideration during initprotected voiddoSwapKieContainers(org.kie.api.runtime.KieContainer kieContainer, KIEModuleCacheBuilder cache, RuleEngineActionResult ruleEngineActionResult, DroolsKIEModuleModel module, String deployedReleaseIdVersion, boolean propagateToOtherNodes) evaluate(RuleEvaluationContext context) Since 6.0 Executes rule evaluation for given RuleEvaluationContext.protected Supplier<org.kie.api.runtime.ExecutionResults>executionResultsSupplierWithStatefulSession(org.kie.api.runtime.KieContainer kContainer, org.kie.api.command.BatchExecutionCommand command, RuleEvaluationContext context) protected Supplier<org.kie.api.runtime.ExecutionResults>executionResultsSupplierWithStatelessSession(org.kie.api.runtime.KieContainer kContainer, org.kie.api.command.BatchExecutionCommand command, RuleEvaluationContext context) protected ConcurrentMapFactoryprotected ConfigurationServiceprotected DroolsKIEBaseFinderStrategyprotected EngineRuleDaoprotected EngineRulesRepositoryprotected EventServiceprotected MultiFlagprotected KieSessionHelperprotected Function<RuleEvaluationContext,Integer> protected ModelServiceprotected PostRulesModuleSwappingTasksProviderprotected RuleEngineBootstrap<org.kie.api.KieServices,org.kie.api.runtime.KieContainer, DroolsKIEModuleModel> protected RuleEngineCacheServiceprotected RuleEngineContainerRegistry<org.kie.api.builder.ReleaseId,org.kie.api.runtime.KieContainer> protected RuleEngineKieModuleSwapperprotected org.springframework.retry.support.RetryTemplategetRuleForCodeAndModule(String code, String moduleName) Finds AbstractRuleEngineRuleModel for given code and module.getRuleForUuid(String uuid) Finds AbstractRuleEngineRuleModel for given uuid.protected RulesModuleDaovoidinitialize(AbstractRulesModuleModel abstractModule, String deployedMvnVersion, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, RuleEngineActionResult result) Since 6.4 Initializes the given rules module (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).voidinitialize(AbstractRulesModuleModel abstractModule, String deployedMvnVersion, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, RuleEngineActionResult result, ExecutionContext executionContext) Since 18.08 Initializes the given rules module (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).initialize(List<AbstractRulesModuleModel> modules, boolean propagateToOtherNodes, boolean enableIncrementalUpdate) Since 6.4 Initializes the given rules module in blocking/async mode (depending on blocking param) (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).initialize(List<AbstractRulesModuleModel> modules, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, ExecutionContext executionContext) Since 6.7 Initializes the given rules module in blocking/async mode (depending on blocking param) (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).Initializes allAbstractRulesModuleModels that are marked as active (in case of cluster mode - on all the nodes).initializeAllRulesModules(boolean propagateToOtherNodes) Initializes allAbstractRulesModuleModels that are marked as active.voidinitializeNonBlocking(AbstractRulesModuleModel abstractModule, String deployedMvnVersion, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, RuleEngineActionResult result) Since 6.4 Asynchronously initializes the given rules module (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).protected booleanprotected booleanprotected voidprotected voidnotifyOtherNodesAboutKieModuleSwapping(String moduleName, String deployedReleaseIdVersion) protected voidpopulateRuleEngineActionResult(RuleEngineActionResult result, String message, String moduleName, boolean success, MessageLevel level) populates a RuleEngineActionResult object with the given parameters.protected voidretrySetFlagWhenSwitchKieModule(String moduleName) voidsetConcurrentMapFactory(ConcurrentMapFactory concurrentMapFactory) voidsetConfigurationService(ConfigurationService configurationService) voidsetDroolsKIEBaseFinderStrategy(DroolsKIEBaseFinderStrategy droolsKIEBaseFinderStrategy) voidsetEngineRuleDao(EngineRuleDao engineRuleDao) voidsetEngineRulesPersistingTaskProcessor(RuleEngineTaskProcessor<AbstractRuleEngineRuleModel, TaskResult> engineRulesPersistingTaskProcessor) voidsetEngineRulesRepository(EngineRulesRepository engineRulesRepository) voidsetEventService(EventService eventService) voidsetKieSessionHelper(KieSessionHelper kieSessionHelper) voidsetMaxRuleExecutionsFunction(Function<RuleEvaluationContext, Integer> maxRuleExecutionsFunction) voidsetModelService(ModelService modelService) voidsetPostRulesModuleSwappingTasksProvider(PostRulesModuleSwappingTasksProvider postRulesModuleSwappingTasksProvider) voidsetRuleEngineBootstrap(RuleEngineBootstrap<org.kie.api.KieServices, org.kie.api.runtime.KieContainer, DroolsKIEModuleModel> ruleEngineBootstrap) voidsetRuleEngineCacheService(RuleEngineCacheService ruleEngineCacheService) voidsetRuleEngineContainerRegistry(RuleEngineContainerRegistry<org.kie.api.builder.ReleaseId, org.kie.api.runtime.KieContainer> ruleEngineContainerRegistry) voidsetRuleEngineKieModuleSwapper(RuleEngineKieModuleSwapper ruleEngineKieModuleSwapper) voidsetRuleEnginePublishRetryTemplate(org.springframework.retry.support.RetryTemplate ruleEnginePublishRetryTemplate) voidsetRulesModuleDao(RulesModuleDao rulesModuleDao) voidsetup()The method is used to set the date format and KIEServices before the class is put into service(dependency injection).protected voidswitchKieModule(DroolsKIEModuleModel module, KieContainerListener listener, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, RuleEngineActionResult result, Collection<Supplier<Object>> chainOfPostTasks) Switches the Kie modules in the rule execution contextupdateEngineRule(AbstractRuleEngineRuleModel ruleEngineRule, AbstractRulesModuleModel rulesModule) Updates the given rule if it already exists.protected Optional<RuleEngineActionResult>validateEngineRulesModule(AbstractRulesModuleModel rulesModule)
-
Field Details
-
MODULE_MVN_VERSION_NONE
- See Also:
-
SWAPPING_IS_BLOCKING
- See Also:
-
-
Constructor Details
-
DefaultPlatformRuleEngineService
public DefaultPlatformRuleEngineService()
-
-
Method Details
-
evaluate
Description copied from interface:RuleEngineServiceSince 6.0 Executes rule evaluation for given RuleEvaluationContext. Executes all rules contained within the context- Specified by:
evaluatein interfaceRuleEngineService- Parameters:
context- the rule engine context containing data about rule engine execution- Returns:
- results of rule engine execution
-
executionResultsSupplierWithStatefulSession
protected Supplier<org.kie.api.runtime.ExecutionResults> executionResultsSupplierWithStatefulSession(org.kie.api.runtime.KieContainer kContainer, org.kie.api.command.BatchExecutionCommand command, RuleEvaluationContext context) -
executionResultsSupplierWithStatelessSession
protected 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(List<AbstractRulesModuleModel> modules, boolean propagateToOtherNodes, boolean enableIncrementalUpdate) Description copied from interface:RuleEngineServiceSince 6.4 Initializes the given rules module in blocking/async mode (depending on blocking param) (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).- Specified by:
initializein interfaceRuleEngineService- Parameters:
modules- the modules to be initializedpropagateToOtherNodes- if true propagates aRuleEngineInitializedEventto other nodes.enableIncrementalUpdate- flag, if true, enables for incremental updates of the rule engine kie module- Returns:
- instance of
InitializationFutureto be used for eventual blocking on multiple parallel swapping
-
initialize
public InitializationFuture initialize(List<AbstractRulesModuleModel> modules, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, ExecutionContext executionContext) Description copied from interface:RuleEngineServiceSince 6.7 Initializes the given rules module in blocking/async mode (depending on blocking param) (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).- Specified by:
initializein interfaceRuleEngineService- Parameters:
modules- the modules to be initializedpropagateToOtherNodes- if true propagates aRuleEngineInitializedEventto other nodes.enableIncrementalUpdate- flag, if true, enables for incremental updates of the rule engine kie moduleexecutionContext- instance ofExecutionContextthat serves as a storage for initialization related data- Returns:
- instance of
InitializationFutureto be used for eventual blocking on multiple parallel swapping
-
initializeNonBlocking
public void initializeNonBlocking(AbstractRulesModuleModel abstractModule, String deployedMvnVersion, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, RuleEngineActionResult result) Description copied from interface:RuleEngineServiceSince 6.4 Asynchronously initializes the given rules module (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).- Specified by:
initializeNonBlockingin interfaceRuleEngineService- Parameters:
abstractModule- the module to be initializeddeployedMvnVersion- currently deployed version of the Kie ModulepropagateToOtherNodes- if true propagates aRuleEngineInitializedEventto other nodes.enableIncrementalUpdate- flag, if true, enables for incremental updates of the rule engine kie moduleresult- the instance ofRuleEngineActionResultaccumulating the results of initialization
-
initialize
public void initialize(AbstractRulesModuleModel abstractModule, String deployedMvnVersion, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, RuleEngineActionResult result) Description copied from interface:RuleEngineServiceSince 6.4 Initializes the given rules module (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).- Specified by:
initializein interfaceRuleEngineService- Parameters:
abstractModule- the module to be initializeddeployedMvnVersion- currently deployed mvn version of the rule engine modulepropagateToOtherNodes- if true propagates aRuleEngineInitializedEventto other nodes.enableIncrementalUpdate- flag, if true, enables for incremental updates of the rule engine kie moduleresult- the instance ofRuleEngineActionResultaccumulating the results of initialization
-
initialize
public void initialize(AbstractRulesModuleModel abstractModule, String deployedMvnVersion, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, RuleEngineActionResult result, ExecutionContext executionContext) Description copied from interface:RuleEngineServiceSince 18.08 Initializes the given rules module (and ifpropagateToOtherNodesis set totruepropagates aRuleEngineInitializedEventto other nodes).- Specified by:
initializein interfaceRuleEngineService- Parameters:
abstractModule- the module to be initializeddeployedMvnVersion- currently deployed mvn version of the rule engine modulepropagateToOtherNodes- if true propagates aRuleEngineInitializedEventto other nodes.enableIncrementalUpdate- flag, if true, enables for incremental updates of the rule engine kie moduleresult- the instance ofRuleEngineActionResultaccumulating the results of initializationexecutionContext- the instance ofExecutionContextto be set as executionContext ofRuleEngineActionResultif not null
-
deactivateRulesModuleEngineRules
public <T extends AbstractRuleEngineRuleModel> void deactivateRulesModuleEngineRules(String moduleName, Collection<T> engineRules) Description copied from interface:RuleEngineServicemake 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:
deactivateRulesModuleEngineRulesin interfaceRuleEngineService- Type Parameters:
T- a type of engine rules- Parameters:
moduleName- Name of the module the rules should refer to when applying changesengineRules- A collection ofAbstractRuleEngineRuleModelto be deactivated
-
doSwapKieContainers
protected void doSwapKieContainers(org.kie.api.runtime.KieContainer kieContainer, KIEModuleCacheBuilder cache, RuleEngineActionResult ruleEngineActionResult, DroolsKIEModuleModel module, String deployedReleaseIdVersion, boolean propagateToOtherNodes) -
isBlocking
protected boolean isBlocking() -
retrySetFlagWhenSwitchKieModule
-
switchKieModule
protected void switchKieModule(DroolsKIEModuleModel module, KieContainerListener listener, boolean propagateToOtherNodes, boolean enableIncrementalUpdate, RuleEngineActionResult result, Collection<Supplier<Object>> chainOfPostTasks) Switches the Kie modules in the rule execution context- Parameters:
module- instance of theDroolsKIEModuleModelmodulelistener- instance ofKieContainerListenerthat implements the switching logicpropagateToOtherNodes- flag, if true, enables the module swap/initialization event be propagated in the clusterenableIncrementalUpdate- flag, if true, enables for incremental updates of the rule engine kie moduleresult- instance ofRuleEngineActionResultto be used for cluster nodes notificationchainOfPostTasks- chain of suppliers to be used as a sequence of post-swapping tasks
-
notifyOtherNodes
-
notifyOtherNodesAboutKieModuleSwapping
-
isRuleEngineActive
protected boolean isRuleEngineActive() -
initializeAllRulesModules
Description copied from interface:RuleEngineServiceInitializes allAbstractRulesModuleModels that are marked as active.- Specified by:
initializeAllRulesModulesin interfaceRuleEngineService- Parameters:
propagateToOtherNodes- if true on all the nodes of cluster- Returns:
- the activation results
-
initializeAllRulesModules
Description copied from interface:RuleEngineServiceInitializes allAbstractRulesModuleModels that are marked as active (in case of cluster mode - on all the nodes).- Specified by:
initializeAllRulesModulesin interfaceRuleEngineService- Returns:
- the results of the initialize action (use
RuleEngineActionResult.isActionFailed()to check if the action succeeded)
-
updateEngineRule
public RuleEngineActionResult updateEngineRule(@Nonnull AbstractRuleEngineRuleModel ruleEngineRule, @Nonnull AbstractRulesModuleModel rulesModule) Description copied from interface:RuleEngineServiceUpdates the given rule if it already exists.- Specified by:
updateEngineRulein interfaceRuleEngineService- Parameters:
ruleEngineRule- Rule to be updatedrulesModule-AbstractRulesModuleModelwhere the Rule be updated- Returns:
- the result of the update action (use
RuleEngineActionResult.isActionFailed()to check if the action succeeded)
-
validateEngineRulesModule
protected Optional<RuleEngineActionResult> validateEngineRulesModule(AbstractRulesModuleModel rulesModule) -
archiveRules
public <T extends DroolsRuleModel> Optional<InitializationFuture> archiveRules(@Nonnull Collection<T> engineRules) Description copied from interface:RuleEngineServiceArchive a collection of rules- Specified by:
archiveRulesin interfaceRuleEngineService- Type Parameters:
T- subtype ofDroolsRuleModel- Parameters:
engineRules- collection ofDroolsRuleModelinstances- Returns:
- optional of
InitializationFuturekeeping the status of initialization
-
getRuleForCodeAndModule
Description copied from interface:RuleEngineServiceFinds AbstractRuleEngineRuleModel for given code and module.- Specified by:
getRuleForCodeAndModulein interfaceRuleEngineService- Parameters:
code- the rule codemoduleName- the rules module name- Returns:
- AbstractRuleEngineRuleModel for given code.
-
getRuleForUuid
Description copied from interface:RuleEngineServiceFinds AbstractRuleEngineRuleModel for given uuid.- Specified by:
getRuleForUuidin interfaceRuleEngineService- Parameters:
uuid- the rule uuid- Returns:
- AbstractRuleEngineRuleModel for given uuid.
-
getEventService
-
setEventService
-
getConfigurationService
-
setConfigurationService
-
createRuleEngineActionResult
protected RuleEngineActionResult createRuleEngineActionResult(String message, String moduleName, boolean success, MessageLevel level) creates a RuleEngineActionResult object with the given parameters. The result contains one ResultItem object with the givenmessageandlevel.- Parameters:
message- the messagemoduleName- the module's namesuccess- whether the operation of this result was successful or not (setsRuleEngineActionResult.setActionFailed(boolean)with the negated value ofsuccesslevel- the message level of the ResultItem- Returns:
- a new RuleEngineActionResult object
-
populateRuleEngineActionResult
protected void populateRuleEngineActionResult(RuleEngineActionResult result, String message, String moduleName, boolean success, MessageLevel level) populates a RuleEngineActionResult object with the given parameters. Changes the state ofRuleEngineActionResultand should be used with care- Parameters:
result- theRuleEngineActionResultinstance to be populated with given fieldsmessage- the messagemoduleName- the module's namesuccess- whether the operation of this result was successful or not (setsRuleEngineActionResult.setActionFailed(boolean)with the negated value ofsuccesslevel- 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). -
getEngineRuleDao
-
setEngineRuleDao
-
getRulesModuleDao
-
setRulesModuleDao
-
getModelService
-
setModelService
-
getRuleEngineKieModuleSwapper
-
setRuleEngineKieModuleSwapper
-
getDroolsKIEBaseFinderStrategy
-
setDroolsKIEBaseFinderStrategy
-
getRuleEngineCacheService
-
setRuleEngineCacheService
-
getConcurrentMapFactory
-
setConcurrentMapFactory
-
getInitializationMultiFlag
-
getKieSessionHelper
-
setKieSessionHelper
-
getEngineRulesPersistingTaskProcessor
protected RuleEngineTaskProcessor<AbstractRuleEngineRuleModel,TaskResult> getEngineRulesPersistingTaskProcessor() -
setEngineRulesPersistingTaskProcessor
public void setEngineRulesPersistingTaskProcessor(RuleEngineTaskProcessor<AbstractRuleEngineRuleModel, TaskResult> engineRulesPersistingTaskProcessor) -
getRuleEngineBootstrap
protected RuleEngineBootstrap<org.kie.api.KieServices,org.kie.api.runtime.KieContainer, getRuleEngineBootstrap()DroolsKIEModuleModel> -
setRuleEngineBootstrap
public void setRuleEngineBootstrap(RuleEngineBootstrap<org.kie.api.KieServices, org.kie.api.runtime.KieContainer, DroolsKIEModuleModel> ruleEngineBootstrap) -
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) -
getEngineRulesRepository
-
setEngineRulesRepository
-
getPostRulesModuleSwappingTasksProvider
-
setPostRulesModuleSwappingTasksProvider
public void setPostRulesModuleSwappingTasksProvider(PostRulesModuleSwappingTasksProvider postRulesModuleSwappingTasksProvider) -
getMaxRuleExecutionsFunction
-
setMaxRuleExecutionsFunction
public void setMaxRuleExecutionsFunction(Function<RuleEvaluationContext, Integer> maxRuleExecutionsFunction) -
setRuleEnginePublishRetryTemplate
public void setRuleEnginePublishRetryTemplate(org.springframework.retry.support.RetryTemplate ruleEnginePublishRetryTemplate) -
getRuleEnginePublishRetryTemplate
protected org.springframework.retry.support.RetryTemplate getRuleEnginePublishRetryTemplate()
-