Java Reference
In-Depth Information
public class Server extends DProcess
implements ServerInterface{
private String cells[] # {"", "", "", "", "", "", "", ""};
public Server(String address, String name)
hrows java.rmi.RemoteException {
super (address, name);
}
// moves the position of runner "id" to the cell number
// "pos" when it is empty
public synchronized void next(String id, int pos) {
try {
while (! cells[pos].equals(""))
wait(); // the cell is not empty
for ( int i # 0; i<cells.length; i !! )
if (cells[i].equals(id)) {
cells[i] # "";
break ;
}
cells[pos] # id;
notifyAll(); // wakes up the activities moving toward
// this cell
} catch (InterruptedException ie) {}
}
// overrides method stopActivity in class DProcess
public void stopActivity(String activityURL) {
super .stopActivity(activityURL);
// removes from path the id of activity
for ( int i # 0; i < cells.length; i !! )
if (cells[i].equals(activityURL)) {
cells[i] # "";
break ;
}
}
public String startRunner( int path[])
throws java.rmi.RemoteException{
return startActivity( new Runner(this, path));
}
public void stopRunner(String activityURL)
throws java.rmi.RemoteException {
stopActivity(activityURL);
}
public interface RunnerInterface
extends java.rmi.Remote {
public void setSpeed( int percent)
throws java.rmi.RemoteException;
public int getPosition()
throws java.rmi.RemoteException;
}
Search WWH ::




Custom Search