001: // $Id: GmsImpl.java,v 1.18 2006/08/04 15:53:33 belaban Exp $
002:
003: package org.jgroups.protocols.pbcast;
004:
005: import org.apache.commons.logging.Log;
006: import org.jgroups.*;
007:
008: import java.util.Vector;
009: import java.util.Collection;
010: import java.util.Set;
011:
012: public abstract class GmsImpl {
013: protected GMS gms = null;
014: // protected final Log log=LogFactory.getLog(getClass());
015: protected final Log log;
016: final boolean trace;
017: final boolean warn;
018: boolean leaving = false;
019:
020: protected GmsImpl() {
021: log = null;
022: trace = warn = false;
023: }
024:
025: protected GmsImpl(GMS gms) {
026: this .gms = gms;
027: log = gms.getLog();
028: trace = log.isTraceEnabled();
029: warn = log.isWarnEnabled();
030: }
031:
032: public abstract void join(Address mbr);
033:
034: public abstract void leave(Address mbr);
035:
036: public abstract void handleJoinResponse(JoinRsp join_rsp);
037:
038: public abstract void handleLeaveResponse();
039:
040: public abstract void suspect(Address mbr);
041:
042: public abstract void unsuspect(Address mbr);
043:
044: public void merge(Vector other_coords) {
045: } // only processed by coord
046:
047: public void handleMergeRequest(Address sender, ViewId merge_id) {
048: } // only processed by coords
049:
050: public void handleMergeResponse(MergeData data, ViewId merge_id) {
051: } // only processed by coords
052:
053: public void handleMergeView(MergeData data, ViewId merge_id) {
054: } // only processed by coords
055:
056: public void handleMergeCancelled(ViewId merge_id) {
057: } // only processed by coords
058:
059: public abstract void handleMembershipChange(Collection newMembers,
060: Collection oldMembers, Collection suspectedMembers);
061:
062: public abstract void handleViewChange(View new_view, Digest digest);
063:
064: public void handleExit() {
065: }
066:
067: public boolean handleUpEvent(Event evt) {
068: return true;
069: }
070:
071: public void init() throws Exception {
072: leaving = false;
073: }
074:
075: public void start() throws Exception {
076: leaving = false;
077: }
078:
079: public void stop() {
080: leaving = true;
081: }
082:
083: protected void sendMergeRejectedResponse(Address sender,
084: ViewId merge_id) {
085: Message msg = new Message(sender, null, null);
086: GMS.GmsHeader hdr = new GMS.GmsHeader(GMS.GmsHeader.MERGE_RSP);
087: hdr.merge_rejected = true;
088: hdr.merge_id = merge_id;
089: msg.putHeader(gms.getName(), hdr);
090: if (log.isDebugEnabled())
091: log.debug("response=" + hdr);
092: gms.passDown(new Event(Event.MSG, msg));
093: }
094:
095: protected void wrongMethod(String method_name) {
096: if (log.isWarnEnabled())
097: log.warn(method_name
098: + "() should not be invoked on an instance of "
099: + getClass().getName());
100: }
101:
102: /**
103: Returns potential coordinator based on lexicographic ordering of member addresses. Another
104: approach would be to keep track of the primary partition and return the first member if we
105: are the primary partition.
106: */
107: protected boolean iWouldBeCoordinator(Vector new_mbrs) {
108: Membership tmp_mbrs = gms.members.copy();
109: tmp_mbrs.merge(new_mbrs, null);
110: tmp_mbrs.sort();
111: if (tmp_mbrs.size() <= 0 || gms.local_addr == null)
112: return false;
113: return gms.local_addr.equals(tmp_mbrs.elementAt(0));
114: }
115:
116: }
|