1 22 package org.jboss.ha.framework.interfaces; 23 24 import java.util.ArrayList ; 25 import java.util.Collections ; 26 import java.util.List ; 27 28 37 public class FamilyClusterInfoImpl implements FamilyClusterInfo 38 { 39 40 42 44 public String familyName = null; 45 ArrayList targets = null; 46 long currentViewId = 0; 47 boolean isViewMembersInSyncWithViewId = false; 48 49 int cursor = FamilyClusterInfo.UNINITIALIZED_CURSOR; 50 Object arbitraryObject = null; 51 52 54 56 private FamilyClusterInfoImpl (){ } 57 58 protected FamilyClusterInfoImpl (String familyName, List targets, long viewId) 59 { 60 this.familyName = familyName; 61 this.targets = cloneList(targets); 62 this.currentViewId = viewId; 63 64 this.isViewMembersInSyncWithViewId = false; 65 } 66 67 69 71 public String getFamilyName () { return this.familyName; } 72 73 78 public synchronized List getTargets () 79 { 80 return Collections.unmodifiableList(this.targets); 81 } 82 public long getCurrentViewId () { return this.currentViewId; } 83 public int getCursor () { return this.cursor; } 84 public int setCursor (int cursor) { return (this.cursor = cursor);} 85 public Object getObject () { return this.arbitraryObject; } 86 public Object setObject (Object whatever) { this.arbitraryObject = whatever; return this.arbitraryObject; } 87 88 public List removeDeadTarget(Object target) 89 { 90 synchronized (this) 91 { 92 ArrayList tmp = (ArrayList ) targets.clone(); 93 tmp.remove (target); 94 this.targets = tmp; 95 this.isViewMembersInSyncWithViewId = false; 96 return Collections.unmodifiableList(this.targets); 97 } 98 } 99 100 public List updateClusterInfo (List targets, long viewId) 101 { 102 synchronized (this) 103 { 104 this.targets = cloneList(targets); 105 this.currentViewId = viewId; 106 this.isViewMembersInSyncWithViewId = true; 107 return Collections.unmodifiableList(this.targets); 108 } 109 } 110 111 public boolean currentMembershipInSyncWithViewId () 112 { 113 return this.isViewMembersInSyncWithViewId; 114 } 115 116 public void resetView () 117 { 118 synchronized (this) 119 { 120 this.currentViewId = -1; 121 this.isViewMembersInSyncWithViewId = false; 122 } 123 } 124 125 127 public int hashCode() 128 { 129 return this.familyName.hashCode (); 130 } 131 132 public boolean equals (Object o) 133 { 134 if (o instanceof FamilyClusterInfoImpl) 135 { 136 FamilyClusterInfoImpl fr = (FamilyClusterInfoImpl)o; 137 return fr.familyName == this.familyName; 138 } 139 else 140 return false; 141 } 142 143 public String toString() 144 { 145 StringBuffer tmp = new StringBuffer (super.toString()); 146 tmp.append("{familyName="); 147 tmp.append(familyName); 148 tmp.append(",targets="); 149 tmp.append(targets); 150 tmp.append(",currentViewId="); 151 tmp.append(currentViewId); 152 tmp.append(",isViewMembersInSyncWithViewId="); 153 tmp.append(isViewMembersInSyncWithViewId); 154 tmp.append(",cursor="); 155 tmp.append(cursor); 156 tmp.append(",arbitraryObject="); 157 tmp.append(arbitraryObject); 158 tmp.append("}"); 159 return tmp.toString(); 160 } 161 163 165 167 169 private static ArrayList cloneList(List toClone) 170 { 171 if (toClone instanceof ArrayList ) 172 { 173 synchronized (toClone) 174 { 175 return (ArrayList ) ((ArrayList ) toClone).clone(); 176 } 177 } 178 179 ArrayList clone = new ArrayList (toClone.size()); 180 synchronized (toClone) 181 { 182 clone.addAll(toClone); 183 } 184 return clone; 185 } 186 } 187 | Popular Tags |