1 22 package org.jboss.ha.framework.interfaces; 23 24 import java.util.ArrayList ; 25 import java.util.HashSet ; 26 27 37 public class SubPartitionInfo 38 implements Comparable , Cloneable , java.io.Serializable 39 { 40 44 private static final long serialVersionUID = -4116262958129610472L; 45 46 48 51 public String subPartitionName = null; 52 53 58 public HashSet subPartitionMergedNames = new HashSet (); 59 60 63 public ArrayList memberNodeNames = new ArrayList (); 64 65 private transient boolean newGroup = false; 66 67 69 71 public SubPartitionInfo () {} 72 73 public SubPartitionInfo (String partitionName, String [] members) 74 { 75 super (); 76 this.subPartitionName = partitionName; 77 if (members != null) 78 for (int i=0; i<members.length; i++) 79 this.memberNodeNames.add (members[i]); 80 } 81 82 84 public void setIsNewGroup () 85 { 86 this.newGroup = true; 87 } 88 89 public void merge (SubPartitionInfo merged) 90 { 91 this.memberNodeNames.addAll (merged.memberNodeNames); 92 if (this.newGroup && !merged.newGroup) 93 this.subPartitionName = merged.subPartitionName; 94 else if (!merged.newGroup) 95 this.subPartitionMergedNames.add (merged.subPartitionName); 96 97 98 if (!merged.newGroup) 99 this.subPartitionMergedNames.add (merged.subPartitionName); 100 this.subPartitionMergedNames.addAll (merged.subPartitionMergedNames); merged.memberNodeNames.clear (); 102 merged.subPartitionMergedNames.clear (); 103 } 104 105 public String toString () 106 { 107 return subPartitionName + ":[" + memberNodeNames + "] aka '" + subPartitionMergedNames + "'"; 108 } 109 110 public boolean actsForSubPartition (String subPartitionName) 111 { 112 return (subPartitionName.equals (subPartitionName) || subPartitionMergedNames.contains (subPartitionName)); 113 } 114 115 public boolean containsNode (String node) 116 { 117 return memberNodeNames.contains (node); 118 } 119 120 122 126 public int compareTo (Object o) 127 { 128 int mySize = memberNodeNames.size (); 129 int itsSize = ((SubPartitionInfo)o).memberNodeNames.size (); 130 131 if (mySize==itsSize) 132 return 0; 133 else if (mySize > itsSize) 134 return 1; 135 else 136 return -1; 137 138 } 139 140 142 public Object clone () 143 { 144 SubPartitionInfo clonedObject = new SubPartitionInfo (); 145 clonedObject.subPartitionName = this.subPartitionName; 146 clonedObject.memberNodeNames = (ArrayList )this.memberNodeNames.clone (); 147 clonedObject.subPartitionMergedNames = (HashSet )this.subPartitionMergedNames.clone (); 148 149 return clonedObject; 150 } 151 152 } 153 | Popular Tags |