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

1    //Created automatically by CentiJ 
2    package graphics.raytracers.rmiRaytracer.raytracer; 
3     
4    import net.rmi.rmiSynth.Host; 
5    import net.rmi.rmiSynth.HostManager; 
6    import net.rmi.rmiSynth.HostManagerInterface; 
7     
8    import java.awt.*; 
9    import java.rmi.AlreadyBoundException; 
10   import java.rmi.RMISecurityManager; 
11   import java.rmi.RemoteException; 
12   import java.rmi.registry.LocateRegistry; 
13   import java.rmi.registry.Registry; 
14    
15   /** 
16    *  Launch <code>DoImageServer</code> <em>after</em> 
17    * a launch of the <code>DoImageClientManager</code>. 
18    * The DoImageServer must contact the HostManager to register itself 
19    * as available for use. 
20    */ 
21   public class DoImageServer 
22           extends java.rmi.server.UnicastRemoteObject 
23           implements DoImageInterface { 
24    
25       private graphics.raytracers.rmiRaytracer.raytracer.DoImage v = null; 
26    
27    
28       public DoImageServer(Dimension d) 
29               throws java.rmi.RemoteException { 
30           super(); 
31           v = new graphics.raytracers.rmiRaytracer.raytracer.DoImage(d); 
32           registerWithTheHostMaster(); 
33       } 
34    
35       private void registerWithTheHostMaster() throws RemoteException { 
36           System.out.println("getting proxy..."); 
37           HostManagerInterface hm = 
38                   HostManager.getProxy(); 
39           System.out.println("contacting HostManager..."); 
40           Host h = new Host(); 
41           System.out.println("Adding new host:" + h); 
42           hm.add(h); 
43       } 
44    
45       public int[][] int2SubInt(int i[][]) 
46               throws java.rmi.RemoteException { 
47           return v.int2SubInt(i); 
48       } 
49    
50       public int[][] getSubPixels() 
51               throws java.rmi.RemoteException { 
52           return v.getSubPixels(); 
53       } 
54    
55    
56       public void doTheWork() 
57               throws java.rmi.RemoteException { 
58           v.doTheWork(); 
59       } 
60    
61       public void setBand(java.awt.Dimension p0) throws java.rmi.RemoteException { 
62           v.setBand(p0); 
63       } 
64    
65       public int[][] getPixels() throws java.rmi.RemoteException { 
66           return v.getPixels(); 
67       } 
68    
69       public java.awt.Dimension getSize() throws java.rmi.RemoteException { 
70           return v.getSize(); 
71       } 
72    
73       public void setSize(Dimension d) throws java.rmi.RemoteException { 
74           v.setSize(d); 
75       } 
76    
77       public static void main(String args[]) { 
78           try { 
79               createRegistryIfNeeded(); 
80    
81               bindToRegistry(); 
82           } catch (Exception e) { 
83               e.printStackTrace(); 
84           } 
85    
86       } 
87    
88       private static void createRegistryIfNeeded() { 
89           try { 
90               // Create and install a security manager 
91               System.setSecurityManager(new RMISecurityManager()); 
92    
93               //Create the registry and bind the Server class to the registry 
94               LocateRegistry.createRegistry(1099); 
95           } catch (RemoteException e) { 
96               System.out.println("DoImageServer: port 1099 Registry detected"); 
97           } 
98       } 
99    
100      private static void bindToRegistry() throws RemoteException, AlreadyBoundException { 
101          DoImageServer rs = new DoImageServer(new Dimension(200, 200)); 
102          Registry r = LocateRegistry.getRegistry(); 
103          r.bind("DoImageServer", rs); 
104          System.out.println("DoImageServer is bound and running"); 
105      } 
106   
107  }