use of org.eclipse.smarthome.automation.handler.TriggerHandler in project smarthome by eclipse.
the class RuleEngine method register.
/**
* This method register the Rule to start working. This is the final step of initialization process where triggers
* received {@link RuleEngineCallback}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(RuntimeRule rule) {
RuleEngineCallback reCallback = getRuleEngineCallback(rule);
for (Iterator<Trigger> it = rule.getTriggers().iterator(); it.hasNext(); ) {
RuntimeTrigger t = (RuntimeTrigger) it.next();
TriggerHandler triggerHandler = t.getModuleHandler();
triggerHandler.setRuleEngineCallback(reCallback);
}
}
use of org.eclipse.smarthome.automation.handler.TriggerHandler in project smarthome by eclipse.
the class CompositeTriggerHandler method setRuleEngineCallback.
/**
* 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.eclipse.smarthome.automation.handler.TriggerHandler#setRuleEngineCallback(org.eclipse.smarthome.automation.handler.RuleEngineCallback)
*/
@Override
public void setRuleEngineCallback(RuleEngineCallback ruleCallback) {
this.ruleCallback = ruleCallback;
if (ruleCallback != null) {
// could be called with 'null' from dispose
List<Trigger> children = getChildren();
for (Trigger child : children) {
TriggerHandler handler = moduleHandlerMap.get(child);
handler.setRuleEngineCallback(this);
}
}
}
use of org.eclipse.smarthome.automation.handler.TriggerHandler in project smarthome by eclipse.
the class CompositeModuleHandlerFactory method internalCreate.
@Override
public ModuleHandler internalCreate(Module module, String ruleUID) {
ModuleHandler handler = null;
if (module != null) {
String moduleType = module.getTypeUID();
ModuleType mt = mtRegistry.get(moduleType);
if (mt instanceof CompositeTriggerType) {
List<Trigger> childModules = ((CompositeTriggerType) mt).getChildren();
LinkedHashMap<Trigger, TriggerHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeTriggerHandler((Trigger) module, (CompositeTriggerType) mt, mapModuleToHandler, ruleUID);
}
} else if (mt instanceof CompositeConditionType) {
List<Condition> childModules = ((CompositeConditionType) mt).getChildren();
LinkedHashMap<Condition, ConditionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeConditionHandler((Condition) module, (CompositeConditionType) mt, mapModuleToHandler, ruleUID);
}
} else if (mt instanceof CompositeActionType) {
List<Action> childModules = ((CompositeActionType) mt).getChildren();
LinkedHashMap<Action, ActionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeActionHandler((Action) module, (CompositeActionType) mt, mapModuleToHandler, ruleUID);
}
}
if (handler != null) {
logger.debug("Set module handler: {} -> {} of rule {}.", module.getId(), handler.getClass().getSimpleName() + "(" + moduleType + ")", ruleUID);
} else {
logger.debug("Not found module handler {} for moduleType {} of rule {}.", module.getId(), moduleType, ruleUID);
}
}
return handler;
}
Aggregations