Author: manik.surtani(a)jboss.com
Date: 2008-06-25 10:15:51 -0400 (Wed, 25 Jun 2008)
New Revision: 6035
Modified:
core/trunk/src/main/java/org/jboss/cache/Fqn.java
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/Region.java
core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
core/trunk/src/main/java/org/jboss/cache/commands/ReplicableCommand.java
core/trunk/src/main/java/org/jboss/cache/config/Option.java
Log:
Removed dependence on Cloneable where possible.
Modified: core/trunk/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-06-25 13:48:34 UTC (rev 6034)
+++ core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-06-25 14:15:51 UTC (rev 6035)
@@ -82,7 +82,7 @@
* @version $Revision$
*/
@Immutable
-public class Fqn<E> implements Cloneable, Externalizable,
Comparable<Fqn<?>>
+public class Fqn<E> implements Externalizable, Comparable<Fqn<?>>
{
/**
* Separator between FQN elements.
@@ -429,24 +429,6 @@
}
/**
- * Clones the Fqn.
- */
- @Override
- @SuppressWarnings("unchecked")
- public Fqn<E> clone() throws CloneNotSupportedException
- {
- try
- {
- return (Fqn<E>) super.clone();
- }
- catch (CloneNotSupportedException e)
- {
- log.error("Unable to clone Fqn " + this, e);
- return null;
- }
- }
-
- /**
* Returns true if obj is a Fqn with the same elements.
*/
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-06-25 13:48:34
UTC (rev 6034)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-06-25 14:15:51
UTC (rev 6035)
@@ -379,17 +379,26 @@
/**
* This is a "copy-factory-method" that should be used whenever a clone of
this class is needed. The resulting instance
- * is equal() to, but not ==, to the template passed in.
+ * is equal() to, but not ==, to the InvocationContext invoked on. Note that this is
a shallow copy with the exception
+ * of the Option object, which is deep, as well as any collections held on the context
such as locks. Note that the reference
+ * to a TransactionEntry, if any, is maintained.
*
- * @param template template to copy
* @return a new InvocationContext
*/
- public static InvocationContext copy(InvocationContext template)
+ @SuppressWarnings("unchecked")
+ public InvocationContext copy()
{
- // TODO: Remove all use of cloning and replace with copy factory methods.
-// InvocationContext clone = (InvocationContext) super.clone();
-// clone.setOptionOverrides(getOptionOverrides().clone());
-// return clone;
+ InvocationContext copy = new InvocationContext();
+ copy.command = command;
+ copy.globalTransaction = globalTransaction;
+ copy.invocationLocks = invocationLocks == null ? null : new
LinkedHashSet(invocationLocks);
+ copy.localRollbackOnly = localRollbackOnly;
+ copy.lookedUpNodes.putAll(lookedUpNodes);
+ copy.optionOverrides = optionOverrides == null ? null : optionOverrides.copy();
+ copy.originLocal = originLocal;
+ copy.transaction = transaction;
+ copy.transactionEntry = transactionEntry;
+ copy.txHasMods = txHasMods;
return null;
}
Modified: core/trunk/src/main/java/org/jboss/cache/Region.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Region.java 2008-06-25 13:48:34 UTC (rev
6034)
+++ core/trunk/src/main/java/org/jboss/cache/Region.java 2008-06-25 14:15:51 UTC (rev
6035)
@@ -31,7 +31,7 @@
* @see org.jboss.cache.RegionManager
* @since 2.0.0
*/
-public interface Region extends Comparable<Region>, Cloneable
+public interface Region extends Comparable<Region>
{
/**
@@ -214,6 +214,12 @@
*/
Status getStatus();
- Region clone(Fqn cloneFqn);
-
+ /**
+ * copies the region - including eviction queue events - to a new Region instance,
attached to a new Fqn root.
+ * Typically used with Buddy Replication where region roots need to be adjusted.
+ *
+ * @param newRoot new root for the region - e.g., a buddy backup root.
+ * @return a new Region instance.
+ */
+ Region copy(Fqn newRoot);
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-06-25 13:48:34 UTC (rev
6034)
+++ core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-06-25 14:15:51 UTC (rev
6035)
@@ -279,28 +279,18 @@
}
}
- public RegionImpl clone(Fqn newRoot)
+ public Region copy(Fqn newRoot)
{
- RegionImpl clone = null;
- try
+ RegionImpl clone;
+ clone = new RegionImpl(policy, configuration, Fqn.fromRelativeFqn(newRoot, fqn),
regionManager);
+ clone.status = status;
+ // we also need to copy all of the eviction event nodes to the clone's queue
+ clone.createQueue();
+ for (EvictedEventNode een : this.nodeEventQueue)
{
- clone = (RegionImpl) super.clone();
- clone.policy = policy;
- clone.configuration = configuration;
- clone.status = status;
- clone.fqn = Fqn.fromRelativeFqn(newRoot, fqn);
- // we also need to copy all of the eviction event nodes to the clone's
queue
- clone.createQueue();
- for (EvictedEventNode een : this.nodeEventQueue)
- {
- EvictedEventNode cloneEEN = een.clone(newRoot);
- clone.putNodeEvent(cloneEEN);
- }
+ EvictedEventNode cloneEEN = een.copy(newRoot);
+ clone.putNodeEvent(cloneEEN);
}
- catch (CloneNotSupportedException e)
- {
- // problems cloning? Should never get here.
- }
return clone;
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/ReplicableCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/ReplicableCommand.java 2008-06-25
13:48:34 UTC (rev 6034)
+++ core/trunk/src/main/java/org/jboss/cache/commands/ReplicableCommand.java 2008-06-25
14:15:51 UTC (rev 6035)
@@ -10,7 +10,7 @@
* @author Manik Surtani
* @since 2.2.0
*/
-public interface ReplicableCommand extends Cloneable
+public interface ReplicableCommand
{
/**
* Performs the primary function of the command. Please see specific implementation
classes for details on what is
Modified: core/trunk/src/main/java/org/jboss/cache/config/Option.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Option.java 2008-06-25 13:48:34 UTC
(rev 6034)
+++ core/trunk/src/main/java/org/jboss/cache/config/Option.java 2008-06-25 14:15:51 UTC
(rev 6035)
@@ -251,13 +251,34 @@
'}';
}
+ /**
+ * @see #copy()
+ * @deprecated this method may disappear in future, please use copy() instead.
+ */
@Override
+ @Deprecated
public Option clone() throws CloneNotSupportedException
{
return (Option) super.clone();
}
+ /**
+ * @return a new Option instance with all fields shallow-copied.
+ */
+ public Option copy()
+ {
+ try
+ {
+ return (Option) super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ // should never happen
+ return null;
+ }
+ }
+
@Override
public boolean equals(Object o)
{
Show replies by date