Search in sources :

Example 6 with WrappedRule

use of org.eclipse.smarthome.automation.core.internal.ruleengine.WrappedRule in project smarthome by eclipse.

the class RuleEngineImpl method scheduleRuleInitialization.

/**
 * Creates and schedules a re-initialization task for the {@link Rule} with the specified UID.
 *
 * @param rUID the UID of the {@link Rule}.
 */
protected void scheduleRuleInitialization(final String rUID) {
    Future<?> f = scheduleTasks.get(rUID);
    if (f == null || f.isDone()) {
        ScheduledExecutorService ex = getScheduledExecutor();
        f = ex.schedule(new Runnable() {

            @Override
            public void run() {
                final WrappedRule managedRule = getManagedRule(rUID);
                if (managedRule == null) {
                    return;
                }
                setRule(managedRule);
            }
        }, scheduleReinitializationDelay, TimeUnit.MILLISECONDS);
        scheduleTasks.put(rUID, f);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WrappedRule(org.eclipse.smarthome.automation.core.internal.ruleengine.WrappedRule)

Example 7 with WrappedRule

use of org.eclipse.smarthome.automation.core.internal.ruleengine.WrappedRule in project smarthome by eclipse.

the class RuleEngineImpl method removeRule.

/**
 * This method removes Rule from the rule engine.
 *
 * @param rUID id of removed {@link Rule}
 * @return true when a rule is deleted, false when there is no rule with such id.
 */
protected boolean removeRule(String rUID) {
    final WrappedRule r = managedRules.remove(rUID);
    if (r != null) {
        unregister(r);
        synchronized (this) {
            for (Iterator<Map.Entry<String, Set<String>>> it = mapModuleTypeToRules.entrySet().iterator(); it.hasNext(); ) {
                Map.Entry<String, Set<String>> e = it.next();
                Set<String> rules = e.getValue();
                if (rules != null && rules.contains(rUID)) {
                    rules.remove(rUID);
                    if (rules.size() < 1) {
                        it.remove();
                    }
                }
            }
        }
        scheduleTasks.remove(rUID);
        return true;
    }
    return false;
}
Also used : Entry(java.util.Map.Entry) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) WrappedRule(org.eclipse.smarthome.automation.core.internal.ruleengine.WrappedRule) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

WrappedRule (org.eclipse.smarthome.automation.core.internal.ruleengine.WrappedRule)7 RuleStatusInfo (org.eclipse.smarthome.automation.RuleStatusInfo)4 RuleStatus (org.eclipse.smarthome.automation.RuleStatus)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1