View Javadoc

1   /*
2    * Copyright (c) 1998-2002 The Jgroup Team.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser General Public License version 2 as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Lesser General Public License for more details.
12   *
13   * You should have received a copy of the GNU Lesser General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16   */
17  
18  package jgroup.test.performance;
19  
20  import jgroup.core.registry.DependableRegistry;
21  import jgroup.core.registry.RegistryFactory;
22  import jgroup.relacs.daemon.Daemon;
23  import jgroup.relacs.daemon.DaemonService;
24  
25  /**
26   * a very simple client of a dependable registry. It shows the contents of the
27   * registry and quits.
28   * 
29   * @author Marcin Solarski
30   * @since Jgroup 2.1
31   * 
32   *  
33   */
34  public class RegistryClient
35  {
36  
37    public static void main(String[] args)
38    {
39  
40      DependableRegistry reg = null;
41      try {
42        reg = RegistryFactory.getRegistry();
43      } catch (Exception e) {
44        System.err.println("Error when contacting the registry");
45        System.exit(1);
46      }
47  
48      String names[] = null;
49  
50      try {
51        names = reg.list();
52      } catch (Exception e) {
53        System.err.println("Error when listening  the registry");
54        System.exit(1);
55      }
56  
57      System.out.println("Entries in the Registry");
58      for (int i = 0; i < names.length; i++) {
59        System.out.println("[" + i + "]: " + names[i]);
60      }
61      System.out.println("=========");
62  
63      try {
64        DaemonService daemonService = Daemon.createDaemon(null);
65        System.out.println("Daemon found in bootstrap registry ");
66      } catch (Exception e) {
67        System.err.println("Error when looking up the local daemon in the registry");
68        e.printStackTrace();
69        System.exit(1);
70      }
71  
72    }
73  }