001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ha.framework.interfaces;
023:
024: import java.io.Serializable;
025:
026: /**
027: * Holder class that knows about a set of HA(sub)Partition currently
028: * building the overall cluster. Exchanged between HASessionState
029: * instances to share the same knowledge.
030: *
031: * @see SubPartitionInfo
032: * @see org.jboss.ha.hasessionstate.interfaces.HASessionState
033: * @see org.jboss.ha.hasessionstate.server.HASessionStateImpl
034: *
035: * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>
036: * @version $Revision: 57188 $
037: */
038: public class SubPartitionsInfo implements Serializable, Cloneable {
039: // Constants -----------------------------------------------------
040: /** The serialVersionUID
041: * @since 1.2
042: */
043: private static final long serialVersionUID = 3231573521328800529L;
044:
045: // Attributes ----------------------------------------------------
046:
047: public SubPartitionInfo[] partitions = null;
048: protected long groupId = 0;
049:
050: // Static --------------------------------------------------------
051:
052: // Constructors --------------------------------------------------
053:
054: public SubPartitionsInfo() {
055: }
056:
057: // Public --------------------------------------------------------
058:
059: /**
060: * return the next distinct id for a new group
061: */
062: public long getNextGroupId() {
063: return groupId++;
064: }
065:
066: /**
067: * Returns the {@link SubPartitionInfo} instance in this group that has the given name.
068: */
069: public SubPartitionInfo getSubPartitionWithName(String name) {
070: if (partitions != null) {
071: for (int i = 0; i < partitions.length; i++)
072: if ((partitions[i]).containsNode(name))
073: return partitions[i];
074: }
075:
076: return null;
077: }
078:
079: // Cloneable implementation ----------------------------------------------
080:
081: public Object clone() {
082: SubPartitionsInfo theClone = new SubPartitionsInfo();
083:
084: if (partitions != null) {
085: theClone.partitions = new SubPartitionInfo[partitions.length];
086: for (int i = 0; i < partitions.length; i++)
087: theClone.partitions[i] = (SubPartitionInfo) partitions[i]
088: .clone();
089: }
090:
091: theClone.groupId = groupId;
092:
093: return theClone;
094:
095: }
096:
097: // Object overrides ---------------------------------------------------
098:
099: public String toString() {
100: String result = null;
101:
102: if (partitions == null)
103: result = "{null}";
104: else {
105: result = "{";
106: for (int i = 0; i < partitions.length; i++)
107: result += "\n " + partitions[i].toString();
108: result += "\n}";
109: }
110:
111: return result;
112: }
113:
114: // Package protected ---------------------------------------------
115:
116: // Protected -----------------------------------------------------
117:
118: // Private -------------------------------------------------------
119:
120: // Inner classes -------------------------------------------------
121:
122: }
|