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.util.ArrayList;
025:
026: import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
027:
028: /**
029: * Default implementation of FamilyClusterInfo
030: *
031: * @see org.jboss.ha.framework.interfaces.FamilyClusterInfo
032: * @see org.jboss.ha.framework.interfaces.ClusteringTargetsRepository
033: *
034: * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
035: * @version $Revision: 57188 $
036: */
037: public class FamilyClusterInfoImpl implements FamilyClusterInfo {
038:
039: // Constants -----------------------------------------------------
040:
041: // Attributes ----------------------------------------------------
042:
043: public String familyName = null;
044: ArrayList targets = null;
045: long currentViewId = 0;
046: boolean isViewMembersInSyncWithViewId = false;
047:
048: int cursor = FamilyClusterInfo.UNINITIALIZED_CURSOR;
049: Object arbitraryObject = null;
050:
051: // Static --------------------------------------------------------
052:
053: // Constructors --------------------------------------------------
054:
055: private FamilyClusterInfoImpl() {
056: }
057:
058: protected FamilyClusterInfoImpl(String familyName,
059: ArrayList targets, long viewId) {
060: this .familyName = familyName;
061: this .targets = (ArrayList) targets.clone();
062: this .currentViewId = viewId;
063:
064: this .isViewMembersInSyncWithViewId = false;
065: }
066:
067: // Public --------------------------------------------------------
068:
069: // FamilyClusterInfo implementation ----------------------------------------------
070:
071: public String getFamilyName() {
072: return this .familyName;
073: }
074:
075: /**
076: * Returns an immutable subclass of ArrayList.
077: */
078: public synchronized ArrayList getTargets() {
079: return new ImmutableArrayList(this .targets);
080: }
081:
082: public long getCurrentViewId() {
083: return this .currentViewId;
084: }
085:
086: public int getCursor() {
087: return this .cursor;
088: }
089:
090: public int setCursor(int cursor) {
091: return (this .cursor = cursor);
092: }
093:
094: public Object getObject() {
095: return this .arbitraryObject;
096: }
097:
098: public Object setObject(Object whatever) {
099: this .arbitraryObject = whatever;
100: return this .arbitraryObject;
101: }
102:
103: public ArrayList removeDeadTarget(Object target) {
104: synchronized (this ) {
105: ArrayList tmp = (ArrayList) targets.clone();
106: tmp.remove(target);
107: this .targets = tmp;
108: this .isViewMembersInSyncWithViewId = false;
109: return new ImmutableArrayList(this .targets);
110: }
111: }
112:
113: public ArrayList updateClusterInfo(ArrayList targets, long viewId) {
114: synchronized (this ) {
115: this .targets = (ArrayList) targets.clone();
116: this .currentViewId = viewId;
117: this .isViewMembersInSyncWithViewId = true;
118: return new ImmutableArrayList(this .targets);
119: }
120: }
121:
122: public boolean currentMembershipInSyncWithViewId() {
123: return this .isViewMembersInSyncWithViewId;
124: }
125:
126: public void resetView() {
127: synchronized (this ) {
128: this .currentViewId = -1;
129: this .isViewMembersInSyncWithViewId = false;
130: }
131: }
132:
133: // Object overrides ---------------------------------------------------
134:
135: public int hashCode() {
136: return this .familyName.hashCode();
137: }
138:
139: public boolean equals(Object o) {
140: if (o instanceof FamilyClusterInfoImpl) {
141: FamilyClusterInfoImpl fr = (FamilyClusterInfoImpl) o;
142: return fr.familyName == this .familyName;
143: } else
144: return false;
145: }
146:
147: public String toString() {
148: StringBuffer tmp = new StringBuffer(super .toString());
149: tmp.append("{familyName=");
150: tmp.append(familyName);
151: tmp.append(",targets=");
152: tmp.append(targets);
153: tmp.append(",currentViewId=");
154: tmp.append(currentViewId);
155: tmp.append(",isViewMembersInSyncWithViewId=");
156: tmp.append(isViewMembersInSyncWithViewId);
157: tmp.append(",cursor=");
158: tmp.append(cursor);
159: tmp.append(",arbitraryObject=");
160: tmp.append(arbitraryObject);
161: tmp.append("}");
162: return tmp.toString();
163: }
164: // Package protected ---------------------------------------------
165:
166: // Protected -----------------------------------------------------
167:
168: // Private -------------------------------------------------------
169:
170: // Inner classes -------------------------------------------------
171: }
|