1 3 package org.jgroups.protocols; 4 5 import org.jgroups.Address; 6 import org.jgroups.Event; 7 import org.jgroups.View; 8 import org.jgroups.stack.Protocol; 9 10 import java.util.Vector ; 11 12 13 18 19 public class VIEW_ENFORCER extends Protocol { 20 Address local_addr=null; 21 boolean is_member=false; 22 23 24 27 public String getName() { 28 return "VIEW_ENFORCER"; 29 } 30 31 32 public void up(Event evt) { 33 34 switch(evt.getType()) { 35 36 case Event.VIEW_CHANGE: 37 if(is_member) break; 39 40 Vector new_members=((View)evt.getArg()).getMembers(); 41 if(new_members == null || new_members.size() == 0) 42 break; 43 if(local_addr == null) { 44 System.err.println("VIEW_ENFORCER.up(VIEW_CHANGE): local address is null; cannot check " + 45 "whether I'm a member of the group; discarding view change"); 46 return; 47 } 48 49 if(new_members.contains(local_addr)) 50 is_member=true; 51 else 52 return; 53 54 break; 55 56 case Event.SET_LOCAL_ADDRESS: 57 local_addr=(Address)evt.getArg(); 58 break; 59 60 61 case Event.MSG: 62 if(!is_member) { if(log.isInfoEnabled()) log.info("dropping message " + evt.getArg()); 64 return; 65 } 66 break; 67 68 } 69 passUp(evt); } 71 72 73 } 74 | Popular Tags |