[Fix] Ignore duplicate calls in SimpleDurationExecutionTimer for same Locator
This commit is contained in:
parent
89b3612c03
commit
34d53d5d56
|
@ -1,5 +1,6 @@
|
||||||
package li.strolch.execution;
|
package li.strolch.execution;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
@ -22,7 +23,7 @@ public class SimpleDurationExecutionTimer implements DelayedExecutionTimer {
|
||||||
|
|
||||||
public SimpleDurationExecutionTimer(StrolchAgent agent) {
|
public SimpleDurationExecutionTimer(StrolchAgent agent) {
|
||||||
this.agent = agent;
|
this.agent = agent;
|
||||||
this.simulationTasks = new HashMap<>();
|
this.simulationTasks = Collections.synchronizedMap(new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,10 +43,16 @@ public class SimpleDurationExecutionTimer implements DelayedExecutionTimer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(String realm, ComponentContainer container, Locator actionLocator, long duration) {
|
public void execute(String realm, ComponentContainer container, Locator actionLocator, long duration) {
|
||||||
SimulationTask task = new SimulationTask(realm, container, actionLocator);
|
synchronized (this.simulationTasks) {
|
||||||
ScheduledFuture<?> future = getExecutor().schedule(task, duration, TimeUnit.MILLISECONDS);
|
if (this.simulationTasks.containsKey(actionLocator)) {
|
||||||
this.simulationTasks.put(actionLocator, future);
|
logger.warn("Ignoring duplicate timer for locator " + actionLocator);
|
||||||
logger.info("Registered execution timer for " + actionLocator);
|
} else {
|
||||||
|
SimulationTask task = new SimulationTask(realm, container, actionLocator);
|
||||||
|
ScheduledFuture<?> future = getExecutor().schedule(task, duration, TimeUnit.MILLISECONDS);
|
||||||
|
this.simulationTasks.put(actionLocator, future);
|
||||||
|
logger.info("Registered execution timer for " + actionLocator);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledExecutorService getExecutor() {
|
private ScheduledExecutorService getExecutor() {
|
||||||
|
@ -56,6 +63,7 @@ public class SimpleDurationExecutionTimer implements DelayedExecutionTimer {
|
||||||
|
|
||||||
logger.info("Completing execution for " + locator);
|
logger.info("Completing execution for " + locator);
|
||||||
|
|
||||||
|
this.simulationTasks.remove(locator);
|
||||||
ExecutionHandler executionHandler = container.getComponent(ExecutionHandler.class);
|
ExecutionHandler executionHandler = container.getComponent(ExecutionHandler.class);
|
||||||
executionHandler.toExecuted(realm, locator);
|
executionHandler.toExecuted(realm, locator);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue