[New] Added ExecutionPolicy.delay(Duration, Runnable)

This commit is contained in:
Robert von Burg 2020-12-03 18:22:58 +01:00
parent d2c3bd8c8f
commit 3727bdca70
3 changed files with 28 additions and 0 deletions

View File

@ -14,6 +14,16 @@ import li.strolch.model.activity.Action;
*/
public interface DelayedExecutionTimer {
/**
* Delays the execution of the given {@link Runnable} by the given milliseconds
*
* @param duration
* the duration in milliseconds before calling the {@link Runnable}
* @param runnable
* the action to call after the given delay
*/
void delay(long duration, Runnable runnable);
/**
* Completes the execution of the given {@link Action} {@link Locator} after the given duration in milliseconds
*

View File

@ -48,6 +48,11 @@ public class SimpleDurationExecutionTimer implements DelayedExecutionTimer {
}
}
@Override
public void delay(long duration, Runnable runnable) {
getExecutor().schedule(runnable, duration, TimeUnit.MILLISECONDS);
}
@Override
public void execute(String realm, ComponentContainer container, Locator actionLocator, long duration) {
synchronized (this.simulationTasks) {

View File

@ -197,6 +197,19 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
logger.info(msg);
}
/**
* Delays the given {@link Runnable} by the given {@link Duration}
*
* @param duration
* the duration to delay
* @param runnable
* the action to delay
*/
public void delay(Duration duration, Runnable runnable) {
long delayMs = duration.toMillis();
getDelayedExecutionTimer().delay(delayMs, runnable);
}
/**
* Method to delay toExecuted() call for this action by the given duration
*