Search in sources :

Example 1 with ModuleHandlerFactory

use of org.eclipse.smarthome.automation.handler.ModuleHandlerFactory in project smarthome by eclipse.

the class RuleEngine method added.

@Override
public void added(ModuleType moduleType) {
    String moduleTypeName = moduleType.getUID();
    for (ModuleHandlerFactory moduleHandlerFactory : allModuleHandlerFactories) {
        Collection<String> moduleTypes = moduleHandlerFactory.getTypes();
        if (moduleTypes.contains(moduleTypeName)) {
            synchronized (this) {
                this.moduleHandlerFactories.put(moduleTypeName, moduleHandlerFactory);
            }
            break;
        }
    }
    Set<String> rules = null;
    synchronized (this) {
        Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
        if (rulesPerModule != null) {
            rules = new HashSet<String>();
            rules.addAll(rulesPerModule);
        }
    }
    if (rules != null) {
        for (String rUID : rules) {
            RuleStatus ruleStatus = getRuleStatus(rUID);
            if (ruleStatus == RuleStatus.UNINITIALIZED) {
                scheduleRuleInitialization(rUID);
            }
        }
    }
}
Also used : CompositeModuleHandlerFactory(org.eclipse.smarthome.automation.core.internal.composite.CompositeModuleHandlerFactory) ModuleHandlerFactory(org.eclipse.smarthome.automation.handler.ModuleHandlerFactory) RuleStatus(org.eclipse.smarthome.automation.RuleStatus)

Example 2 with ModuleHandlerFactory

use of org.eclipse.smarthome.automation.handler.ModuleHandlerFactory in project smarthome by eclipse.

the class RuleEngine method getModuleHandler.

/**
 * Gets handler of passed module.
 *
 * @param m a {@link Module} which is looking for handler
 * @return handler for this module or null when it is not available.
 */
private ModuleHandler getModuleHandler(Module m, String ruleUID) {
    String moduleTypeId = m.getTypeUID();
    ModuleHandlerFactory mhf = getModuleHandlerFactory(moduleTypeId);
    if (mhf == null || mtRegistry.get(moduleTypeId) == null) {
        return null;
    }
    return mhf.getHandler(m, ruleUID);
}
Also used : CompositeModuleHandlerFactory(org.eclipse.smarthome.automation.core.internal.composite.CompositeModuleHandlerFactory) ModuleHandlerFactory(org.eclipse.smarthome.automation.handler.ModuleHandlerFactory)

Example 3 with ModuleHandlerFactory

use of org.eclipse.smarthome.automation.handler.ModuleHandlerFactory in project smarthome by eclipse.

the class CompositeModuleHandlerFactory method getChildHandlers.

/**
 * This method associates module handlers to the child modules of composite module types. It links module types of
 * child modules to the rule which contains this composite module. It also resolve links between child configuration
 * properties and configuration of composite module see:
 * {@link #ReferenceResolverUtil.updateModuleConfiguration(Module, Map)}.
 *
 * @param compositeConfig configuration values of composite module.
 * @param childModules list of child modules
 * @param childModulePrefix defines UID of child module. The rule id is not enough for prefix when a composite type
 *            is used more then one time in one and the same rule. For example the prefix can be:
 *            ruleId:compositeModuleId:compositeModileId2.
 * @return map of pairs of module and its handler. Return null when some of the child modules can not find its
 *         handler.
 */
@SuppressWarnings("unchecked")
private <T extends Module, MT extends ModuleHandler> LinkedHashMap<T, MT> getChildHandlers(String compositeModuleId, Configuration compositeConfig, List<T> childModules, String childModulePrefix) {
    LinkedHashMap<T, MT> mapModuleToHandler = new LinkedHashMap<T, MT>();
    for (T child : childModules) {
        String ruleId = getRuleId(childModulePrefix);
        ruleEngine.updateMapModuleTypeToRule(ruleId, child.getTypeUID());
        ModuleHandlerFactory childMhf = ruleEngine.getModuleHandlerFactory(child.getTypeUID());
        if (childMhf == null) {
            mapModuleToHandler.clear();
            mapModuleToHandler = null;
            return null;
        }
        ReferenceResolverUtil.updateModuleConfiguration(child, compositeConfig.getProperties());
        MT childHandler = (MT) childMhf.getHandler(child, childModulePrefix + ":" + compositeModuleId);
        if (childHandler == null) {
            mapModuleToHandler.clear();
            mapModuleToHandler = null;
            return null;
        }
        mapModuleToHandler.put(child, childHandler);
    }
    return mapModuleToHandler;
}
Also used : BaseModuleHandlerFactory(org.eclipse.smarthome.automation.handler.BaseModuleHandlerFactory) ModuleHandlerFactory(org.eclipse.smarthome.automation.handler.ModuleHandlerFactory) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ModuleHandlerFactory

use of org.eclipse.smarthome.automation.handler.ModuleHandlerFactory in project smarthome by eclipse.

the class CompositeModuleHandlerFactory method ungetHandler.

@SuppressWarnings({ "unchecked" })
@Override
public void ungetHandler(Module module, String childModulePrefix, ModuleHandler handler) {
    ModuleHandler handlerOfModule = getHandlers().get(childModulePrefix + module.getId());
    if (handlerOfModule instanceof AbstractCompositeModuleHandler) {
        AbstractCompositeModuleHandler<Module, ?, ?> h = (AbstractCompositeModuleHandler<Module, ?, ?>) handlerOfModule;
        Set<Module> modules = h.moduleHandlerMap.keySet();
        if (modules != null) {
            for (Module child : modules) {
                ModuleHandler childHandler = h.moduleHandlerMap.get(child);
                ModuleHandlerFactory mhf = ruleEngine.getModuleHandlerFactory(child.getTypeUID());
                mhf.ungetHandler(child, childModulePrefix + ":" + module.getId(), childHandler);
            }
        }
    }
    String ruleId = getRuleId(childModulePrefix);
    super.ungetHandler(module, ruleId, handler);
}
Also used : ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler) BaseModuleHandlerFactory(org.eclipse.smarthome.automation.handler.BaseModuleHandlerFactory) ModuleHandlerFactory(org.eclipse.smarthome.automation.handler.ModuleHandlerFactory) Module(org.eclipse.smarthome.automation.Module)

Aggregations

ModuleHandlerFactory (org.eclipse.smarthome.automation.handler.ModuleHandlerFactory)4 CompositeModuleHandlerFactory (org.eclipse.smarthome.automation.core.internal.composite.CompositeModuleHandlerFactory)2 BaseModuleHandlerFactory (org.eclipse.smarthome.automation.handler.BaseModuleHandlerFactory)2 LinkedHashMap (java.util.LinkedHashMap)1 Module (org.eclipse.smarthome.automation.Module)1 RuleStatus (org.eclipse.smarthome.automation.RuleStatus)1 ModuleHandler (org.eclipse.smarthome.automation.handler.ModuleHandler)1