1 3 package org.jgroups.protocols; 4 5 import org.jgroups.Address; 6 import org.jgroups.View; 7 import org.jgroups.ViewId; 8 import org.jgroups.blocks.GroupRequest; 9 import org.jgroups.blocks.MethodCall; 10 11 import java.util.Vector ; 12 13 14 public class ParticipantGmsImpl extends GmsImpl { 15 boolean leaving=false; 16 boolean received_final_view=false; 17 final Object leave_mutex=new Object (); 18 final Vector suspected_mbrs=new Vector (5); 19 final Vector new_mbrs=new Vector (11); 20 21 22 public ParticipantGmsImpl(GMS g) { 23 gms=g; 24 init(); 25 } 26 27 28 public void init() { 29 leaving=false; 30 received_final_view=false; 31 suspected_mbrs.removeAllElements(); 32 new_mbrs.removeAllElements(); 33 if(gms.members != null) 34 for(int i=0; i < gms.members.size(); i++) 35 new_mbrs.addElement(gms.members.elementAt(i)); 36 } 37 38 39 public void join(Address mbr) { 40 wrongMethod("join"); 41 } 42 43 44 48 public void leave(Address mbr) { 49 Address coord; 50 Boolean retval=null; 51 52 if(mbr.equals(gms.local_addr)) 53 leaving=true; 54 55 56 while((coord=gms.determineCoordinator()) != null && !received_final_view) { 57 synchronized(leave_mutex) { 58 if(gms.local_addr.equals(coord)) { gms.becomeCoordinator(); 60 gms.handleLeave(mbr, false); } 62 else { 63 try { 64 65 if(log.isInfoEnabled()) log.info("sending LEAVE request to " + coord); 66 MethodCall call = new MethodCall("handleLeave", new Object [] {mbr, Boolean.FALSE}, 67 new String [] {Address.class.getName(), boolean.class.getName()}); 68 gms.callRemoteMethod(coord, call, GroupRequest.GET_NONE, 0); } 70 catch(Exception e) { 71 } 72 } 73 74 try { 75 leave_mutex.wait(gms.leave_timeout); 76 } 77 catch(Exception e) { 78 } 79 } 80 } 81 gms.becomeClient(); 82 } 83 84 85 public void suspect(Address mbr) { 86 handleSuspect(mbr); 87 } 88 89 90 public void merge(Vector other_coords) { 91 wrongMethod("merge"); 92 } 93 94 95 public boolean handleJoin(Address mbr) { 96 wrongMethod("handleJoin"); 97 return false; 98 } 99 100 101 public void handleLeave(Address mbr, boolean suspected) { 102 wrongMethod("handleLeave"); 103 } 104 105 106 110 public void handleViewChange(ViewId new_view, Vector mbrs) { 111 if(log.isInfoEnabled()) log.info("mbrs are " + mbrs); 112 113 suspected_mbrs.removeAllElements(); 114 new_mbrs.removeAllElements(); 115 if(mbrs != null) 116 for(int i=0; i < mbrs.size(); i++) 117 new_mbrs.addElement(mbrs.elementAt(i)); 118 119 if(leaving) { 120 if(mbrs.contains(gms.local_addr)) { 121 if(log.isWarnEnabled()) log.warn("received view in " + 122 "which I'm still a member, cannot quit yet"); 123 gms.installView(new_view, mbrs); 124 } 125 else { 126 synchronized(leave_mutex) { 127 received_final_view=true; 128 leave_mutex.notifyAll(); 129 } 130 } 131 return; 132 } 133 gms.installView(new_view, mbrs); 134 } 135 136 137 public View handleMerge(ViewId other_view, Vector other_members) { 139 wrongMethod("handleMerge"); 140 return null; 141 } 142 143 public void handleSuspect(Address mbr) { 144 Vector suspects=null; 145 146 if(mbr == null) return; 147 if(!suspected_mbrs.contains(mbr)) 148 suspected_mbrs.addElement(mbr); 149 new_mbrs.removeElement(mbr); 150 151 152 if(log.isInfoEnabled()) log.info("suspected mbr=" + mbr + 153 "\nsuspected_mbrs=" + suspected_mbrs + "\nnew_mbrs=" + new_mbrs); 154 155 if(new_mbrs.size() > 0 && new_mbrs.elementAt(0).equals(gms.local_addr)) { 156 157 if(log.isInfoEnabled()) log.info("suspected mbr=" + mbr + ", members are " + gms.members + 158 ", coord=" + gms.local_addr + ": I'm the new coord !"); 159 160 suspects=(Vector ) suspected_mbrs.clone(); 161 suspected_mbrs.removeAllElements(); 162 new_mbrs.removeAllElements(); 163 gms.becomeCoordinator(); 164 gms.castViewChange(null, null, suspects); 165 } 166 } 167 168 169 } 170 | Popular Tags |