[Jboss-cvs] JBossAS SVN: r54919 - trunk/cluster/src/main/org/jboss/ha/framework/interfaces
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 31 12:43:01 EDT 2006
Author: bstansberry at jboss.com
Date: 2006-07-31 12:43:00 -0400 (Mon, 31 Jul 2006)
New Revision: 54919
Modified:
trunk/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java
Log:
[JBAS-2225] Target list exposed by FCI s/b immutable
Modified: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java 2006-07-31 16:12:12 UTC (rev 54918)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java 2006-07-31 16:43:00 UTC (rev 54919)
@@ -22,6 +22,10 @@
package org.jboss.ha.framework.interfaces;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ListIterator;
+
import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
/**
@@ -67,8 +71,15 @@
// FamilyClusterInfo implementation ----------------------------------------------
- public String getFamilyName () { return this.familyName; }
- public synchronized ArrayList getTargets () { return this.targets; }
+ public String getFamilyName () { return this.familyName; }
+
+ /**
+ * Returns an immutable subclass of ArrayList.
+ */
+ public synchronized ArrayList getTargets ()
+ {
+ return new ImmutableArrayList(this.targets);
+ }
public long getCurrentViewId () { return this.currentViewId; }
public int getCursor () { return this.cursor; }
public int setCursor (int cursor) { return (this.cursor = cursor);}
@@ -83,8 +94,8 @@
tmp.remove (target);
this.targets = tmp;
this.isViewMembersInSyncWithViewId = false;
- }
- return this.targets;
+ return new ImmutableArrayList(this.targets);
+ }
}
public ArrayList updateClusterInfo (ArrayList targets, long viewId)
@@ -94,8 +105,8 @@
this.targets = (ArrayList) targets.clone();
this.currentViewId = viewId;
this.isViewMembersInSyncWithViewId = true;
+ return new ImmutableArrayList(this.targets);
}
- return this.targets;
}
public boolean currentMembershipInSyncWithViewId ()
@@ -156,4 +167,152 @@
// Inner classes -------------------------------------------------
+ private class ImmutableArrayList extends ArrayList
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -991188901511748496L;
+
+ ImmutableArrayList(ArrayList source)
+ {
+ super(source);
+ }
+
+ public void add(int arg0, Object arg1)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean add(Object arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean addAll(Collection arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean addAll(int arg0, Collection arg1)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public void ensureCapacity(int arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public Object remove(int arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean remove(Object arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ protected void removeRange(int arg0, int arg1)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public Object set(int arg0, Object arg1)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public void trimToSize()
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public Iterator iterator()
+ {
+ return new ImmutableArrayListIterator(super.listIterator());
+ }
+
+ public ListIterator listIterator()
+ {
+ return new ImmutableArrayListIterator(super.listIterator());
+ }
+
+ public ListIterator listIterator(int index)
+ {
+ return new ImmutableArrayListIterator(super.listIterator(index));
+ }
+
+ public boolean removeAll(Collection arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean retainAll(Collection arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ }
+
+ private class ImmutableArrayListIterator implements ListIterator
+ {
+ private ListIterator delegate;
+
+ ImmutableArrayListIterator(ListIterator delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public boolean hasNext()
+ {
+ return delegate.hasNext();
+ }
+
+ public Object next()
+ {
+ return delegate.next();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+
+ }
+
+ public void add(Object o)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean hasPrevious()
+ {
+ return delegate.hasPrevious();
+ }
+
+ public int nextIndex()
+ {
+ return delegate.nextIndex();
+ }
+
+ public Object previous()
+ {
+ return delegate.previous();
+ }
+
+ public int previousIndex()
+ {
+ return delegate.previousIndex();
+ }
+
+ public void set(Object o)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ }
}
More information about the jboss-cvs-commits
mailing list