View Javadoc

1   /*
2    * Copyright (c) 1998-2004 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 java.rmi.AccessException;
22  import java.rmi.NotBoundException;
23  import java.rmi.RemoteException;
24  
25  import jgroup.core.GroupManager;
26  import jgroup.core.JgroupException;
27  import jgroup.core.MembershipListener;
28  import jgroup.core.View;
29  import jgroup.core.registry.LookupService;
30  
31  /**
32   *  Group client program for Hello
33   *
34   *  @author Hein Meling
35   *  @since Jgroup 2.2
36   */
37  public class HelloGroupClient
38    implements MembershipListener
39  {
40  
41    public HelloGroupClient()
42      throws JgroupException, AccessException, RemoteException, NotBoundException
43    {
44      GroupManager gm = GroupManager.getGroupManager(this);
45      LookupService registry = (LookupService) gm.getService(LookupService.class);
46      /*
47       * Retrieve a proxy for an object group implementing the Hello
48       * interface registered under the name "Jgroup/HelloServer".
49       */
50      Hello server = (Hello) registry.lookup("Jgroup/HelloServer");
51      /*
52       * Invoking method sayHello, which returns an object of type Answer
53       * containing a string produced by the contacted object plus
54       * the time at which the groups members installed the last view.
55       */
56      for (int i = 0; i < 20; i++) {
57        Answer answer = server.sayHello();
58        System.out.println(answer);
59      }
60    }
61  
62  
63    public static void main(String argv[])
64      throws Exception
65    {
66      new HelloGroupClient();
67      /*
68       * There may be several threads blocking (e.g., the threads pooling
69       * for registry instances), thus we just exit everything.
70       */
71      System.exit(0);
72    }
73  
74  
75    public void viewChange(View view)
76    {
77      System.out.println(view);
78    }
79  
80    public void prepareChange() { }
81  
82    public void hasLeft() { }
83  
84  } // END HelloGroupClient