Search in sources :

Example 1 with TriggerHandler

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);
    }
}
Also used : Trigger(org.eclipse.smarthome.automation.Trigger) RuleEngineCallback(org.eclipse.smarthome.automation.handler.RuleEngineCallback) TriggerHandler(org.eclipse.smarthome.automation.handler.TriggerHandler)

Example 2 with TriggerHandler

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);
        }
    }
}
Also used : Trigger(org.eclipse.smarthome.automation.Trigger) TriggerHandler(org.eclipse.smarthome.automation.handler.TriggerHandler)

Example 3 with TriggerHandler

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;
}
Also used : Action(org.eclipse.smarthome.automation.Action) TriggerHandler(org.eclipse.smarthome.automation.handler.TriggerHandler) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) LinkedHashMap(java.util.LinkedHashMap) ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler) CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) ModuleType(org.eclipse.smarthome.automation.type.ModuleType) Trigger(org.eclipse.smarthome.automation.Trigger) List(java.util.List) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) ActionHandler(org.eclipse.smarthome.automation.handler.ActionHandler)

Aggregations

Trigger (org.eclipse.smarthome.automation.Trigger)3 TriggerHandler (org.eclipse.smarthome.automation.handler.TriggerHandler)3 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Action (org.eclipse.smarthome.automation.Action)1 ActionHandler (org.eclipse.smarthome.automation.handler.ActionHandler)1 ModuleHandler (org.eclipse.smarthome.automation.handler.ModuleHandler)1 RuleEngineCallback (org.eclipse.smarthome.automation.handler.RuleEngineCallback)1 CompositeActionType (org.eclipse.smarthome.automation.type.CompositeActionType)1 CompositeConditionType (org.eclipse.smarthome.automation.type.CompositeConditionType)1 CompositeTriggerType (org.eclipse.smarthome.automation.type.CompositeTriggerType)1 ModuleType (org.eclipse.smarthome.automation.type.ModuleType)1