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 java.io.Externalizable;
22  
23  /**
24   *  The Partitionable Group Membership Service contained in Jgroup
25   *  tracks changes in the group's composition and installs them as views
26   *  at member objects.  Installated views are an abstraction of the
27   *  current environment with respect to failures and recoveries.  Member
28   *  objects can obtain information about the current view through the
29   *  <code>View</code> interface.  Each view is uniquely identified by a
30   *  view identifier, that can be obtained by invoking method
31   *  <code>getVid</code>.  The composition of the view may be obtained by
32   *  invoking method <code>getMembers</code>.
33   *
34   *  @author Alberto Montresor
35   *  @author Hein Meling
36   *  @since Jgroup 0.1
37   */
38  public interface View
39    extends Externalizable, Cloneable
40  {
41  
42    /**
43     *  Returns the identifier of the group for which this view has been
44     *  generated.
45     */
46    public int getGid();
47  
48    /**
49     *  Returns the identifier of this view.
50     */
51    public long getVid();
52  
53    /**
54     *  Returns the number of views (or partitions) merging into this view.
55     */
56    public int mergingViews();
57  
58    /**
59     *  Returns an array of <code>MemberId</code>s identifying the members
60     *  included in this view.
61     */
62    public MemberId[] getMembers();
63  
64    /**
65     *  Return the <code>MemberId</code> of the group leader (member in
66     *  position 0).
67     */
68    public MemberId getLeader();
69  
70    /**
71     *  Returns true if the given member is the group leader.
72     */
73    public boolean isLeader(MemberId member);
74  
75    /**
76     *  Returns an array of <code>MemberId</code>s that are common to this
77     *  view and the provided member array.
78     */
79    public MemberId[] commonMembers(MemberId[] members);
80  
81    /**
82     *  Returns an array of <code>MemberId</code>s that are common to this
83     *  view and the provided view.
84     */
85    public MemberId[] commonMembers(View view);
86  
87    /**
88     *  Returns an array of <code>MemberId</code>s that are new to this
89     *  view; that is they were not in the previous view.
90     */
91    public MemberId[] newMembers(View previousView);
92  
93    /**
94     *  Returns an array of <code>MemberId</code>s that are not longer
95     *  part of this view; that is they were members of the previous view
96     *  but are no longer members of the this view.
97     */
98    public MemberId[] oldMembers(View previousView);
99  
100   /**
101    *  Returns true if the given member is contained in the current view.
102    *  Otherwise, false is returned.
103    */
104   public boolean contains(MemberId memberId);
105 
106   /**
107    *  Returns true if this view contains all members of the provided view.
108    *  False is returned otherwise. <p>
109    *
110    *  This is useful for checking if a new view is a contraction of the
111    *  previous view, or if there are new members.
112    */
113   public boolean containsAll(View view);
114 
115   /**
116    * Returns true if this view has exactly the same members are the provided
117    * view.  False is returned otherwise. <p>
118    * 
119    * Note that this is different from using <code>Object.equals()</code>, since
120    * this method will not check that the view identifiers are the same.
121    */
122   public boolean hasSameMembers(View prevView);
123 
124   /**
125    *  Returns the number of members in this view.
126    */
127   public int size();
128 
129   /**
130    * Returns the position of the given member in this view.  If the member
131    * is not in this view, a negative value is returned.
132    */
133   public int getMemberPosition(MemberId id);
134 
135   /**
136    *  Returns true if the specified member is the member at the given
137    *  position; otherwise false is returned.
138    *
139    *  @param pos
140    *    The position in the view to check for equality with the given
141    *    member.  A negative position value is considered to indicate
142    *    a position from the end of the view array, while a positive
143    *    value indicate a position from the beginning of the view
144    *    array.  A position value outside the range of the view, will
145    *    always return false.
146    *  @param member
147    *    The member whose position to check.
148    *  @return 
149    *    True if the given member is at the specified position in this
150    *    view; false otherwise.
151    */
152   public boolean memberHasPosition(int pos, MemberId member);
153   
154   public Object clone();
155 
156 } // END View