1 / 15

INF 123: Software Architectures, Distributed Systems, and Interoperability

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.

dchacon
Download Presentation

INF 123: Software Architectures, Distributed Systems, and Interoperability

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INF 123: Software Architectures, Distributed Systems, and Interoperability Discussion Session Week 8 - Spring 2008 Instructor: Prof. Richard N. Taylor TA: Rosalva Gallardo

  2. Overview • Comments about Assignment 2 • Assignment 3 • Lunar Lander Game Server (RMI)

  3. Assignment 3 • Assignment 3 and the Discussion’s Slides for Week 7 and 8 are in eee. • Assignment 3 Discussion

  4. 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

  5. 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; }

  6. 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; } }

  7. 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; }

  8. 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(); } } }

  9. 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());

  10. 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()); } } }

  11. Output of RMI Client

  12. 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

  13. 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.

  14. 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.

  15. 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.

More Related