“The Network is the Computer”The Client Passes HardWork to a Remote ObjectHardWork implements TaskAll Tasks Have An Execute MethodComputeEngines implement ComputeThe Remote ComputeEngineSlide 7This all depends on…95-702 OCT 1“The Network is the Computer”Advanced RMI orPassing Behavior95-702 OCT 2The Client Passes HardWork to a Remote Objectimport java.rmi.*;import java.math.*;public class ComputeClient { public static void main(String args[]) { if(System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } try { String name = "//localhost/Compute"; Compute comp = (Compute) Naming.lookup(name); HardWork task = new HardWork(); BigInteger bi = (BigInteger) (comp.executeTask(task)); System.out.println("The result is " + bi); } catch(Exception e) { e.printStackTrace(); }}}95-702 OCT 3HardWork implements Taskimport java.math.*;public class HardWork implements Task { public Object execute() { BigInteger sum = new BigInteger(""+0); for(int j = 0; j < 1000; j++ ) { BigInteger x = new BigInteger(""+j); sum.add(x); } return sum; }}95-702 OCT 4All Tasks Have An Execute Methodimport java.io.Serializable;public interface Task extends Serializable { Object execute();}95-702 OCT 5ComputeEngines implement Computeimport java.rmi.Remote;import java.rmi.RemoteException;public interface Compute extends Remote { Object executeTask(Task t) throws RemoteException;}95-702 OCT 6The Remote ComputeEngineimport java.rmi.*;import java.rmi.server.*;public class ComputeEngine extends UnicastRemoteObject implements Compute { public ComputeEngine() throws RemoteException { super(); } public Object executeTask(Task t) { return t.execute(); }95-702 OCT 7public static void main(String[] args) { if(System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } String name = "//localhost/Compute"; try { Compute engine = new ComputeEngine(); Naming.rebind(name,engine); System.out.println("ComputeEngine bound"); } catch(Exception e) { System.out.println("exception thrown"); e.printStackTrace(); } }}95-702 OCT 8This all depends on…•Java’s ability to download class files via a codebase (see reading on schedule)•The downloaded class behaving itself (security manager and
View Full Document