150 likes | 168 Views
INF 123: Software Architectures, Distributed Systems, and Interoperability. Discussion Session Week 8 - Spring 2008 Instructor: Prof. Richard N. Taylor TA: Rosalva Gallardo. Overview. Comments about Assignment 2 Assignment 3 Lunar Lander Game Server (RMI). Assignment 3.
E N D
INF 123: Software Architectures, Distributed Systems, and Interoperability Discussion Session Week 8 - Spring 2008 Instructor: Prof. Richard N. Taylor TA: Rosalva Gallardo
Overview • Comments about Assignment 2 • Assignment 3 • Lunar Lander Game Server (RMI)
Assignment 3 • Assignment 3 and the Discussion’s Slides for Week 7 and 8 are in eee. • Assignment 3 Discussion
Deployment Client Machine Server Machine Lunar Lander Code rmiregistry Network edu.uci.inf123 - ServerRMI.java - SpacecraftStateIntf.java - SpacecraftState.java edu.uci.inf123 - SpacecraftStateIntf.java - SpacecraftState.java
Implementation: Interface package edu.uci.inf123; import java.rmi.Remote; import java.rmi.RemoteException; import java.util.HashMap; publicinterface SpacecraftStateIntf extends Remote { SpacecraftState getState(String identifier) throws RemoteException; void setState(String identifier, SpacecraftState state) throws RemoteException; void clearState(String identifier) throws RemoteException; HashMap<String, SpacecraftState> getStates() throws RemoteException; }
Implementation: Spacecraft Status Bean package edu.uci.inf123; publicclass SpacecraftState implements java.io.Serializable { privatestaticfinallongserialVersionUID = 1L; doublealtitude; doublevelocity; doublefuel; public SpacecraftState() { altitude = 0.0; velocity = 0.0; fuel = 0.0; } publicvoid setAltitude(double pAltitude) { altitude = pAltitude; } publicdouble getAltitude() { returnaltitude; } publicvoid setVelocity(double pVelocity) { velocity = pVelocity; } publicdouble getVelocity() { returnvelocity; } publicvoid setFuel(double pFuel) { fuel = pFuel; } publicdouble getFuel() { returnfuel; } }
Implementation: Server package edu.uci.inf123; import java.rmi.registry.Registry; import java.rmi.registry.LocateRegistry; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import java.util.HashMap; publicclass ServerRMI implements SpacecraftStateIntf { HashMap<String, SpacecraftState> states; public ServerRMI() { states = new HashMap<String, SpacecraftState>(); } public SpacecraftState getState(String identifier) throws RemoteException { return (SpacecraftState)states.get(identifier); } publicvoid clearState(String identifier) throws RemoteException { states.keySet().remove(identifier); } publicvoid setState(String identifier, SpacecraftState state) throws RemoteException { states.put(identifier, state); } public HashMap<String, SpacecraftState> getStates() throws RemoteException { returnstates; }
Implementation: Server (cont.) publicstaticvoid main(String args[]) { try { ServerRMI obj = new ServerRMI(); SpacecraftStateIntf stub = (SpacecraftStateIntf) UnicastRemoteObject.exportObject(obj, 0); // Bind the remote object's stub in the registry System.setProperty("java.rmi.server.hostname", "tps.ics.uci.edu"); Registry registry = LocateRegistry.getRegistry(); registry.bind("SpacecraftStates", stub); System.err.println("Server ready"); } catch (Exception e) { System.err.println("Server exception: " + e.toString()); e.printStackTrace(); } } }
Implementation: RMI Client package edu.uci.inf123; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.util.HashMap; import java.util.Iterator; publicclass ClientRMI { private ClientRMI() {} publicstaticvoid main(String[] args) { String host = "tps.ics.uci.edu"; try { Registry registry = LocateRegistry.getRegistry(host); SpacecraftStateIntf stub = (SpacecraftStateIntf) registry.lookup("SpacecraftStates"); SpacecraftState ss1, ss2; ss1 = new SpacecraftState(); ss1.setVelocity(25.00); System.out.println(”\nCurrent States:"); printStates(stub.getStates()); System.out.println("\nState set for rgallard_MyLL"); stub.setState("rgallard_MyLL", ss1); System.out.println("\nCurrent States:"); printStates(stub.getStates());
Implementation: RMI Client ss1.setVelocity(100.00); System.out.println("\nState set for rgallard_MyLL"); stub.setState("rgallard_MyLL", ss1); System.out.println("\nCurrent States:"); printStates(stub.getStates()); System.out.println("\nState get for rgallard_MyLL"); ss2 = stub.getState("rgallard_MyLL"); System.out.println("\nCurrent States:"); printStates(stub.getStates()); System.out.println("\nState cleared for rgallard_MyLL"); stub.clearState("rgallard_MyLL"); System.out.println("\nCurrent States:"); printStates(stub.getStates()); } catch (Exception e) { System.err.println("Exception: " + e.toString()); e.printStackTrace(); } } privatestaticvoid printStates(HashMap<String, SpacecraftState> states) { Iterator iterator = states.keySet().iterator(); while(iterator. hasNext()) { String key = (String)iterator.next(); SpacecraftState value = (SpacecraftState)states.get(key); System.out.println("Key: " + key + " Values: alt=" + value.getAltitude() + ", vel=" + value.getVelocity() + ", fue=" + value.getFuel()); } } }
Important Considerations • For the name of the Local Spacecraft and Remote Spacecraft you should use the following pattern: • #uciNetID_NameYouLike • Ex: rgallard_Ariadne • Make sure you will clean the state of your Local Spacecraft when your game finishes. If it is necessary run the ClientRMI to clean the states you create during your tests
Important Considerations • Make sure you press “Return” after you enter the value in the text fields in the Lunar Lander Launcher menu. If you only use your mouse the value of the text fields will be null. Be careful. You are welcome to change the implementation to improve this, but this is not required.
Important Considerations • Testing options: • Using one machine: • Test your application with the name for the Local Spacecraft and Remote Spacecraft being the same. • Test your application using two different installations of Eclipse. • Test your application using two different machines. You can ask for help to your classmates.
Important Considerations • If you choose to test using two different installations of Eclipse. Make sure that you have the following in your new Eclipse installation: • SubEclipse Plug-in • ArchStudio Plug-in • Check out source code of Myx.fw • Check out your source code of LL from your SVN repository. If you see error makes sure the installation of the OpenGL libraries is correct.