KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id: GmsImpl.java,v 1.6 2004/10/05 15:30:06 belaban Exp $
2

3 package org.jgroups.protocols.pbcast;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.jgroups.Address;
8 import org.jgroups.Event;
9 import org.jgroups.Membership;
10 import org.jgroups.View;
11
12 import java.util.Vector JavaDoc;
13
14
15
16
17
18 public abstract class GmsImpl {
19     protected GMS gms=null;
20     protected final Log log=LogFactory.getLog(getClass());
21     boolean leaving=false;
22
23     public abstract void join(Address mbr);
24     public abstract void leave(Address mbr);
25
26     public abstract void handleJoinResponse(JoinRsp join_rsp);
27     public abstract void handleLeaveResponse();
28
29     public abstract void suspect(Address mbr);
30     public abstract void unsuspect(Address mbr);
31
32     public void merge(Vector JavaDoc other_coords) {;} // only processed by coord
33
public void handleMergeRequest(Address sender, Object JavaDoc merge_id) {;} // only processed by coords
34
public void handleMergeResponse(MergeData data, Object JavaDoc merge_id) {;} // only processed by coords
35
public void handleMergeView(MergeData data, Object JavaDoc merge_id) {;} // only processed by coords
36
public void handleMergeCancelled(Object JavaDoc merge_id) {;} // only processed by coords
37

38     public abstract JoinRsp handleJoin(Address mbr);
39     public abstract void handleLeave(Address mbr, boolean suspected);
40     public abstract void handleViewChange(View new_view, Digest digest);
41     public abstract void handleSuspect(Address mbr);
42     public void handleExit() {;}
43
44     public boolean handleUpEvent(Event evt) {return true;}
45     public boolean handleDownEvent(Event evt) {return true;}
46
47     public void init() throws Exception JavaDoc {leaving=false;}
48     public void start() throws Exception JavaDoc {leaving=false;}
49     public void stop() {leaving=true;}
50
51
52
53
54     protected void wrongMethod(String JavaDoc method_name) {
55         if(log.isErrorEnabled())
56             log.error(method_name + "() should not be invoked on an instance of " + getClass().getName());
57     }
58
59
60
61     /**
62        Returns potential coordinator based on lexicographic ordering of member addresses. Another
63        approach would be to keep track of the primary partition and return the first member if we
64        are the primary partition.
65      */

66     protected boolean iWouldBeCoordinator(Vector JavaDoc new_mbrs) {
67         Membership tmp_mbrs=gms.members.copy();
68         tmp_mbrs.merge(new_mbrs, null);
69         tmp_mbrs.sort();
70         if(tmp_mbrs.size() <= 0 || gms.local_addr == null)
71             return false;
72         return gms.local_addr.equals(tmp_mbrs.elementAt(0));
73     }
74
75 }
76
Popular Tags