/Users/lyon/j4p/src/graphics/raytracers/rmiRaytracer/raytracer/DoImageClientManager.java

1    package graphics.raytracers.rmiRaytracer.raytracer; 
2     
3    import net.rmi.rmiSynth.Host; 
4    import net.rmi.rmiSynth.HostManager; 
5    import net.rmi.rmiSynth.HostManagerInterface; 
6     
7    import java.rmi.NotBoundException; 
8    import java.rmi.RemoteException; 
9    import java.rmi.registry.LocateRegistry; 
10   import java.rmi.registry.Registry; 
11    
12   /** 
13    *   The DoImageClientManager uses the <code>HostManager</code> 
14    * to find image servers. 
15    */ 
16   public class DoImageClientManager { 
17    
18    
19       public DoImageClientManager() { 
20       } 
21    
22       /** 
23        * 
24        */ 
25       public DoImageInterface getNextProxy() { 
26           //locate the server class on remote machine 
27           Registry r = getNextHostAndLocateRegistry(); 
28           return lookupImageServer(r); 
29    
30       } 
31    
32       private DoImageInterface lookupImageServer(Registry r) { 
33           System.out.println("Registry:\n\t" + r + "\n\t Looking up DoImageInterface"); 
34           Object o = null; 
35           try { 
36               o = r.lookup( 
37                       "DoImageServer"); 
38           } catch (RemoteException e) { 
39               System.out.println("ERROR:DoImageInterface RemoteException on lookup"); 
40               System.exit(0); 
41           } catch (NotBoundException e) { 
42               System.out.println("ERROR:DoImageInterface NotBoundException on lookup"); 
43               System.exit(0); 
44           } 
45           return (DoImageInterface) o; 
46       } 
47    
48       private Registry getNextHostAndLocateRegistry() { 
49           Host h = null; 
50           try { 
51               HostManagerInterface hm = HostManager.getProxy(); 
52               h = hm.getNextHost(); 
53               System.out.println("Got a host:" + h); 
54           } catch (RemoteException e) { 
55               System.out.println("ERROR:DoImageInterface;HostMaster.getNextHost"); 
56               System.exit(0); 
57           } 
58           Registry r = null; 
59           try { 
60               //r = LocateRegistry.getRegistry(h.toString()); 
61               String hs = h.toString(); 
62               String ips = hs.substring(hs.indexOf('/') + 1); 
63               System.out.println("ipstring for registry is:" + h.getIP()); 
64               r = LocateRegistry.getRegistry(h.getIP()); //CHANGE ME! 
65           } catch (RemoteException e) { 
66               System.out.println("ERROR:DoImageInterface;HostMaster.getRegistry"); 
67           } 
68           return r; 
69       } 
70    
71   }