Commit 3fe40487 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Sanity checks in the PeriodicOperation

- isStopped is true, if the OP is not yet started
parent 560ff1d8
......@@ -32,7 +32,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
public abstract class PeriodicOperation<T extends HostComponent, R> extends
AbstractOperation<T, R> {
private boolean stopped = false;
private boolean stopped = true;
private Distribution intervalDist;
......@@ -157,6 +157,10 @@ public abstract class PeriodicOperation<T extends HostComponent, R> extends
* Same functionality like scheduleImmediately
*/
public void start() {
if (!isStopped()) {
throw new AssertionError(
"Periodic Operation already running - ignoring start()!");
}
this.scheduleImmediately();
}
......@@ -167,6 +171,10 @@ public abstract class PeriodicOperation<T extends HostComponent, R> extends
* The delay for the first execution
*/
public void startWithDelay(long delay) {
if (!isStopped()) {
throw new AssertionError(
"Periodic Operation already running - ignoring start()!");
}
this.scheduleWithDelay(delay);
}
......@@ -176,12 +184,12 @@ public abstract class PeriodicOperation<T extends HostComponent, R> extends
super.scheduleWithDelay(delay);
}
@Override
public void scheduleImmediately() {
this.stopped = false;
super.scheduleImmediately();
}
/**
* True, if the operation is currently stopped or was not yet scheduled to
* start.
*
* @return
*/
public boolean isStopped() {
return stopped;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment