1 package org.jgroups.blocks; 2 3 import org.jgroups.Address; 4 import org.jgroups.MembershipListener; 5 import org.jgroups.View; 6 7 import java.util.HashSet ; 8 9 18 19 public class MembershipListenerAdapter implements MembershipListener { 20 21 protected final HashSet membershipListeners = new HashSet (); 22 protected MembershipListener[] membershipListenersCache = 23 new MembershipListener[0]; 24 25 30 public void block() { 31 for(int i = 0; i < membershipListenersCache.length; i++) 32 membershipListenersCache[i].block(); 33 } 34 35 40 public void suspect(Address suspected_mbr) { 41 for(int i = 0; i < membershipListenersCache.length; i++) 42 membershipListenersCache[i].suspect(suspected_mbr); 43 } 44 45 49 public void viewAccepted(View new_view) { 50 for(int i = 0; i < membershipListenersCache.length; i++) 51 membershipListenersCache[i].viewAccepted(new_view); 52 } 53 54 61 public synchronized void addMembershipListener(MembershipListener listener) { 62 if (membershipListeners.add(listener)) 63 membershipListenersCache = 64 (MembershipListener[])membershipListeners.toArray( 65 new MembershipListener[membershipListeners.size()]); 66 } 67 68 75 public synchronized void removeMembershipListener(MembershipListener listener) { 76 if (membershipListeners.remove(listener)) 77 membershipListenersCache = 78 (MembershipListener[])membershipListeners.toArray( 79 new MembershipListener[membershipListeners.size()]); 80 81 } 82 83 } | Popular Tags |