1 package org.sapia.ubik.rmi.examples; 2 3 import org.sapia.ubik.rmi.naming.remote.JNDIServer; 4 import org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory; 5 import org.sapia.ubik.rmi.naming.remote.discovery.ServiceDiscoListener; 6 import org.sapia.ubik.rmi.naming.remote.discovery.ServiceDiscoveryEvent; 7 import org.sapia.ubik.rmi.naming.remote.proxy.ReliableLocalContext; 8 import org.sapia.ubik.rmi.server.Log; 9 import org.sapia.ubik.rmi.server.Stateless; 10 11 import java.rmi.RemoteException ; 12 13 import java.util.Properties ; 14 15 import javax.naming.*; 16 17 18 26 public class ColocatedStatelessFoo implements Foo, Stateless, 27 ServiceDiscoListener { 28 public ColocatedStatelessFoo() throws java.rmi.RemoteException { 29 } 30 31 34 public Bar getBar() throws RemoteException { 35 return new UbikBar(); 36 } 37 38 41 public void onServiceDiscovered(ServiceDiscoveryEvent evt) { 42 System.out.println("Discovered : " + evt); 43 } 44 45 public static void main(String [] args) { 46 try { 47 Log.setWarning(); 48 49 Thread t = new Thread () { 50 public void run() { 51 JNDIServer.main(new String [] { }); 52 } 53 }; 54 55 t.start(); 56 Thread.sleep(2000); 57 58 Properties props = new Properties (); 60 props.setProperty(InitialContext.PROVIDER_URL, "ubik://localhost:1099/"); 61 props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, 62 RemoteInitialContextFactory.class.getName()); 63 64 InitialContext ctx = new InitialContext(props); 65 66 ReliableLocalContext.currentContext().addServiceDiscoListener(new ColocatedStatelessFoo()); 67 68 ctx.rebind("Foo", new ColocatedStatelessFoo()); 69 70 System.out.println("StatelessFoo started..."); 71 72 while (true) { 73 Thread.sleep(10000); 74 } 75 } catch (Throwable t) { 76 t.printStackTrace(); 77 } 78 } 79 } 80 | Popular Tags |