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  
19  package jgroup.test.hello;
20  
21  import jgroup.core.registry.DependableRegistry;
22  import jgroup.core.registry.RegistryFactory;
23  
24  /**
25   *  Client program for Hello
26   *
27   *  @author Alberto Montresor
28   *  @author Hein Meling
29   *  @since Jgroup 0.1
30   */
31  public class HelloClient
32  {
33  
34    public static void main(String argv[])
35      throws Exception
36    {
37      /*
38       * Obtain a proxy for the depedable registry running in the
39       * distributed system described in the config.xml file.
40       */
41      DependableRegistry registry = RegistryFactory.getRegistry();
42  
43      /*
44       * Print the number of groups registered in the dependable registry
45       */
46      String[] bindings = registry.list();
47      System.out.println("Number of elements: " + bindings.length);
48  
49      /*
50       * Retrieve a proxy for an object group implementing the Hello
51       * interface registered under the name "Jgroup/HelloServer".
52       */
53      Hello server = (Hello) registry.lookup("Jgroup/HelloServer");
54  
55      /*
56       * Ask all servers to perform the doCompute() method (multicast).
57       */
58      double d = server.doCompute();
59      System.out.println("Server computed: " + d);
60  
61      /*
62       * Invoking method sayHello, which returns an object of type Answer
63       * containing a string produced by the contacted object plus
64       * the time at which the groups members installed the last view.
65       */
66      for (int i = 0; i < 20; i++) {
67        Answer answer = server.sayHello();
68        System.out.println(answer);
69      }
70  
71      d = server.doCompute();
72      System.out.println("Server computed: " + d);
73  
74      /*
75       * There may be several threads blocking (e.g., the threads pooling
76       * for registry instances), thus we just exit everything.
77       */
78      System.exit(0);
79    }
80  
81  } // END HelloClient