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.core;
20  
21  import jgroup.core.Layer.FinalizeLayer;
22  
23  /**
24   *  The facilities provided by the group membership service included in
25   *  Jgroup may be accessed using the <code>MembershipService</code>
26   *  interface.  Methods in this interfaces enable objects to become
27   *  members of a group and subsequentially leave it. <p>
28   *
29   *  Instances of <code>MembershipService</code> may be obtained through
30   *  the <code>GroupManager</code> class.
31   *
32   *  @author Alberto Montresor
33   *  @author Hein Meling
34   *  @since Jgroup 0.1 (Revised Jgroup 2.2)
35   *  @see jgroup.core.GroupManager
36   */
37  public interface MembershipService
38    extends Layer, FinalizeLayer
39  {
40  
41    /**
42     *  Requests to join a group identified by <code>groupId</code>.  <p>
43     *
44     *  @param groupId
45     *    Non-negative integer identifying the group.
46     *  @exception IllegalArgumentException
47     *    Raised if <code>groupId</code> is negative.
48     *  @exception JgroupException
49     *    Raised if the membership service receives a request to join a
50     *    group to which it is already a member.
51     */
52    public void join(int groupId)
53      throws JgroupException;
54  
55  
56    /**
57     *  Requests to join the default group associated with the Jgroup daemon. <p>
58     *
59     *  Each Jgroup daemon has a default group.  If a Jgroup daemon does not need
60     *  to be shared by multiple groups, the application servers may simply join
61     *  the default group without having to specify group identifiers.
62     *
63     *  @exception JgroupException
64     *    Raised if the membership service receives a request to join a
65     *    group to which it is already a member.
66     */
67    public void join()
68      throws JgroupException;
69  
70  
71    /**
72     *  Request to leave a group.  Note that an object member may receive
73     *  event notifications such as view installations for a group even
74     *  after having requested to leave the group itself.  However, the
75     *  member will eventually leave the group.  When this happens, its
76     *  <code>hasLeft</code> method is invoked.  After this invocation,
77     *  the member will not receive any further event notification related
78     *  to the group.
79     *
80     *  @exception JgroupException
81     *    Rasied if the server is not member of any group, or is already
82     *    leaving its current group.
83     */
84    public void leave()
85      throws JgroupException;
86  
87  
88    /**
89     *  Returns true if the <code>GroupManager</code> is member of some
90     *  group.  Otherwise, false is returned.
91     */
92    public boolean isMember();
93  
94  
95    /**
96     *  Returns true if the <code>GroupManager</code> is in the process of
97     *  joining some group.  Otherwise, false is returned.
98     */
99    public boolean isJoining();
100 
101 
102   /**
103    *  Returns true if the <code>GroupManager</code> is member of some group
104    *  or is in the process of joining some group.  Otherwise, false is returned.
105    */
106   public boolean isMemberOrJoining();
107 
108 
109   /**
110    * Returns true if the local member is the group leader.
111    */
112   public boolean isLeader();
113 
114 
115   /**
116    *  Returns the member identifier of the local member.
117    */
118   public MemberId getMyIdentifier();
119 
120 
121   /**
122    *  Returns the group identifier.
123    */
124   public int getGid();
125 
126 
127   /**
128    *  Returns a <code>MemberTable</code> helper object that will be
129    *  notified of changes in the membership.  This is used to provide
130    *  application developers with additional information about members
131    *  of their current view.
132    */
133   public MemberTable getMemberTable();
134 
135 
136   /**
137    *  Return the number of members of this group.
138    */
139   public int members();
140 
141 
142   /**
143    *  Position index of this member in the array containing
144    *  the members of the current view.
145    */
146   public int getViewIndex();
147 
148 
149   /**
150    *  Position index of this member in the array containing 
151    *  the local members of the current view.
152    */
153   public int getMemberIndex();
154 
155 } // END MembershipService