KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > protocols > GmsImpl


1 // $Id: GmsImpl.java,v 1.3 2004/09/23 16:29:41 belaban Exp $
2

3 package org.jgroups.protocols;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.jgroups.*;
8
9 import java.util.Vector JavaDoc;
10
11
12
13 public abstract class GmsImpl {
14     protected GMS gms=null;
15
16     protected final Log log=LogFactory.getLog(getClass());
17
18     public abstract void init(); // initialize variables
19

20     public abstract void join(Address mbr);
21     public abstract void leave(Address mbr);
22     public abstract void suspect(Address mbr);
23     public abstract void merge(Vector JavaDoc coords);
24
25     public abstract boolean handleJoin(Address mbr);
26     public abstract void handleLeave(Address mbr, boolean suspected);
27     public abstract void handleViewChange(ViewId new_view, Vector JavaDoc mbrs);
28     public abstract View handleMerge(ViewId other_view,Vector JavaDoc other_members);
29     public abstract void handleSuspect(Address mbr);
30
31     public boolean handleUpEvent(Event evt) {return true;}
32     public boolean handleDownEvent(Event evt) {return true;}
33
34
35
36
37     protected void wrongMethod(String JavaDoc method_name) {
38     if(log.isErrorEnabled()) log.error("method " + method_name +
39             "() should not be sent to an instance of " + getClass().getName());
40     }
41
42
43
44     /**
45        Returns potential coordinator based on lexicographic ordering of member addresses. Another
46        approach would be to keep track of the primary partition and return the first member if we
47        are the primary partition.
48      */

49     protected boolean iWouldBeCoordinator(Vector JavaDoc new_mbrs) {
50     Membership tmp_mbrs=gms.members.copy();
51     tmp_mbrs.merge(new_mbrs, null);
52     tmp_mbrs.sort();
53     if(tmp_mbrs.size() <= 0 || gms.local_addr == null)
54         return false;
55     return gms.local_addr.equals(tmp_mbrs.elementAt(0));
56     }
57
58 }
59
Popular Tags