/** * The {@link CompositeTriggerHandler} sets itself as callback to the child triggers and store the callback to the * rule engine. In this way the trigger of composite type will be notified always when some of the child triggers * are triggered and has an opportunity to set the outputs of parent trigger to the rule context. * * @see org.openhab.core.automation.handler.TriggerHandler#setTriggerHandlerCallback(org.openhab.core.automation.handler.TriggerHandlerCallback) */ @Override public void setCallback(@Nullable ModuleHandlerCallback callback) { this.callback = (TriggerHandlerCallback) callback; if (callback instanceof TriggerHandlerCallback) {// could be called with 'null' from dispose and might not be a // trigger callback List<Trigger> children = getChildren(); for (Trigger child : children) { TriggerHandler handler = moduleHandlerMap.get(child); handler.setCallback(this); } } }
/** * This method register the Rule to start working. This is the final step of initialization process where * triggers received {@link TriggerHandlerCallback}s object and starts to notify the rule engine when they are * triggered. After activating all triggers the rule goes into IDLE state. * * @param rule an initialized rule which has to starts tracking the triggers. */ private void register(WrappedRule rule) { final String ruleUID = rule.getUID(); TriggerHandlerCallback thCallback = getTriggerHandlerCallback(ruleUID); rule.getTriggers().forEach(trigger -> { TriggerHandler triggerHandler = trigger.getModuleHandler(); if (triggerHandler != null) { triggerHandler.setCallback(thCallback); } }); rule.getConditions().forEach(condition -> { ConditionHandler conditionHandler = condition.getModuleHandler(); if (conditionHandler != null) { conditionHandler.setCallback(moduleHandlerCallback); } }); rule.getActions().forEach(action -> { ActionHandler actionHandler = action.getModuleHandler(); if (actionHandler != null) { actionHandler.setCallback(moduleHandlerCallback); } }); }