How to deactivate/activate rules in TIBCO BusinessEvents.
book
Article ID: KB0084750
calendar_today
Updated On:
TIBCO BusinessEvents Enterprise Edition
-
Not Applicable
-
Show More
Show Less
Description
Resolution: Description: =========== How to deactivate/activate rules in TIBCO BusinessEvents. Environment: =========== BusinessEvents 4.0.1 All Operating Systems Resolution: ======== Create a custom function that iterates through all rules defined in the project and deactivate/activate the required rules (rule-uri). Example: (code suggested by Engineering) ============================================================= import com.tibco.cep.kernel.core.base.WorkingMemoryImpl; import com.tibco.cep.kernel.core.rete.conflict.AgendaItem; import com.tibco.cep.kernel.model.knowledgebase.ExecutionContext; import com.tibco.cep.kernel.model.knowledgebase.WorkingMemory; import com.tibco.cep.kernel.model.rule.Rule; import com.tibco.cep.kernel.service.logging.Level; import com.tibco.cep.runtime.session.RuleServiceProviderManager; import com.tibco.cep.runtime.session.RuleSession; import com.tibco.cep.runtime.session.RuleSessionManager; import com.tibco.cep.runtime.session.impl.RuleSessionImpl; public class EngineOperations { public static boolean activateRules(String ruleUriExpr) { RuleSessionImpl session = (RuleSessionImpl) RuleSessionManager.getCurrentRuleSession(); WorkingMemory wm = session.getWorkingMemory(); try { int result = 0; Iterator<Rule> ruleItr = wm.getRuleLoader().getRules().iterator(); while (ruleItr.hasNext()) { Rule rule = ruleItr.next(); String ruleUri = rule.getUri(); if (ruleUri.matches(ruleUriExpr)) { Rule actRule = wm.getRuleLoader().activateRule(ruleUri); if (actRule != null) { result++; session.getRuleServiceProvider().getLogger("custom.code").log(Level.INFO, "Activated rule: " + ruleUri); } } } return (result > 0); } catch (Exception e) { session.getRuleServiceProvider().getLogger("custom.code").log(Level.ERROR, e, "Activating rules failed: " + ruleUriExpr); } return false; } public static boolean deactivateRules(String ruleUriExpr) { RuleSessionImpl session = (RuleSessionImpl) RuleSessionManager.getCurrentRuleSession(); WorkingMemory wm = session.getWorkingMemory(); try { int result = 0; Iterator<Rule> ruleItr = wm.getRuleLoader().getRules().iterator(); while (ruleItr.hasNext()) { Rule rule = ruleItr.next(); String ruleUri = rule.getUri(); if (ruleUri.matches(ruleUriExpr)) { Rule actRule = wm.getRuleLoader().activateRule(ruleUri); if (actRule != null) { result++; session.getRuleServiceProvider().getLogger("custom.code").log(Level.INFO, "Deactivated rule: " + ruleUri); } } } return (result > 0); } catch (Exception e) { session.getRuleServiceProvider().getLogger("custom.code").log(Level.ERROR, e, "Deactivating rules failed: " + ruleUriExpr); } return false; } } =============================================================
Issue/Introduction
How to deactivate/activate rules in TIBCO BusinessEvents.
Feedback
thumb_up
Yes
thumb_down
No