KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.ubik.rmi.examples;
2
3 import org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory;
4 import org.sapia.ubik.rmi.naming.remote.discovery.ServiceDiscoListener;
5 import org.sapia.ubik.rmi.naming.remote.discovery.ServiceDiscoveryEvent;
6 import org.sapia.ubik.rmi.naming.remote.proxy.ReliableLocalContext;
7
8 import java.util.*;
9
10 import javax.naming.*;
11
12
13 /**
14  * @author Yanick Duchesne
15  * <dl>
16  * <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>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class ServiceDiscoListenerEg implements ServiceDiscoListener {
22   /**
23    * Constructor for ServiceDiscoListenerExample.
24    */

25   public ServiceDiscoListenerEg() {
26     super();
27   }
28
29   /**
30    * @see org.sapia.ubik.rmi.naming.remote.discovery.ServiceDiscoListener#onServiceDiscovered(ServiceDiscoveryEvent)
31    */

32   public void onServiceDiscovered(ServiceDiscoveryEvent evt) {
33     System.out.println("Discovered: " + evt);
34   }
35
36   public static void main(String JavaDoc[] args) {
37     System.out.println("Waiting for service discovery. Press CTRL-C to stop.");
38
39     try {
40       Properties props = new Properties();
41       props.setProperty(InitialContext.PROVIDER_URL, "ubik://localhost:1098/");
42       props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,
43         RemoteInitialContextFactory.class.getName());
44
45       InitialContext ctx = new InitialContext(props);
46
47       ServiceDiscoListenerEg sdisco = new ServiceDiscoListenerEg();
48
49       ReliableLocalContext rctx = ReliableLocalContext.currentContext();
50       rctx.addServiceDiscoListener(sdisco);
51
52       while (true) {
53         Thread.sleep(100000);
54       }
55     } catch (Exception JavaDoc e) {
56       e.printStackTrace();
57     }
58   }
59 }
60
Popular Tags