1 3 package org.jgroups; 4 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 import java.util.*; 10 11 12 17 public class Membership implements Cloneable { 18 19 private final LinkedList members=new LinkedList(); 20 protected static final Log log=LogFactory.getLog(Membership.class); 21 22 26 public Membership() { 27 } 28 29 30 38 public Membership(Collection initial_members) { 39 if(initial_members != null) 40 add(initial_members); 41 } 42 43 44 45 53 public Vector getMembers() { 54 55 synchronized(members) { 56 return new Vector(members); 57 } 58 } 59 60 61 66 public void add(Address new_member) { 67 synchronized(members) { 68 if(new_member != null && !members.contains(new_member)) { 69 members.add(new_member); 70 } 71 } 72 } 73 74 75 82 public void add(Collection v) { 83 if(v != null) { 84 for(Iterator it=v.iterator(); it.hasNext();) { 85 Address addr=(Address)it.next(); 86 add(addr); 87 } 88 } 89 } 90 91 92 98 public void remove(Address old_member) { 99 if(old_member != null) { 100 synchronized(members) { 101 members.remove(old_member); 102 } 103 } 104 } 105 106 107 112 public void remove(Collection v) { 113 if(v != null) { 114 synchronized(members) { 115 members.removeAll(v); 116 } 117 } 118 } 119 120 121 124 public void clear() { 125 synchronized(members) { 126 members.clear(); 127 } 128 } 129 130 138 public void set(Collection v) { 139 clear(); 140 if(v != null) { 141 add(v); 142 } 143 } 144 145 146 154 public void set(Membership m) { 155 clear(); 156 if(m != null) { 157 add(m.getMembers()); 158 } 159 } 160 161 162 173 public void merge(Collection new_mems, Collection suspects) { 174 remove(suspects); 175 add(new_mems); 176 } 177 178 179 185 public boolean contains(Address member) { 186 if(member == null) return false; 187 synchronized(members) { 188 return members.contains(member); 189 } 190 } 191 192 193 194 public void sort() { 195 synchronized(members) { 196 Collections.sort(members); 197 } 198 } 199 200 201 202 203 208 public Membership copy() { 209 return ((Membership)clone()); 210 } 211 212 213 217 public Object clone() { 218 return new Membership(this.members); 219 } 220 221 222 227 public int size() { 228 synchronized(members) { 229 return members.size(); 230 } 231 } 232 233 240 241 public Object elementAt(int index) { 242 synchronized(members) { 243 return members.get(index); 244 } 245 } 246 247 248 public String toString() { 249 synchronized(members) { 250 return members.toString(); 251 } 252 } 253 254 255 } 256 | Popular Tags |