Java Reference
In-Depth Information
public class
Runner
extends
DActivity
implements
RunnerInterface {
private int
path[];
// the set of lay-bys on the runner's track
private long
delay; // one step's duration
private long
maxDelay
#
1000;
// one step's maximum duration
private int
currentPosition
#
0;
private int
currentStep
#
0;
public
Runner(DProcess server,
int
path[])
throws
java.rmi.RemoteException {
super
(server);
this
.path
#
path;
this
.delay
#
maxDelay;
}
// every "delay" milliseconds the runner moves to the next
// cell
public void
step() {
try
{
Thread.sleep(delay);
((Server) process).next(
this
.getURL(),
path[currentStep]);
currentPosition
#
path[currentStep];
currentStep
!!
;
if
(currentStep
##
path.length) currentStep
#
0;
}
catch
(InterruptedException ie) { ie.printStackTrace(); }
}
// sets the duration of a transition between two cells
public void
setSpeed(
int
percent)
throws
java.rmi.RemoteException {
this
.delay
#
maxDelay - 80 * percent;
}
// returns the ID of the cell currently occupied by the
// runner
public int
getPosition()
throws
java.rmi.RemoteException {
return
currentPosition;
}
}
package
jogging.client;
import
mmi.*;
import
jogging.server.*;
public interface
ClientInterface
extends
java.rmi.Remote {}
public class
Client
extends
DProcess
implements
ClientInterface {
public
ServerInterface server;
// reference to the remote server