/Users/lyon/j4p/src/net/rmi/armi/RmiHelloServer.java

1    package net.rmi.armi; 
2     
3    import net.rmi.utils.RmiRegistryUtils; 
4    import net.rmi.utils.Compile; 
5     
6    import java.rmi.RemoteException; 
7    import java.rmi.registry.Registry; 
8     
9    public class RmiHelloServer { 
10       // before you run this program, 
11       // you must start the rmiregistry 
12       // from the classpath root. 
13       public static void main(String args[]) { 
14           try { 
15               startServer(); 
16           } catch (RemoteException e) { 
17               e.printStackTrace(); 
18           } 
19       } 
20    
21       private static void startServer() 
22               throws RemoteException { 
23           println("starting server"); 
24           Class c = RemoteHelloImplementation.class; 
25           Compile.runRmic(c); 
26           RemoteHelloInterface ro = new RemoteHelloImplementation(); 
27    
28           bindInstances(ro); 
29       } 
30    
31       private static void bindInstances(RemoteHelloInterface ro) throws RemoteException { 
32           println("binding remote instances"); 
33           // We don't need Naming anymore... 
34           //Naming.rebind("RemoteHello",ro); 
35           Registry r = RmiRegistryUtils.getRegistry(); 
36           r.rebind("RemoteHello", ro); 
37           println("waiting for invocations"); 
38       } 
39    
40       public static void println(Object o) { 
41           System.out.println(o); 
42       } 
43   } 
44