KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > examples > ColocatedStatelessFoo


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 JavaDoc;
12
13 import java.util.Properties JavaDoc;
14
15 import javax.naming.*;
16
17
18 /**
19  * @author Yanick Duchesne
20  * <dl>
21  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
22  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
23  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
24  * </dl>
25  */

26 public class ColocatedStatelessFoo implements Foo, Stateless,
27   ServiceDiscoListener {
28   public ColocatedStatelessFoo() throws java.rmi.RemoteException JavaDoc {
29   }
30
31   /**
32    * @see org.sapia.ubik.rmi.Foo#getBar()
33    */

34   public Bar getBar() throws RemoteException JavaDoc {
35     return new UbikBar();
36   }
37
38   /**
39    * @see org.sapia.ubik.rmi.naming.remote.discovery.ServiceDiscoListener#onServiceDiscovered(ServiceDiscoveryEvent)
40    */

41   public void onServiceDiscovered(ServiceDiscoveryEvent evt) {
42     System.out.println("Discovered : " + evt);
43   }
44
45   public static void main(String JavaDoc[] args) {
46     try {
47       Log.setWarning();
48
49       Thread JavaDoc t = new Thread JavaDoc() {
50           public void run() {
51             JNDIServer.main(new String JavaDoc[] { });
52           }
53         };
54
55       t.start();
56       Thread.sleep(2000);
57
58       //PerfAnalyzer.getInstance().setEnabled(true);
59
Properties JavaDoc props = new Properties JavaDoc();
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 JavaDoc t) {
76       t.printStackTrace();
77     }
78   }
79 }
80
Popular Tags