package sim.engine; /** Wraps a steppable in an easy-to-stop wrapper. This is intended for those rare cases when you feel the need to prevent a scheduled ones-shot Steppable from firing. To do so, wrap the Steppable in a OneShotStoppable, and schedule the OneShotStoppable. Everything will work according to plan unless you call stop(), in which case the Steppable will not be stepped and will instead just drop out of the schedule when its time comes up

If you need to undo the effect of stop(), you can do so with restart(). Note that this does not reschedule the steppable or anything like that: if the Steppable's step() method has already passted, calling restart() does not give it another chance. However, it's reasonable to stop() a Steppable, wait for its step() time to pass, then call restart() and reschedule the OneShotStoppable in the schedule again.

OneShotSchedule is synchronized, so the stop() and step() methods can be called in different threads (from a ParallelSequence, for example).

If you're trying to stop a repeated Steppable, use the Stoppable provided by the schedule instead. */ public class OneShotStoppable { final Steppable step; boolean stopped = false; public OneShotStoppable(Steppable step) { this.step = step; } public synchronized void stop() { stopped = true; } public synchronized void restart() { stopped = false; } public synchronized void step(SimState state) { step.step(state); } }