01: // $Id: GmsImpl.java,v 1.5 2005/08/11 12:43:47 belaban Exp $
02:
03: package org.jgroups.protocols;
04:
05: import org.apache.commons.logging.Log;
06: import org.apache.commons.logging.LogFactory;
07: import org.jgroups.*;
08:
09: import java.util.Vector;
10:
11: public abstract class GmsImpl {
12: protected GMS gms = null;
13:
14: protected final Log log = LogFactory.getLog(getClass());
15: final boolean warn = log.isWarnEnabled();
16:
17: public abstract void init(); // initialize variables
18:
19: public abstract void join(Address mbr);
20:
21: public abstract void leave(Address mbr);
22:
23: public abstract void suspect(Address mbr);
24:
25: public abstract void merge(Vector coords);
26:
27: public abstract boolean handleJoin(Address mbr);
28:
29: public abstract void handleLeave(Address mbr, boolean suspected);
30:
31: public abstract void handleViewChange(ViewId new_view, Vector mbrs);
32:
33: public abstract View handleMerge(ViewId other_view,
34: Vector other_members);
35:
36: public abstract void handleSuspect(Address mbr);
37:
38: public boolean handleUpEvent(Event evt) {
39: return true;
40: }
41:
42: public boolean handleDownEvent(Event evt) {
43: return true;
44: }
45:
46: protected void wrongMethod(String method_name) {
47: if (log.isErrorEnabled())
48: log.error("method " + method_name
49: + "() should not be sent to an instance of "
50: + getClass().getName());
51: }
52:
53: /**
54: Returns potential coordinator based on lexicographic ordering of member addresses. Another
55: approach would be to keep track of the primary partition and return the first member if we
56: are the primary partition.
57: */
58: protected boolean iWouldBeCoordinator(Vector new_mbrs) {
59: Membership tmp_mbrs = gms.mbrs.copy();
60: tmp_mbrs.merge(new_mbrs, null);
61: tmp_mbrs.sort();
62: if (tmp_mbrs.size() <= 0 || gms.local_addr == null)
63: return false;
64: return gms.local_addr.equals(tmp_mbrs.elementAt(0));
65: }
66:
67: }
|