/* non-synched version Beaware of the following variables (global within hrserver class): HN = number of horses in race clients = number of clients that has called joinrace (race starts when clients==HN) H = array of horse objects stoprace = stop race when true */ import java.rmi.*; import java.rmi.server.*; public class hrserver extends UnicastRemoteObject implements horserace { private horse[] H; private int HN = 3; //default number of horses private int clients = 0; public int LW = 60; // lane width public int TW = 800; // track length; private boolean stoprace = false; public hrserver(int x) throws RemoteException { super(); HN = x; H = new horse[HN]; } /* -------------------- need fix'in ---------------------- */ public synchronized raceinfo joinrace(String name) throws RemoteException { raceinfo info = null; if (clients >= HN) return null; H[clients] = new horse(true,0,(clients*LW)+LW,name); info = new raceinfo((byte)clients,H); clients++; // need to check if enough horses are ready: this won't work! while (clients TW-68) stoprace = true; } catch (Exception e) {e.printStackTrace();} return new raceinfo((byte)id,H); } public synchronized raceinfo quitrace(int id) throws RemoteException { H[id].inrace = false; clients--; return new raceinfo((byte)id,H); } public static void main(String[] args) // args define HN and orbd host { try { /* System.setProperty("java.security.policy", "server.policy"); System.setSecurityManager( new RMISecurityManager()); */ hrserver server = new hrserver(Integer.parseInt(args[0])); String serverloc="127.0.0.1"; if (args.length>1) serverloc = args[1]; Naming.rebind("//"+serverloc+"/hrserver",server); System.out.println("horserace server started"); } catch (Exception e) {e.printStackTrace();} } // main } // hrserver