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);
}
}
}
}
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);
}
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;
}
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);
}
Aggregations