KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ha > framework > interfaces > SubPartitionsInfo


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ha.framework.interfaces;
23
24 import java.io.Serializable JavaDoc;
25
26 /**
27  * Holder class that knows about a set of HA(sub)Partition currently
28  * building the overall cluster. Exchanged between HASessionState
29  * instances to share the same knowledge.
30  *
31  * @see SubPartitionInfo
32  * @see org.jboss.ha.hasessionstate.interfaces.HASessionState
33  * @see org.jboss.ha.hasessionstate.server.HASessionStateImpl
34  *
35  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>
36  * @version $Revision: 37459 $
37  */

38 public class SubPartitionsInfo implements Serializable JavaDoc, Cloneable JavaDoc
39 {
40    // Constants -----------------------------------------------------
41
/** The serialVersionUID
42     * @since 1.2
43     */

44    private static final long serialVersionUID = 3231573521328800529L;
45
46    // Attributes ----------------------------------------------------
47

48     public SubPartitionInfo[] partitions = null;
49     protected long groupId = 0;
50
51     // Static --------------------------------------------------------
52

53    // Constructors --------------------------------------------------
54

55     public SubPartitionsInfo () {}
56
57    // Public --------------------------------------------------------
58

59     /**
60      * return the next distinct id for a new group
61      */

62     public long getNextGroupId ()
63     {
64        return groupId++;
65     }
66     
67     /**
68      * Returns the {@link SubPartitionInfo} instance in this group that has the given name.
69      */

70     public SubPartitionInfo getSubPartitionWithName (String JavaDoc name)
71     {
72        if (partitions != null)
73        {
74          for (int i=0; i<partitions.length; i++)
75             if ((partitions[i]).containsNode (name))
76                return partitions[i];
77        }
78
79        return null;
80     }
81     
82    // Cloneable implementation ----------------------------------------------
83

84     public Object JavaDoc clone ()
85     {
86        SubPartitionsInfo theClone = new SubPartitionsInfo ();
87        
88        if (partitions != null)
89        {
90           theClone.partitions = new SubPartitionInfo[partitions.length];
91          for (int i=0; i<partitions.length; i++)
92             theClone.partitions[i] = (SubPartitionInfo)partitions[i].clone ();
93        }
94        
95        theClone.groupId = groupId;
96        
97        return theClone;
98        
99     }
100     
101    // Object overrides ---------------------------------------------------
102

103     public String JavaDoc toString ()
104     {
105        String JavaDoc result = null;
106        
107        if (partitions == null)
108           result = "{null}";
109        else
110        {
111           result = "{";
112           for (int i=0; i<partitions.length; i++)
113              result+= "\n " + partitions[i].toString ();
114           result+= "\n}";
115        }
116        
117        return result;
118     }
119
120     // Package protected ---------------------------------------------
121

122    // Protected -----------------------------------------------------
123

124    // Private -------------------------------------------------------
125

126    // Inner classes -------------------------------------------------
127

128 }
129
Popular Tags