sim.engine
Class WeakStep
java.lang.Object
sim.engine.WeakStep
- All Implemented Interfaces:
- java.io.Serializable, Steppable
public class WeakStep
- extends java.lang.Object
- implements Steppable
WeakStep is a wrapper for steppable objects in the situation where we only want
the schedule to tenuously hold onto the steppable object -- that is, if everyone
else has forgotten about the object, the schedule should as well. This is commonly
the case for inspectors and other kinds of windows which might be closed by the user
without any way to get back to the schedule and remove themselves.
You schedule a Steppable weakly something like this:
mySchedule.schedule(new WeakStep(mySteppable));
A WeakStep can also wrap a Steppable you plan on scheduling repeating. You'd
do it along these lines:
WeakStep weak = new WeakStep(mySteppable);
Stoppable stop = mySchedule.scheduleRepeating(weak);
weak.setStoppable(stop);
In this case, when the underlying Steppable is garbage-collected, then the
schedule will automatically stop repeatedly stepping it. Note that the Stoppable
is also stored weakly.
- See Also:
- Serialized Form
Field Summary |
protected java.lang.ref.WeakReference |
weakStep
|
protected java.lang.ref.WeakReference |
weakStop
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
weakStep
protected java.lang.ref.WeakReference weakStep
weakStop
protected java.lang.ref.WeakReference weakStop
WeakStep
public WeakStep(Steppable step)
setStoppable
public void setStoppable(Stoppable stop)
step
public void step(SimState state)
- Specified by:
step
in interface Steppable