User: slaboure Date: 01/11/09 14:41:22 Added: src/main/org/jboss/ha/framework/interfaces SubPartitionInfo.java SubPartitionsInfo.java Log: Clustering for SFSB Revision Changes Path 1.1 jbossmx/src/main/org/jboss/ha/framework/interfaces/SubPartitionInfo.java Index: SubPartitionInfo.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ha.framework.interfaces; import java.util.ArrayList; import java.util.HashSet; import java.io.Serializable; /** * Holder class that knows about a particular HA(sub)Partition i.e. member nodes, * partition name and some utility functions. * * @see HASessionState, HASessionStateImpl * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a> * @version $Revision: 1.1 $ * * <p><b>Revisions:</b> */ public class SubPartitionInfo implements Serializable, Comparable, Cloneable { // Name of the current sub-partition (will be used to create a JavaGroups group) // public String subPartitionName = null; // When sub-partitions are merged, some names will disappear (eg. Merge G1 and G2 in G1) // this structure remembers the removed named so that HAPartition can know which new group // they should join // public HashSet subPartitionMergedNames = new HashSet (); // List of nodes part of this sub-partition // public ArrayList memberNodeNames = new ArrayList (); private transient boolean newGroup = false; public SubPartitionInfo () {} public SubPartitionInfo (String partitionName, String[] members) { super (); this.subPartitionName = partitionName; if (members != null) for (int i=0; i<members.length; i++) this.memberNodeNames.add (members[i]); } public void setIsNewGroup () { this.newGroup = true; } /** * "Note: this class has a natural ordering that is * inconsistent with equals." */ public int compareTo (Object o) { int mySize = memberNodeNames.size (); int itsSize = ((SubPartitionInfo)o).memberNodeNames.size (); if (mySize==itsSize) return 0; else if (mySize > itsSize) return 1; else return -1; } public Object clone () { SubPartitionInfo clonedObject = new SubPartitionInfo (); clonedObject.subPartitionName = this.subPartitionName; clonedObject.memberNodeNames = (ArrayList)this.memberNodeNames.clone (); clonedObject.subPartitionMergedNames = (HashSet)this.subPartitionMergedNames.clone (); return clonedObject; } public void merge (SubPartitionInfo merged) { this.memberNodeNames.addAll (merged.memberNodeNames); if (this.newGroup && !merged.newGroup) this.subPartitionName = merged.subPartitionName; else if (!merged.newGroup) this.subPartitionMergedNames.add (merged.subPartitionName); if (!merged.newGroup) this.subPartitionMergedNames.add (merged.subPartitionName); this.subPartitionMergedNames.addAll (merged.subPartitionMergedNames); // ? needed ? merged.memberNodeNames.clear (); merged.subPartitionMergedNames.clear (); } public String toString () { return subPartitionName + ":[" + memberNodeNames + "] aka '" + subPartitionMergedNames + "'"; } public boolean actsForSubPartition (String subPartitionName) { return (subPartitionName.equals (subPartitionName) || subPartitionMergedNames.contains (subPartitionName)); } public boolean containsNode (String node) { return memberNodeNames.contains (node); } } 1.1 jbossmx/src/main/org/jboss/ha/framework/interfaces/SubPartitionsInfo.java Index: SubPartitionsInfo.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ha.framework.interfaces; import java.io.Serializable; /** * Holder class that knows about a set of HA(sub)Partition currently * building the overall cluster. Exchanged between HASessionState * instances to share the same knowledge. * * @see SubPartitionInfo, HASessionState, HASessionStateImpl * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a> * @version $Revision: 1.1 $ * * <p><b>Revisions:</b> */ public class SubPartitionsInfo implements Serializable, Cloneable { public SubPartitionInfo[] partitions = null; protected long groupId = 0; public SubPartitionsInfo () {} public long getNextGroupId () { return groupId++; } public SubPartitionInfo getSubPartitionWithName (String name) { if (partitions != null) { for (int i=0; i<partitions.length; i++) if (((SubPartitionInfo)partitions[i]).containsNode (name)) return (SubPartitionInfo)partitions[i]; } return null; } public Object clone () { SubPartitionsInfo theClone = new SubPartitionsInfo (); if (partitions != null) { theClone.partitions = new SubPartitionInfo[partitions.length]; for (int i=0; i<partitions.length; i++) theClone.partitions[i] = (SubPartitionInfo)partitions[i].clone (); } theClone.groupId = groupId; return theClone; } public String toString () { String result = null; if (partitions == null) result = "{null}"; else { result = "{"; for (int i=0; i<partitions.length; i++) result+= "\n " + partitions[i].toString (); result+= "\n}"; } return result; } }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development