Java Reference
In-Depth Information
public class
Runner
extends
DActivity
implements
RunnerInterface {
. . .
// every "delay" milliseconds the runner moves forward to
// the next cell and notifies the remote observers the new
// position
public void
step() {
try
{
. . .
this
.notifyObservers(
new
DEvent("NEXT",
this
.getURL(),
new
Integer(currentPosition)));
}
catch
(InterruptedException ie) { ie.printStackTrace(); }
}
}
public interface
AnimatorInterface
extends
DObserver {}
public class
Animator
extends
DActivity
implements
AnimatorInterface {
private
Object lock
#
new
Object();
private
DEvent lastEvent
#
null
;
. . .
public void
init() {
try
{
// gets a reference to the remote activity and
// subscribes to event "NEXT"
runnerURL
#
((Client) process).
server.startRunner(path);
runner
#
(RunnerInterface) Naming.lookup(runnerURL);
runner.addObserver(
this
.getURL(), "NEXT");
}
catch
(Exception e) { e.printStackTrace(); }
}
public void
update(DEvent event){
lastEvent
#
event;
synchronized
(lock) {
// notifies activities that have invoked the
// waitEvent() method
lock.notify();
}
}
public void
step() {
try
{ // sleeps until the new position is notified
synchronized
(lock) {
lock.wait();
}
pathFrame.setPosition(((Integer)lastEvent.value).
intValue());