Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "INF 123: Software Architectures, Distributed Systems, and Interoperability Discussion Session Week 8 - Spring 2008 Instructor: Prof. Richard N. Taylor."— 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 Server MachineClient Machine Network edu.uci.inf123 - SpacecraftStateIntf.java - SpacecraftState.java rmiregistry Lunar Lander Code edu.uci.inf123 - ServerRMI.java - SpacecraftStateIntf.java - SpacecraftState.java

5 Implementation: Interface package edu.uci.inf123; import java.rmi.Remote; import java.rmi.RemoteException; import java.util.HashMap; public interface SpacecraftStateIntf extends Remote { SpacecraftState getState(String identifier) throws RemoteException; void setState(String identifier, SpacecraftState state) throws RemoteException; void clearState(String identifier) throws RemoteException; HashMap getStates() throws RemoteException; }

6 Implementation: Spacecraft Status Bean package edu.uci.inf123; public class SpacecraftState implements java.io.Serializable { private static final long serialVersionUID = 1L; double altitude; double velocity; double fuel; public SpacecraftState() { altitude = 0.0; velocity = 0.0; fuel = 0.0; } public void setAltitude(double pAltitude) { altitude = pAltitude; } public double getAltitude() { return altitude; } public void setVelocity(double pVelocity) { velocity = pVelocity; } public double getVelocity() { return velocity; } public void setFuel(double pFuel) { fuel = pFuel; } public double getFuel() { return fuel; }

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; public class ServerRMI implements SpacecraftStateIntf { HashMap states; public ServerRMI() { states = new HashMap (); } public SpacecraftState getState(String identifier) throws RemoteException { return (SpacecraftState)states.get(identifier); } public void clearState(String identifier) throws RemoteException { states.keySet().remove(identifier); } public void setState(String identifier, SpacecraftState state) throws RemoteException { states.put(identifier, state); } public HashMap getStates() throws RemoteException { return states; }

8 Implementation: Server (cont.) public static void 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; public class ClientRMI { private ClientRMI() {} public static void 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(); } private static void printStates(HashMap 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.


Download ppt "INF 123: Software Architectures, Distributed Systems, and Interoperability Discussion Session Week 8 - Spring 2008 Instructor: Prof. Richard N. Taylor."

Similar presentations


Ads by Google