import java.util.*; // VamlorRMIImpl - Class which implements the functionality of the // abstract Vamlor RMI class public class VamlorRMIImpl extends java.rmi.server.UnicastRemoteObject implements VamlorRMI { public VamlorRMIImpl() throws java.rmi.RemoteException { super(); } // getIDList - Method that returns the IDs of all alive Vamlors public int [] getIDList() throws java.rmi.RemoteException { DumbBrain brain; // This is the parent class of a Vamlor // The Doit class is the main server class. It holds all data // concerning the Vamlor World. The vTable is a hashtable of the // existing Vamlors int [] list = new int[Doit.vTable.size()]; int i = 0; // Cycle through all entries in the hashtable and add them to the list for (Enumeration e = Doit.vTable.elements() ; e.hasMoreElements() ;) { brain = (DumbBrain)e.nextElement(); // The DumbBrain class class returns a Vamlor ID which in turn // returns an integer value list[i] = brain.getID().id.intValue(); i++; } return (list); } // getState - Method returning state of Vamlor public String getState(int id) throws java.rmi.RemoteException { // This method gets the parent class DumbBrain given a Vamlor id DumbBrain dumb = Doit.getBrainFromVamlor(new Vamlor(id)); if (dumb == null) return null; else { if (dumb.isSleeping()) { return ("Sleeping"); } else if (dumb.getMotion() == DumbBrain.SPEED_RUN) { return ("Running"); } else if (dumb.getMotion() == DumbBrain.SPEED_WALK) { return ("Walking"); } else { return ("Stopped"); } } } // getName - Given ID return Vamlor Name public String getName(int id) throws java.rmi.RemoteException { // This method gets the parent class DumbBrain given a Vamlor id DumbBrain dumb = Doit.getBrainFromVamlor(new Vamlor(id)); if (dumb == null) return null; else { return(dumb.getVamlorName()); } } // getX - Given ID return X location public int getX(int id) throws java.rmi.RemoteException { // This method gets the parent class DumbBrain given a Vamlor id DumbBrain dumb = Doit.getBrainFromVamlor(new Vamlor(id)); if (dumb == null) return 0; else { return(dumb.getPositionX()); } } // getY - Given ID return Y location public int getY(int id) throws java.rmi.RemoteException { // This method gets the parent class DumbBrain given a Vamlor id DumbBrain dumb = Doit.getBrainFromVamlor(new Vamlor(id)); if (dumb == null) return 0; else { return(dumb.getPositionY()); } } // getEnergyLevel - Given ID return Energy Level public int getEnergyLevel(int id) throws java.rmi.RemoteException { // This method gets the parent class DumbBrain given a Vamlor id DumbBrain dumb = Doit.getBrainFromVamlor(new Vamlor(id)); if (dumb == null) return 0; else { return(dumb.getEnergy()); } } // getHealthLevel - Given ID return Health Level public int getHealthLevel(int id) throws java.rmi.RemoteException { // This method gets the parent class DumbBrain given a Vamlor id DumbBrain dumb = Doit.getBrainFromVamlor(new Vamlor(id)); if (dumb == null) return 0; else { return(dumb.getHealth()); } } }