JBoss Cache SVN: r6202 - in core/trunk/src/main/java/org/jboss/cache: interceptors and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-07 19:39:38 -0400 (Mon, 07 Jul 2008)
New Revision: 6202
Added:
core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
Log:
Abstracted MVCC locking and wrapping logic into separate helper
Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-07-07 23:13:35 UTC (rev 6201)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-07-07 23:39:38 UTC (rev 6202)
@@ -10,6 +10,7 @@
import org.jboss.cache.lock.LockStrategyFactory;
import org.jboss.cache.marshall.Marshaller;
import org.jboss.cache.marshall.VersionAwareMarshaller;
+import org.jboss.cache.mvcc.MVCCNodeHelper;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.remoting.jgroups.ChannelMessageListener;
import org.jboss.cache.transaction.TransactionTable;
@@ -20,7 +21,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.1.0
*/
-@DefaultFactoryFor(classes = {Notifier.class,
+@DefaultFactoryFor(classes = {Notifier.class, MVCCNodeHelper.class,
ChannelMessageListener.class, CacheLoaderManager.class, Marshaller.class, InvocationContextContainer.class,
CacheInvocationDelegate.class, TransactionTable.class, DataContainer.class,
LockStrategyFactory.class, BuddyFqnTransformer.class})
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-07-07 23:13:35 UTC (rev 6201)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-07-07 23:39:38 UTC (rev 6202)
@@ -1,11 +1,8 @@
package org.jboss.cache.interceptors;
-import org.jboss.cache.CacheException;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
-import org.jboss.cache.InternalNode;
import org.jboss.cache.NodeFactory;
-import org.jboss.cache.NodeSPI;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.read.ExistsCommand;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
@@ -30,17 +27,11 @@
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.interceptors.base.PrePostProcessingCommandInterceptor;
import org.jboss.cache.invocation.InvocationContext;
-import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.lock.LockManager;
-import static org.jboss.cache.lock.LockType.WRITE;
-import org.jboss.cache.lock.TimeoutException;
-import org.jboss.cache.mvcc.NullMarkerNode;
+import org.jboss.cache.mvcc.MVCCNodeHelper;
import org.jboss.cache.mvcc.ReadCommittedNode;
-import java.util.Collections;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
/**
* Interceptor to implement <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">MVCC</a> functionality.
@@ -55,35 +46,23 @@
LockManager lockManager;
DataContainer dataContainer;
NodeFactory nodeFactory;
- private long defaultLockAcquisitionTimeout;
- private boolean lockParentForChildInsertRemove;
+ MVCCNodeHelper helper;
@Inject
- public void setDependencies(LockManager lockManager, DataContainer dataContainer, NodeFactory nodeFactory)
+ public void setDependencies(LockManager lockManager, DataContainer dataContainer, NodeFactory nodeFactory, MVCCNodeHelper helper)
{
this.lockManager = lockManager;
this.dataContainer = dataContainer;
this.nodeFactory = nodeFactory;
+ this.helper = helper;
}
@Start
public void start()
{
allowWriteSkew = configuration.isAllowWriteSkew();
- defaultLockAcquisitionTimeout = configuration.getLockAcquisitionTimeout();
- lockParentForChildInsertRemove = configuration.isLockParentForChildInsertRemove();
}
- private boolean parentLockNeeded(NodeSPI parent)
- {
- return lockParentForChildInsertRemove || (parent != null && parent.isLockForChildInsertRemove());
- }
-
- private boolean parentLockNeeded(Fqn parent)
- {
- return parentLockNeeded(dataContainer.peek(parent, true, true));
- }
-
@Override
protected boolean doBeforeCall(InvocationContext ctx, VisitableCommand command)
{
@@ -97,131 +76,35 @@
@Override
public Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
{
- getWrappedNode(ctx, command.getFqn(), true, true, false); // get the node and stick it in the context.
+ helper.wrapNodeForWriting(ctx, command.getFqn(), true, true, false, false, false); // get the node and stick it in the context.
return invokeNextInterceptor(ctx, command);
}
@Override
public Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
{
- getWrappedNode(ctx, command.getFqn(), true, true, false); // get the node and stick it in the context.
+ helper.wrapNodeForWriting(ctx, command.getFqn(), true, true, false, false, false); // get the node and stick it in the context.
return invokeNextInterceptor(ctx, command);
}
@Override
public Object handlePutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
{
- getWrappedNode(ctx, command.getFqn(), true, true, false); // get the node and stick it in the context.
+ helper.wrapNodeForWriting(ctx, command.getFqn(), true, true, false, false, false); // get the node and stick it in the context.
return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
{
- addNodeAndParentForRemoval(ctx, command.getFqn(), true);
+ helper.wrapNodesForWriting(ctx, command.getFqn());
return invokeNextInterceptor(ctx, command);
}
- private List<Fqn> addNodeAndParentForRemoval(InvocationContext ctx, Fqn nodeFqn, boolean recursive) throws InterruptedException
- {
- // when removing a node we want to get a lock on the Fqn anyway and return the wrapped node.
- if (nodeFqn.isRoot()) throw new CacheException("Attempting to remove Fqn.ROOT!");
-
- Fqn parentFqn = nodeFqn.getParent();
- // inspect parent
- boolean needToCopyParent = false;
- boolean parentLockNeeded = parentLockNeeded(parentFqn);
- if (parentLockNeeded)
- {
- needToCopyParent = lock(ctx, parentFqn);
- // Ensure the node is in the context.
- putNodeInContext(ctx, parentFqn, needToCopyParent);
- }
-
- boolean needToCopyNode = lock(ctx, nodeFqn);
-
- // Ensure the node is in the context.
- putNodeInContext(ctx, nodeFqn, needToCopyNode);
-
- ReadCommittedNode node = (ReadCommittedNode) ctx.lookUpNode(nodeFqn);
-
- // update child ref on parent to point to child as this is now a copy.
- if (node != null && !(node instanceof NullMarkerNode))
- {
- if (parentLockNeeded && (needToCopyNode || needToCopyParent))
- {
- ReadCommittedNode parent = (ReadCommittedNode) ctx.lookUpNode(parentFqn);
- parent.addChildDirect(nodeFactory.createNodeInvocationDelegate((InternalNode) node.getDelegationTarget()));
- }
-
- // now deal with children.
- if (recursive)
- {
- Map childMap = node.getChildrenMapDirect();
- List<Fqn> fqnsToBeRemoved = new LinkedList<Fqn>();
- fqnsToBeRemoved.add(nodeFqn);
- if (childMap == null || childMap.isEmpty()) return fqnsToBeRemoved;
-
- for (Object n : childMap.values())
- {
- NodeSPI child = (NodeSPI) n;
- lockForRemoval(child.getFqn(), recursive, ctx, fqnsToBeRemoved);
- }
-
- return fqnsToBeRemoved;
- }
- }
-
- return null;
- }
-
- private void lockForRemoval(Fqn fqn, boolean isRecursive, InvocationContext ctx, List<Fqn> fqnList) throws InterruptedException
- {
- lock(ctx, fqn); // lock node
- if (fqnList != null) fqnList.add(fqn);
-
- // now wrap and add to the context
- ReadCommittedNode rcn = (ReadCommittedNode) getWrappedNode(ctx, fqn, true, false, true);
- if (rcn != null)
- {
- rcn.copyNodeForUpdate(dataContainer, allowWriteSkew, ctx, nodeFactory);
- ReadCommittedNode parent = (ReadCommittedNode) ctx.lookUpNode(fqn.getParent());
- parent.addChildDirect(nodeFactory.createNodeInvocationDelegate((InternalNode) rcn.getDelegationTarget()));
-
- if (isRecursive)
- {
- Map<Object, NodeSPI> children = rcn.getChildrenMapDirect();
- if (children != null)
- {
- for (NodeSPI child : children.values())
- {
- lockForRemoval(child.getFqn(), isRecursive, ctx, fqnList);
- }
- }
- }
- }
- }
-
- private void putNodeInContext(InvocationContext ctx, Fqn fqn, boolean needToCopyNode)
- {
- ReadCommittedNode node = (ReadCommittedNode) ctx.lookUpNode(fqn);
- if (node == null)
- {
- InternalNode in = dataContainer.peekInternalNode(fqn, false);
- node = nodeFactory.createMvccNode(in);
- ctx.putLookedUpNode(fqn, node);
- }
-
- if (needToCopyNode && node != null && !node.isChanged()) // node could be null if using read-committed
- {
- node.copyNodeForUpdate(dataContainer, allowWriteSkew, ctx, nodeFactory);
- }
- }
-
@Override
public Object handleClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
{
- getWrappedNode(ctx, command.getFqn(), true, false, false);
+ helper.wrapNodeForWriting(ctx, command.getFqn(), true, false, false, false, false);
return invokeNextInterceptor(ctx, command);
}
@@ -230,12 +113,15 @@
{
// set lock acquisition timeout to 0 - we need to fail fast.
ctx.getOptionOverrides().setLockAcquisitionTimeout(0);
- List<Fqn> fqnsToEvict = addNodeAndParentForRemoval(ctx, command.getFqn(), command.isRecursive());
-
- if (fqnsToEvict != null) // add this set to the command
+ if (command.isRecursive())
{
+ List<Fqn> fqnsToEvict = helper.wrapNodesForWriting(ctx, command.getFqn());
command.setNodesToEvict(fqnsToEvict);
}
+ else
+ {
+ helper.wrapNodeForWriting(ctx, command.getFqn(), true, false, false, true, true);
+ }
return invokeNextInterceptor(ctx, command);
}
@@ -245,52 +131,57 @@
{
// this should be handled the same as a recursive evict command.
ctx.getOptionOverrides().setLockAcquisitionTimeout(0);
- addNodeAndParentForRemoval(ctx, command.getFqn(), true);
-
+ helper.wrapNodesForWriting(ctx, command.getFqn());
return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
{
- getWrappedNode(ctx, command.getFqn(), true, false, false);
+ helper.wrapNodeForWriting(ctx, command.getFqn(), true, false, false, false, false);
return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
{
- return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ helper.wrapNodeForReading(ctx, command.getFqn());
+ return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
{
- return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ helper.wrapNodeForReading(ctx, command.getFqn());
+ return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
{
- return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ helper.wrapNodeForReading(ctx, command.getFqn());
+ return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
{
- return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ helper.wrapNodeForReading(ctx, command.getFqn());
+ return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
{
- return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ helper.wrapNodeForReading(ctx, command.getFqn());
+ return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
{
- return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ helper.wrapNodeForReading(ctx, command.getFqn());
+ return invokeNextInterceptor(ctx, command);
}
@Override
@@ -298,13 +189,13 @@
{
// nodes we need to get WLs for:
// node we are moving FROM (and it's parent and children.) Same as removeNode.
- List<Fqn> nodeAndChildren = addNodeAndParentForRemoval(ctx, command.getFqn(), true);
+ List<Fqn> nodeAndChildren = helper.wrapNodesForWriting(ctx, command.getFqn());
Fqn newParent = command.getTo();
Fqn oldParent = command.getFqn().getParent();
// now lock the new parent.
- getWrappedNode(ctx, newParent, true, true, false);
+ helper.wrapNodeForWriting(ctx, newParent, true, true, false, false, false);
if (!oldParent.equals(newParent) && nodeAndChildren != null)
{
@@ -313,7 +204,7 @@
for (Fqn f : nodeAndChildren)
{
Fqn newChildFqn = f.replaceAncestor(oldParent, newParent);
- getWrappedNode(ctx, newChildFqn, true, true, true);
+ helper.wrapNodeForWriting(ctx, newChildFqn, true, true, true, false, false);
}
}
@@ -324,13 +215,14 @@
@Override
public Object handleGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
{
- return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ helper.wrapNodeForReading(ctx, command.getFqn());
+ return invokeNextInterceptor(ctx, command);
}
@Override
public Object handleCreateNodeCommand(InvocationContext ctx, CreateNodeCommand command) throws Throwable
{
- getWrappedNode(ctx, command.getFqn(), true, true, false); // get the node and stick it in the context.
+ helper.wrapNodeForWriting(ctx, command.getFqn(), true, true, false, false, false); // get the node and stick it in the context.
return invokeNextInterceptor(ctx, command);
}
@@ -439,148 +331,4 @@
throw new IllegalStateException("Attempting to do a commit or rollback but there is no transactional context in scope. " + ctx);
}
}
-
- // ----------------- actual implementation details ----------------------------
-
- protected Object handleReadCommand(InvocationContext ctx, VisitableCommand command, List<Fqn> fqns) throws Throwable
- {
- boolean forceWriteLock = ctx.getOptionOverrides().isForceWriteLock();
-
- // does the node exist in the context?
- for (Fqn f : fqns)
- {
- if (forceWriteLock)
- {
- if (trace) log.trace("Forcing lock on reading node " + f);
- getWrappedNode(ctx, f, true, false, false);
- }
- else if (ctx.lookUpNode(f) == null)
- {
- if (trace) log.trace("Node " + f + " is not in context, fetching from container.");
- // simple implementation. Peek the node, wrap it, put wrapped node in the context.
- InternalNode node = dataContainer.peekInternalNode(f, false);
- NodeSPI wrapped = nodeFactory.createMvccNode(node);
- if (wrapped != null) ctx.putLookedUpNode(f, wrapped);
- }
- else
- {
- if (trace) log.trace("Node " + f + " is already in context.");
- }
- }
- return invokeNextInterceptor(ctx, command);
- }
-
- /**
- * First checks in contexts for the existence of the node. If it does exist, it will return it, acquiring a lock if
- * necessary. Otherwise, it will peek in the dataContainer, wrap the node, lock if necessary, and add it to the context.
- * If it doesn't even exist in the dataContainer and createIfAbsent is true, it will create a new node and add it to the
- * data structure. It will lock the node, and potentially the parent as well, if necessary. If the parent is locked,
- * it too will be added to the context if it wasn't there already.
- *
- * @param fqn to retrieve
- * @param lockForWriting if true, a lock will be acquired.
- * @param createIfAbsent if true, will be created if absent.
- * @param includeInvalidNodes
- * @return a NodeSPI or null.
- */
- protected NodeSPI getWrappedNode(InvocationContext context, Fqn fqn, boolean lockForWriting, boolean createIfAbsent, boolean includeInvalidNodes) throws InterruptedException
- {
- ReadCommittedNode n = (ReadCommittedNode) context.lookUpNode(fqn);
- if (createIfAbsent && n != null && n.isNullNode()) n = null;
- if (n != null)
- {
- // acquire lock if needed
- if (lockForWriting && lock(context, fqn))
- {
- // create a copy of the underlying node
- n.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
- }
- if (trace) log.trace("Retrieving wrapped node " + fqn);
- if (n.isDeleted() && createIfAbsent)
- {
- if (trace) log.trace("Node is deleted in current scope. Need to un-delete.");
- n.markAsDeleted(false);
- n.setValid(true, false);
- }
- return n;
- }
-
- // else, fetch from dataContainer.
- InternalNode in = dataContainer.peekInternalNode(fqn, includeInvalidNodes);
- if (in != null)
- {
- // do we need a lock?
- boolean needToCopy = false;
- if (lockForWriting && lock(context, fqn))
- {
- needToCopy = true;
- }
- ReadCommittedNode wrapped = nodeFactory.createMvccNode(in);
- context.putLookedUpNode(fqn, wrapped);
- if (needToCopy)
- wrapped.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
- return wrapped;
- }
-
- // else, do we need to create one?
- if (createIfAbsent)
- {
- Fqn parentFqn = fqn.getParent();
- NodeSPI parent = getWrappedNode(context, parentFqn, false, createIfAbsent, false);
- // do we need to lock the parent to create children?
- boolean parentLockNeeded = parentLockNeeded(parent);
- // get a lock on the parent.
- if (parentLockNeeded && lock(context, parentFqn))
- {
- ReadCommittedNode parentRCN = (ReadCommittedNode) context.lookUpNode(parentFqn);
- parentRCN.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
- }
-
- // now to lock and create the node.
- lock(context, fqn);
-
- NodeSPI temp = parent.getOrCreateChild(fqn.getLastElement(), context.getGlobalTransaction());
- // TODO: warning, hack! There is a race condition here. Add a way to create nodes without attaching to a parent.
- parent.removeChildDirect(fqn.getLastElement());
-
- in = (InternalNode) ((NodeInvocationDelegate) temp).getDelegationTarget();
- ReadCommittedNode wrapped = nodeFactory.createMvccNode(in);
- wrapped.setCreated(true);
- context.putLookedUpNode(fqn, wrapped);
- wrapped.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
-// if (parentLockNeeded)
-// {
-// // since we copied the child make sure we update the parent's ref
-// parent.addChildDirect(nodeFactory.createNodeInvocationDelegate(wrapped.getNode()));
-// }
-
- return wrapped;
- }
-
- return null;
- }
-
- /**
- * Attempts to lock a node if the lock isn't already held in the current scope.
- *
- * @param ctx context
- * @param fqn Fqn to lock
- * @return true if a lock was needed and acquired, false if it didn't need to acquire the lock (i.e., lock was already held)
- * @throws InterruptedException
- * @throws TimeoutException if we are unable to acquire the lock after a specified timeout.
- */
- protected boolean lock(InvocationContext ctx, Fqn fqn) throws InterruptedException
- {
- // don't EVER use lockManager.isLocked() since with lock striping it may be the case that we hold the relevant
- // lock which may be shared with another Fqn that we have a lock for already.
- // nothing wrong, just means that we fail to record the lock. And that is a problem.
- // Better to check our records and lock again if necessary.
- if (!ctx.getLocks().contains(fqn))
- {
- if (!lockManager.lockAndRecord(fqn, WRITE, ctx))
- throw new TimeoutException("Unable to acquire lock on Fqn [" + fqn + "] after [" + ctx.getLockAcquisitionTimeout(defaultLockAcquisitionTimeout) + "] milliseconds!");
- return true;
- }
- return false;
- }
}
Added: core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java 2008-07-07 23:39:38 UTC (rev 6202)
@@ -0,0 +1,345 @@
+package org.jboss.cache.mvcc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InternalNode;
+import org.jboss.cache.NodeFactory;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.NonVolatile;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.invocation.InvocationContext;
+import org.jboss.cache.invocation.NodeInvocationDelegate;
+import org.jboss.cache.lock.LockManager;
+import static org.jboss.cache.lock.LockType.WRITE;
+import org.jboss.cache.lock.TimeoutException;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Utility functions to manipulate wrapping {@link org.jboss.cache.InternalNode}s as {@link org.jboss.cache.mvcc.ReadCommittedNode}
+ * or {@link org.jboss.cache.mvcc.RepeatableReadNode}s. Would also entail locking, if necessary.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+@NonVolatile
+public class MVCCNodeHelper
+{
+ DataContainer dataContainer;
+ NodeFactory nodeFactory;
+ private static final Log log = LogFactory.getLog(MVCCNodeHelper.class);
+ private static final boolean trace = log.isTraceEnabled();
+ private long defaultLockAcquisitionTimeout;
+ private LockManager lockManager;
+ private Configuration configuration;
+ private boolean allowWriteSkew;
+ private boolean lockParentForChildInsertRemove;
+
+ @Inject
+ public void injectDependencies(DataContainer dataContainer, NodeFactory nodeFactory, LockManager lockManager, Configuration configuration)
+ {
+ this.nodeFactory = nodeFactory;
+ this.dataContainer = dataContainer;
+ this.configuration = configuration;
+ this.lockManager = lockManager;
+ }
+
+ @Start
+ public void start()
+ {
+ defaultLockAcquisitionTimeout = configuration.getLockAcquisitionTimeout();
+ allowWriteSkew = configuration.isAllowWriteSkew();
+ lockParentForChildInsertRemove = configuration.isLockParentForChildInsertRemove();
+ }
+
+
+ /**
+ * Attempts to provide the context with a set of wrapped nodes based on the Collection of fqns passed in. If the nodes
+ * already exist in the context then the node is not wrapped again.
+ * <p/>
+ * {@link InternalNode}s are wrapped using {@link NodeFactory#createMvccNode(org.jboss.cache.InternalNode)} and as such,
+ * null internal nodes are treated according to isolation level used. See {@link NodeFactory#createMvccNode(org.jboss.cache.InternalNode)}
+ * for details on this behaviour.
+ * <p/>
+ * Note that if the context has the {@link org.jboss.cache.config.Option#isForceWriteLock()} option set, then write locks are
+ * acquired and the node is copied.
+ * <p/>
+ *
+ * @param ctx current invocation context
+ * @param fqns collection of Fqns. Should not be null.
+ * @throws InterruptedException if write locks are forced and the lock manager is interrupted.
+ */
+ public void wrapNodesForReading(InvocationContext ctx, Collection<Fqn> fqns) throws InterruptedException
+ {
+ boolean forceWriteLock = ctx.getOptionOverrides().isForceWriteLock();
+
+ // does the node exist in the context?
+ for (Fqn f : fqns) wrapNodeForReading(ctx, f, forceWriteLock);
+ }
+
+ /**
+ * Similar to {@link #wrapNodesForReading(org.jboss.cache.invocation.InvocationContext, java.util.Collection)} except
+ * that this version takes a single Fqn parameter to wrap a single node.
+ *
+ * @param ctx current invocation context
+ * @param fqn fqn to fetch and wrap
+ * @throws InterruptedException if write locks are forced and the lock manager is interrupted.
+ */
+ public void wrapNodeForReading(InvocationContext ctx, Fqn fqn) throws InterruptedException
+ {
+ wrapNodeForReading(ctx, fqn, ctx.getOptionOverrides().isForceWriteLock());
+ }
+
+ private void wrapNodeForReading(InvocationContext ctx, Fqn f, boolean writeLockForced) throws InterruptedException
+ {
+ if (writeLockForced)
+ {
+ if (trace) log.trace("Forcing lock on reading node " + f);
+ wrapNodeForWriting(ctx, f, true, false, false, false, false);
+ }
+ else if (ctx.lookUpNode(f) == null)
+ {
+ if (trace) log.trace("Node " + f + " is not in context, fetching from container.");
+ // simple implementation. Peek the node, wrap it, put wrapped node in the context.
+ InternalNode node = dataContainer.peekInternalNode(f, false);
+ ReadCommittedNode wrapped = nodeFactory.createMvccNode(node);
+ if (wrapped != null) ctx.putLookedUpNode(f, wrapped);
+ }
+ else
+ {
+ if (trace) log.trace("Node " + f + " is already in context.");
+ }
+ }
+
+ /**
+ * Attempts to lock a node if the lock isn't already held in the current scope, and records the lock in the context.
+ *
+ * @param ctx context
+ * @param fqn Fqn to lock
+ * @return true if a lock was needed and acquired, false if it didn't need to acquire the lock (i.e., lock was already held)
+ * @throws InterruptedException if interrupted
+ * @throws TimeoutException if we are unable to acquire the lock after a specified timeout.
+ */
+ private boolean acquireLock(InvocationContext ctx, Fqn fqn) throws InterruptedException, TimeoutException
+ {
+ // don't EVER use lockManager.isLocked() since with lock striping it may be the case that we hold the relevant
+ // lock which may be shared with another Fqn that we have a lock for already.
+ // nothing wrong, just means that we fail to record the lock. And that is a problem.
+ // Better to check our records and lock again if necessary.
+ if (!ctx.getLocks().contains(fqn))
+ {
+ if (!lockManager.lockAndRecord(fqn, WRITE, ctx))
+ throw new TimeoutException("Unable to acquire lock on Fqn [" + fqn + "] after [" + ctx.getLockAcquisitionTimeout(defaultLockAcquisitionTimeout) + "] milliseconds!");
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * First checks in contexts for the existence of the node. If it does exist, it will return it, acquiring a lock if
+ * necessary. Otherwise, it will peek in the dataContainer, wrap the node, lock if necessary, and add it to the context.
+ * If it doesn't even exist in the dataContainer and createIfAbsent is true, it will create a new node and add it to the
+ * data structure. It will lock the node, and potentially the parent as well, if necessary. If the parent is locked,
+ * it too will be added to the context if it wasn't there already.
+ *
+ * @param fqn to retrieve
+ * @param lockForWriting if true, a lock will be acquired.
+ * @param createIfAbsent if true, will be created if absent.
+ * @param includeInvalidNodes if true, invalid nodes are included.
+ * @param forRemoval if true, the parent may also be locked if locking parents for removal is necessary.
+ * @param force if true, will force the write lock even if the node is null.
+ * @return a wrapped node, or null.
+ */
+ public ReadCommittedNode wrapNodeForWriting(InvocationContext context, Fqn fqn, boolean lockForWriting, boolean createIfAbsent, boolean includeInvalidNodes, boolean forRemoval, boolean force) throws InterruptedException
+ {
+ ReadCommittedNode n = (ReadCommittedNode) context.lookUpNode(fqn);
+ if (createIfAbsent && n != null && n.isNullNode()) n = null;
+ if (n != null)
+ {
+ // acquire lock if needed
+ if (lockForWriting && acquireLock(context, fqn))
+ {
+ // create a copy of the underlying node
+ n.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
+ }
+ if (trace) log.trace("Retrieving wrapped node " + fqn);
+ if (n.isDeleted() && createIfAbsent)
+ {
+ if (trace) log.trace("Node is deleted in current scope. Need to un-delete.");
+ n.markAsDeleted(false);
+ n.setValid(true, false);
+ }
+
+ }
+ else
+ {
+ // else, fetch from dataContainer.
+ InternalNode in = dataContainer.peekInternalNode(fqn, includeInvalidNodes);
+ if (in != null)
+ {
+ // do we need a lock?
+ boolean needToCopy = false;
+ if (lockForWriting && acquireLock(context, fqn))
+ {
+ needToCopy = true;
+ }
+ n = nodeFactory.createMvccNode(in);
+ context.putLookedUpNode(fqn, n);
+ if (needToCopy) n.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
+ }
+ else if (createIfAbsent) // else, do we need to create one?
+ {
+ Fqn parentFqn = fqn.getParent();
+ NodeSPI parent = wrapNodeForWriting(context, parentFqn, false, createIfAbsent, false, false, false);
+ // do we need to lock the parent to create children?
+ boolean parentLockNeeded = isParentLockNeeded(parent);
+ // get a lock on the parent.
+ if (parentLockNeeded && acquireLock(context, parentFqn))
+ {
+ ReadCommittedNode parentRCN = (ReadCommittedNode) context.lookUpNode(parentFqn);
+ parentRCN.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
+ }
+
+ // now to lock and create the node.
+ acquireLock(context, fqn);
+
+ NodeSPI temp = parent.getOrCreateChild(fqn.getLastElement(), context.getGlobalTransaction());
+ // TODO: warning, hack! There is a race condition here. Add a way to create nodes without attaching to a parent.
+ parent.removeChildDirect(fqn.getLastElement());
+
+ in = (InternalNode) ((NodeInvocationDelegate) temp).getDelegationTarget();
+ n = nodeFactory.createMvccNode(in);
+ n.setCreated(true);
+ context.putLookedUpNode(fqn, n);
+ n.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
+ }
+ }
+
+ // see if we need to force the lock on nonexistent nodes.
+ if (n == null && force) acquireLock(context, fqn);
+
+ // now test if we need to lock the parent as well.
+ if ((n != null || force) && forRemoval && isParentLockNeeded(fqn.getParent(), context))
+ wrapNodeForWriting(context, fqn.getParent(), true, false, includeInvalidNodes, false, force);
+
+ return n;
+ }
+
+ /**
+ * Wraps a node and all its subnodes and adds them to the context, acquiring write locks for them all.
+ *
+ * @param ctx context
+ * @param fqn fqn to wrap
+ * @return a list of Fqns of locks acquired in this call.
+ * @throws InterruptedException if the lock manager is interrupted.
+ */
+ public List<Fqn> wrapNodesForWriting(InvocationContext ctx, Fqn fqn) throws InterruptedException
+ {
+ // when removing a node we want to get a lock on the Fqn anyway and return the wrapped node.
+ if (fqn.isRoot()) throw new CacheException("Attempting to remove Fqn.ROOT!");
+
+ Fqn parentFqn = fqn.getParent();
+ // inspect parent
+ boolean needToCopyParent = false;
+ boolean parentLockNeeded = isParentLockNeeded(parentFqn, ctx);
+ if (parentLockNeeded)
+ {
+ needToCopyParent = acquireLock(ctx, parentFqn);
+ // Ensure the node is in the context.
+ putNodeInContext(ctx, parentFqn, needToCopyParent);
+ }
+
+ boolean needToCopyNode = acquireLock(ctx, fqn);
+
+ // Ensure the node is in the context.
+ putNodeInContext(ctx, fqn, needToCopyNode);
+
+ ReadCommittedNode node = (ReadCommittedNode) ctx.lookUpNode(fqn);
+
+ // update child ref on parent to point to child as this is now a copy.
+ if (node != null && !(node instanceof NullMarkerNode))
+ {
+ if (parentLockNeeded && (needToCopyNode || needToCopyParent))
+ {
+ ReadCommittedNode parent = (ReadCommittedNode) ctx.lookUpNode(parentFqn);
+ parent.addChildDirect(nodeFactory.createNodeInvocationDelegate((InternalNode) node.getDelegationTarget()));
+ }
+
+ // now deal with children.
+ Map childMap = node.getChildrenMapDirect();
+ List<Fqn> fqnsToBeRemoved = new LinkedList<Fqn>();
+ fqnsToBeRemoved.add(fqn);
+ if (childMap == null || childMap.isEmpty()) return fqnsToBeRemoved;
+
+ for (Object n : childMap.values())
+ {
+ NodeSPI child = (NodeSPI) n;
+ lockForWritingRecursive(child.getFqn(), ctx, fqnsToBeRemoved);
+ }
+
+ return fqnsToBeRemoved;
+ }
+
+ return null;
+ }
+
+ private void lockForWritingRecursive(Fqn fqn, InvocationContext ctx, List<Fqn> fqnList) throws InterruptedException
+ {
+ acquireLock(ctx, fqn); // lock node
+ if (fqnList != null) fqnList.add(fqn);
+
+ // now wrap and add to the context
+ ReadCommittedNode rcn = wrapNodeForWriting(ctx, fqn, true, false, true, false, false);
+ if (rcn != null)
+ {
+ rcn.copyNodeForUpdate(dataContainer, allowWriteSkew, ctx, nodeFactory);
+ ReadCommittedNode parent = (ReadCommittedNode) ctx.lookUpNode(fqn.getParent());
+ parent.addChildDirect(nodeFactory.createNodeInvocationDelegate((InternalNode) rcn.getDelegationTarget()));
+
+ Map<Object, NodeSPI> children = rcn.getChildrenMapDirect();
+ if (children != null)
+ {
+ for (NodeSPI child : children.values())
+ {
+ lockForWritingRecursive(child.getFqn(), ctx, fqnList);
+ }
+ }
+ }
+ }
+
+ private void putNodeInContext(InvocationContext ctx, Fqn fqn, boolean needToCopyNode)
+ {
+ ReadCommittedNode node = (ReadCommittedNode) ctx.lookUpNode(fqn);
+ if (node == null)
+ {
+ InternalNode in = dataContainer.peekInternalNode(fqn, false);
+ node = nodeFactory.createMvccNode(in);
+ ctx.putLookedUpNode(fqn, node);
+ }
+
+ if (needToCopyNode && node != null && !node.isChanged()) // node could be null if using read-committed
+ {
+ node.copyNodeForUpdate(dataContainer, allowWriteSkew, ctx, nodeFactory);
+ }
+ }
+
+ private boolean isParentLockNeeded(NodeSPI parent)
+ {
+ return lockParentForChildInsertRemove || (parent != null && parent.isLockForChildInsertRemove());
+ }
+
+ private boolean isParentLockNeeded(Fqn parent, InvocationContext ctx)
+ {
+ NodeSPI parentNode = ctx.lookUpNode(parent);
+ if (parentNode == null) parentNode = dataContainer.peek(parent, true, true);
+ return isParentLockNeeded(parentNode);
+ }
+}
15 years, 10 months
JBoss Cache SVN: r6201 - in core/trunk/src: main/java/org/jboss/cache/config/parsing and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-07-07 19:13:35 -0400 (Mon, 07 Jul 2008)
New Revision: 6201
Added:
core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlSchemaTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/config/CustomInterceptorConfig.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
core/trunk/src/main/resources/all-elements-file-3.x.xml
core/trunk/src/main/resources/config-samples/buddy-replication.xml
core/trunk/src/main/resources/jbosscache-config.xsd
core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
core/trunk/src/test/resources/configs/buddy-replication-cache.xml
core/trunk/src/test/resources/configs/clonable-config.xml
core/trunk/src/test/resources/configs/local-lru-eviction.xml
core/trunk/src/test/resources/configs/local-passivation.xml
core/trunk/src/test/resources/configs/local-tx.xml
core/trunk/src/test/resources/configs/mixedPolicy-eviction.xml
core/trunk/src/test/resources/configs/mux.xml
core/trunk/src/test/resources/configs/parser-test.xml
core/trunk/src/test/resources/configs/policyPerRegion-eviction.xml
core/trunk/src/test/resources/configs/replSync.xml
Log:
more elaborated xml schema + unit tests
Modified: core/trunk/src/main/java/org/jboss/cache/config/CustomInterceptorConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CustomInterceptorConfig.java 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/main/java/org/jboss/cache/config/CustomInterceptorConfig.java 2008-07-07 23:13:35 UTC (rev 6201)
@@ -9,6 +9,7 @@
/**
* Holds information about the custom interceptors defined in the configuration file.
+ * todo : As a tip on your CustomInterceptorConfig, you should consider extending ConfigurationComponent which gives you a lot of the basic stuff you need.
*
* @author Mircea.Markus(a)jboss.com
* @since 3.0
Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-07-07 23:13:35 UTC (rev 6201)
@@ -10,6 +10,9 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -32,8 +35,25 @@
private Configuration config = new Configuration();
private Element root;
+ private ErrorHandler errorHandler;
+ private boolean isValidating = true;
+ public XmlConfigurationParser(ErrorHandler errorHandler)
+ {
+ this.errorHandler = errorHandler;
+ }
+ public XmlConfigurationParser(boolean validating, ErrorHandler errorHandler)
+ {
+ isValidating = validating;
+ this.errorHandler = errorHandler;
+ }
+
+ public XmlConfigurationParser()
+ {
+ this(new LoggingErrorHandler());
+ }
+
/**
* Parses an XML file and returns a new configuration. This method attempts to look for the file name passed in on
* the classpath. If not found, it will search for the file on the file system instead, treating the name as an
@@ -304,13 +324,42 @@
try
{
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ if (isValidating)
+ {
+ docBuilderFactory.setValidating(true);
+ docBuilderFactory.setNamespaceAware(true);
+ docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
+ }
DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
+ parser.setErrorHandler(errorHandler);
Document doc = parser.parse(config);
root = doc.getDocumentElement();
root.normalize();
} catch (Exception e)
{
- throw new ConfigurationException("Could not parseStream the ");
+ log.error(e);
+ throw new ConfigurationException("Could not parseStream the config file");
}
}
+
+ /**
+ * Default schema validation error handler, that only logs validation exceptions.
+ */
+ private static class LoggingErrorHandler implements ErrorHandler
+ {
+ public void warning(SAXParseException exception) throws SAXException
+ {
+ log.warn("Configuration warning: " + exception.getMessage());
+ }
+
+ public void error(SAXParseException exception) throws SAXException
+ {
+ log.warn("Configuration error: " + exception.getMessage());
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException
+ {
+ log.warn("Configuration fatal error : " + exception.getMessage());
+ }
+ }
}
Modified: core/trunk/src/main/resources/all-elements-file-3.x.xml
===================================================================
--- core/trunk/src/main/resources/all-elements-file-3.x.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/main/resources/all-elements-file-3.x.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
<locking isolationLevel="REPEATABLE_READ" lockParentForChildInsertRemove="true" lockAcquisitionTimeout="10234"
nodeLockingScheme="mvcc" allowWriteSkew="true" concurrencyLevel="21"/>
@@ -15,6 +16,7 @@
<!-- either replication or invalidation tags will be present, not both -->
<replication>
<sync replTimeout="15421"/>
+ <async useReplQueue="false" replQueueInterval="12" replQueueMaxElements="12345"/>
<buddy enabled="true" poolName="myBuddyPoolReplicationGroup" communicationTimeout="2000">
<dataGravitation auto="true" removeOnFind="true" searchBackupTrees="true"/>
<locator class="org.jboss.cache.buddyreplication.NextMemberBuddyLocator">
@@ -28,8 +30,6 @@
<!-- either replication or invalidation tags will be present, not both -->
<invalidation>
- <!-- either sync or async will be present, not both -->
- <async useReplQueue="false" replQueueInterval="12" replQueueMaxElements="12345"/>
<sync replTimeout="15421"/>
</invalidation>
@@ -64,6 +64,7 @@
<root>
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
+ <attribute name="timeToLive">1000</attribute>
</root>
<region name="/org/jboss/data">
<attribute name="timeToLive">1002</attribute>
Modified: core/trunk/src/main/resources/config-samples/buddy-replication.xml
===================================================================
--- core/trunk/src/main/resources/config-samples/buddy-replication.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/main/resources/config-samples/buddy-replication.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -3,7 +3,9 @@
<!-- todo mmarkus add comments to sample config files (after DTD is written) -->
<!-- todo mmarkus include the DTD file in all configs -->
-<jbosscache>
+<jbosscache xmlns="http://www.jboss.org/jbosscache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.jboss.org/jbosscache ../jbosscache-config.xsd">
+
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<startup stateRetrievalTimeout="20000"/>
Modified: core/trunk/src/main/resources/jbosscache-config.xsd
===================================================================
--- core/trunk/src/main/resources/jbosscache-config.xsd 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/main/resources/jbosscache-config.xsd 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,362 +1,245 @@
<?xml version="1.0" encoding="UTF-8"?>
-<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:element name="jbosscache" type="jbosscacheType"/>
- <xs:complexType name="FRAG2Type">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="frag_size"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="dataGravitationType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="auto"/>
- <xs:attribute type="xs:string" name="removeOnFind"/>
- <xs:attribute type="xs:string" name="searchBackupTrees"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="pbcast.STREAMING_STATE_TRANSFERType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="use_reading_thread"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="positionType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="first" use="optional"/>
- <xs:attribute type="xs:string" name="last" use="optional"/>
- <xs:attribute type="xs:string" name="index" use="optional"/>
- <xs:attribute type="xs:string" name="before" use="optional"/>
- <xs:attribute type="xs:string" name="after" use="optional"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="rootType">
- <xs:sequence>
- <xs:element type="attributeType" name="attribute" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="evictionType">
- <xs:sequence>
- <xs:element type="defaultsType" name="defaults"/>
- <xs:element type="rootType" name="root"/>
- <xs:element type="regionType" name="region" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="wakeUpInterval"/>
- </xs:complexType>
- <xs:complexType name="lockingType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="isolationLevel"/>
- <xs:attribute type="xs:string" name="lockParentForChildInsertRemove"/>
- <xs:attribute type="xs:string" name="lockAcquisitionTimeout"/>
- <xs:attribute type="xs:string" name="nodeLockingScheme"/>
- <xs:attribute type="xs:string" name="allowWriteSkew"/>
- <xs:attribute type="xs:string" name="concurrencyLevel"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="jmxStatisticsType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="enabled"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="defaultsType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="policyClass"/>
- <xs:attribute type="xs:string" name="eventQueueSize"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="transactionType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="transactionManagerLookupClass"/>
- <xs:attribute type="xs:string" name="syncRollbackPhase"/>
- <xs:attribute type="xs:string" name="syncCommitPhase"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="pbcast.FLUSHType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="timeout"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="pbcast.STABLEType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="stability_delay"/>
- <xs:attribute type="xs:string" name="desired_avg_gossip"/>
- <xs:attribute type="xs:string" name="max_bytes"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="transportType">
- <xs:sequence>
- <xs:element type="jgroupsConfigType" name="jgroupsConfig"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="clusterName"/>
- <xs:attribute type="xs:string" name="multiplexerStack"/>
- </xs:complexType>
- <xs:complexType name="regionType">
- <xs:sequence>
- <xs:element type="attributeType" name="attribute" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="name" use="optional"/>
- <xs:attribute type="xs:string" name="policyClass" use="optional"/>
- <xs:attribute type="xs:string" name="eventQueueSize" use="optional"/>
- </xs:complexType>
- <xs:complexType name="jgroupsConfigType">
- <xs:sequence>
- <xs:element type="PINGType" name="PING"/>
- <xs:element type="MERGE2Type" name="MERGE2"/>
- <xs:element type="xs:string" name="FD_SOCK"/>
- <xs:element type="FDType" name="FD"/>
- <xs:element type="VERIFY_SUSPECTType" name="VERIFY_SUSPECT"/>
- <xs:element type="pbcast.NAKACKType" name="pbcast.NAKACK"/>
- <xs:element type="UNICASTType" name="UNICAST"/>
- <xs:element type="pbcast.STABLEType" name="pbcast.STABLE"/>
- <xs:element type="pbcast.GMSType" name="pbcast.GMS"/>
- <xs:element type="FRAG2Type" name="FRAG2"/>
- <xs:element type="pbcast.STREAMING_STATE_TRANSFERType" name="pbcast.STREAMING_STATE_TRANSFER"/>
- <xs:element type="pbcast.FLUSHType" name="pbcast.FLUSH"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="shutdownType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="hookBehavior"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="asyncType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="useReplQueue"/>
- <xs:attribute type="xs:string" name="replQueueInterval"/>
- <xs:attribute type="xs:string" name="replQueueMaxElements"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="serializationType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="objectInputStreamPoolSize"/>
- <xs:attribute type="xs:string" name="objectOutputStreamPoolSize"/>
- <xs:attribute type="xs:string" name="version"/>
- <xs:attribute type="xs:string" name="marshallerClass"/>
- <xs:attribute type="xs:string" name="useLazyDeserialization"/>
- <xs:attribute type="xs:string" name="useRegionBasedMarshalling"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="customInterceptorsType">
- <xs:sequence>
- <xs:element type="interceptorType" name="interceptor" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="startupType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="fetchInMemoryState"/>
- <xs:attribute type="xs:string" name="stateRetrievalTimeout"/>
- <xs:attribute type="xs:string" name="inactiveOnStartup"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="pbcast.GMSType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="print_local_addr"/>
- <xs:attribute type="xs:string" name="join_timeout"/>
- <xs:attribute type="xs:string" name="shun"/>
- <xs:attribute type="xs:string" name="view_bundling"/>
- <xs:attribute type="xs:string" name="view_ack_collection_timeout"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="UNICASTType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="timeout"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="jbosscacheType">
- <xs:sequence>
- <xs:element type="lockingType" name="locking"/>
- <xs:element type="transactionType" name="transaction"/>
- <xs:element type="serializationType" name="serialization">
- <xs:annotation>
- <xs:documentation>serialization related configuration, used for replication and cache loading</xs:documentation>
- </xs:annotation>
- </xs:element>
- <xs:element type="replicationType" name="replication">
- <xs:annotation>
- <xs:documentation>either replication or invalidation tags will be present, not both</xs:documentation>
- </xs:annotation>
- </xs:element>
- <xs:element type="invalidationType" name="invalidation">
- <xs:annotation>
- <xs:documentation>either replication or invalidation tags will be present, not both</xs:documentation>
- </xs:annotation>
- </xs:element>
- <xs:element type="startupType" name="startup"/>
- <xs:element type="shutdownType" name="shutdown"/>
- <xs:element type="jmxStatisticsType" name="jmxStatistics"/>
- <xs:element type="transportType" name="transport"/>
- <xs:element type="evictionType" name="eviction"/>
- <xs:element type="loadersType" name="loaders"/>
- <xs:element type="customInterceptorsType" name="customInterceptors">
- <xs:annotation>
- <xs:documentation>this is new behavior added within 3.x only. it support configuring custom interceptors through configurations</xs:documentation>
- </xs:annotation>
- </xs:element>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="attributeType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="name" use="optional"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="PINGType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="timeout"/>
- <xs:attribute type="xs:string" name="num_initial_members"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="nodeType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="fqn" use="optional"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="invalidationType">
- <xs:sequence>
- <xs:element type="asyncType" name="async">
- <xs:annotation>
- <xs:documentation>either sync or async will be present, not both</xs:documentation>
- </xs:annotation>
- </xs:element>
- <xs:element type="syncType" name="sync"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="loaderType">
- <xs:sequence>
- <xs:element type="xs:string" name="properties"/>
- <xs:element type="singletonStoreType" name="singletonStore"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="class"/>
- <xs:attribute type="xs:string" name="async"/>
- <xs:attribute type="xs:string" name="fetchPersistentState"/>
- <xs:attribute type="xs:string" name="ignoreModifications"/>
- <xs:attribute type="xs:string" name="purgeOnStartup"/>
- </xs:complexType>
- <xs:complexType name="replicationType">
- <xs:sequence>
- <xs:element type="syncType" name="sync"/>
- <xs:element type="buddyType" name="buddy"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="interceptorType">
- <xs:sequence>
- <xs:element type="xs:string" name="properties" minOccurs="0"/>
- <xs:element type="positionType" name="position"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="class" use="optional"/>
- </xs:complexType>
- <xs:complexType name="buddyType">
- <xs:sequence>
- <xs:element type="dataGravitationType" name="dataGravitation"/>
- <xs:element type="locatorType" name="locator"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="enabled"/>
- <xs:attribute type="xs:string" name="poolName"/>
- <xs:attribute type="xs:string" name="communicationTimeout"/>
- </xs:complexType>
- <xs:complexType name="locatorType">
- <xs:sequence>
- <xs:element type="xs:string" name="properties"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="class"/>
- </xs:complexType>
- <xs:complexType name="pbcast.NAKACKType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="use_mcast_xmit"/>
- <xs:attribute type="xs:string" name="gc_lag"/>
- <xs:attribute type="xs:string" name="retransmit_timeout"/>
- <xs:attribute type="xs:string" name="discard_delivered_msgs"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="preloadType">
- <xs:sequence>
- <xs:element type="nodeType" name="node" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="MERGE2Type">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="max_interval"/>
- <xs:attribute type="xs:string" name="min_interval"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="VERIFY_SUSPECTType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="timeout"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="syncType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="replTimeout" use="optional"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="FDType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute type="xs:string" name="timeout"/>
- <xs:attribute type="xs:string" name="max_tries"/>
- <xs:attribute type="xs:string" name="shun"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- <xs:complexType name="singletonStoreType">
- <xs:sequence>
- <xs:element type="xs:string" name="properties"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="enabled"/>
- <xs:attribute type="xs:string" name="class"/>
- </xs:complexType>
- <xs:complexType name="loadersType">
- <xs:sequence>
- <xs:element type="preloadType" name="preload"/>
- <xs:element type="loaderType" name="loader">
- <xs:annotation>
- <xs:documentation>we can now have multiple cache loaders, which get chained</xs:documentation>
- </xs:annotation>
- </xs:element>
- </xs:sequence>
- <xs:attribute type="xs:string" name="passivation"/>
- <xs:attribute type="xs:string" name="shared"/>
- </xs:complexType>
-</xs:schema>
\ No newline at end of file
+<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="jbosscache">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="locking" type="lockingType" minOccurs="0"/>
+ <xs:element name="transaction" type="transactionType" minOccurs="0"/>
+ <xs:element name="startup" type="startupType" minOccurs="0"/>
+ <xs:element name="shutdown" type="shutdownType" minOccurs="0"/>
+ <xs:element name="serialization" type="serializationType" minOccurs="0"/>
+ <xs:element name="replication" type="replicationType" minOccurs="0"/>
+ <xs:element name="invalidation" type="invalidationType" minOccurs="0"/>
+ <xs:element name="jmxStatistics" type="jmxStatisticsType" minOccurs="0"/>
+ <xs:element name="transport" type="transportType" minOccurs="0"/>
+ <xs:element name="eviction" type="evictionType" minOccurs="0"/>
+ <xs:element name="loaders" type="loadersType" minOccurs="0"/>
+ <xs:element name="customInterceptors" type="customInterceptorsType" minOccurs="0"/>
+ </xs:all>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:complexType name="lockingType">
+ <xs:attribute name="isolationLevel">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="SERIALIZABLE"/>
+ <xs:enumeration value="REPEATABLE_READ"/>
+ <xs:enumeration value="READ_COMMITTED"/>
+ <xs:enumeration value="READ_UNCOMMITTED"/>
+ <xs:enumeration value="NONE"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ <xs:attribute name="lockParentForChildInsertRemove" type="booleanType"/>
+ <xs:attribute name="lockAcquisitionTimeout" type="xs:positiveInteger"/>
+ <xs:attribute name="nodeLockingScheme">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="mvcc"/>
+ <xs:enumeration value="optimistic"/>
+ <xs:enumeration value="pessimistic"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ <xs:attribute name="allowWriteSkew" type="booleanType"/>
+ <xs:attribute name="concurrencyLevel" type="xs:integer"/>
+ </xs:complexType>
+
+ <xs:complexType name="transactionType">
+ <xs:attribute name="transactionManagerLookupClass" type="xs:string"/>
+ <xs:attribute name="syncRollbackPhase" type="booleanType"/>
+ <xs:attribute name="syncCommitPhase" type="booleanType"/>
+ </xs:complexType>
+
+ <xs:complexType name="startupType">
+ <xs:attribute name="fetchInMemoryState" type="booleanType"/>
+ <xs:attribute name="inactiveOnStartup" type="booleanType"/>
+ <xs:attribute name="stateRetrievalTimeout" type="xs:positiveInteger"/>
+ </xs:complexType>
+
+ <xs:complexType name="shutdownType">
+ <xs:attribute name="hookBehavior">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="DEFAULT"/>
+ <xs:enumeration value="REGISTER"/>
+ <xs:enumeration value="DONT_REGISTER"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ </xs:complexType>
+
+ <xs:complexType name="serializationType">
+ <xs:attribute name="objectInputStreamPoolSize" type="xs:positiveInteger"/>
+ <xs:attribute name="objectOutputStreamPoolSize" type="xs:positiveInteger"/>
+ <xs:attribute name="version" type="xs:string"/>
+ <xs:attribute name="marshallerClass" type="xs:string"/>
+ <xs:attribute name="useLazyDeserialization" type="booleanType"/>
+ <xs:attribute name="useRegionBasedMarshalling" type="booleanType"/>
+ </xs:complexType>
+
+ <xs:simpleType name="booleanType">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="true"/>
+ <xs:enumeration value="false"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:complexType name="replicationType">
+ <xs:sequence>
+ <xs:choice>
+ <xs:element name="sync" type="syncType" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="async" type="asyncType" minOccurs="0" maxOccurs="1"/>
+ </xs:choice>
+ <xs:element name="buddy" minOccurs="0">
+ <xs:complexType>
+ <xs:all minOccurs="0">
+ <xs:element name="dataGravitation">
+ <xs:complexType>
+ <xs:attribute name="auto" type="booleanType"/>
+ <xs:attribute name="removeOnFind" type="booleanType"/>
+ <xs:attribute name="searchBackupTrees" type="booleanType"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="locator">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="properties" type="xs:string" maxOccurs="1"/>
+ </xs:all>
+ <xs:attribute name="class" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
+ <xs:attribute name="enabled" type="booleanType"/>
+ <xs:attribute name="poolName" type="xs:string"/>
+ <xs:attribute name="communicationTimeout" type="xs:integer"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="invalidationType">
+ <xs:choice>
+ <xs:element name="sync" type="syncType"/>
+ <xs:element name="async" type="asyncType"/>
+ </xs:choice>
+ </xs:complexType>
+
+ <xs:complexType name="jmxStatisticsType">
+ <xs:attribute name="enabled" type="booleanType"/>
+ </xs:complexType>
+
+ <xs:complexType name="transportType">
+ <xs:sequence>
+ <xs:element name="jgroupsConfig" type="xs:anyType" minOccurs="0" maxOccurs="1"/>
+ </xs:sequence>
+ <xs:attribute name="clusterName" type="xs:string"/>
+ <xs:attribute name="multiplexerStack" type="xs:string"/>
+ </xs:complexType>
+
+ <xs:complexType name="syncType">
+ <xs:attribute name="replTimeout" type="xs:positiveInteger"/>
+ </xs:complexType>
+
+
+ <xs:complexType name="asyncType">
+ <xs:attribute name="useReplQueue" type="booleanType"/>
+ <xs:attribute name="replQueueInterval" type="xs:positiveInteger"/>
+ <xs:attribute name="replQueueMaxElements" type="xs:positiveInteger"/>
+ </xs:complexType>
+
+ <xs:complexType name="evictionType">
+ <xs:sequence>
+ <xs:element name="defaults" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="policyClass" type="xs:string"/>
+ <xs:attribute name="eventQueueSize" type="xs:positiveInteger"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="root" type="evictionRegionType" minOccurs="0"/>
+ <xs:element name="region" minOccurs="0" maxOccurs="unbounded" type="evictionRegionType"/>
+ </xs:sequence>
+ <xs:attribute name="wakeUpInterval" type="xs:positiveInteger"/>
+ </xs:complexType>
+
+ <xs:complexType name="evictionRegionType">
+ <xs:sequence>
+ <xs:element name="attribute" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="name" type="xs:string"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:string"/>
+ <xs:attribute name="policyClass" type="xs:string"/>
+ <xs:attribute name="eventQueueSize" type="xs:positiveInteger"/>
+ </xs:complexType>
+
+ <xs:complexType name="loadersType">
+ <xs:sequence>
+ <xs:element name="preload" maxOccurs="1">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="node" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:attribute name="fqn" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="loader" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="properties"/>
+ <xs:element name="singletonStore" minOccurs="0">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="properties" type="xs:string"/>
+ </xs:all>
+ <xs:attribute name="enabled" type="booleanType"/>
+ <xs:attribute name="class" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
+ <xs:attribute name="class" type="xs:string"/>
+ <xs:attribute name="async" type="booleanType"/>
+ <xs:attribute name="fetchPersistentState" type="booleanType"/>
+ <xs:attribute name="ignoreModifications" type="booleanType"/>
+ <xs:attribute name="purgeOnStartup" type="booleanType"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="passivation" type="booleanType"/>
+ <xs:attribute name="shared" type="booleanType"/>
+ </xs:complexType>
+
+ <xs:complexType name="customInterceptorsType">
+ <xs:sequence>
+ <xs:element name="interceptor" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="properties" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="position" minOccurs="0" maxOccurs="1">
+ <xs:complexType>
+ <xs:attribute name="first" type="booleanType"/>
+ <xs:attribute name="last" type="booleanType"/>
+ <xs:attribute name="index" type="xs:positiveInteger"/>
+ <xs:attribute name="before" type="xs:string"/>
+ <xs:attribute name="after" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
+ <xs:attribute name="class" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>
+
Modified: core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java 2008-07-07 23:13:35 UTC (rev 6201)
@@ -207,7 +207,6 @@
public void testCustomInterceptors()
{
List<CustomInterceptorConfig> interceptorConfigs = config.getCustomInterceptors();
- if (interceptorConfigs.isEmpty()) return; //todo drop this once you drop the old configuration
assert interceptorConfigs.size() == 5;
assert interceptorConfigs.get(0).getInterceptorClass().equals("com.myCompany.MyInterceptor1");
assert interceptorConfigs.get(1).getInterceptorClass().equals("com.myCompany.MyInterceptor2");
Added: core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlSchemaTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlSchemaTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlSchemaTest.java 2008-07-07 23:13:35 UTC (rev 6201)
@@ -0,0 +1,83 @@
+package org.jboss.cache.config.parsing;
+
+import org.testng.annotations.Test;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Class that tests how schema works.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+@Test (groups = "unit")
+public class XmlSchemaTest
+{
+ public static final String BASE_DIR_FOR_CONFIG = "./configs";
+
+ private String[] testFiles =
+ {
+ "buddy-replication-cache.xml",
+ "clonable-config.xml",
+ "local-lru-eviction.xml",
+ "local-passivation.xml",
+ "local-tx.xml",
+ "mixedPolicy-eviction.xml",
+ "mux.xml",
+ "parser-test.xml",
+ "policyPerRegion-eviction.xml",
+ "replSync.xml",
+ "string-property-replaced.xml"
+ };
+
+ /**
+ * Simple test to prove that validation works.
+ */
+ public void testSimpleFile()
+ {
+ EceptionCountingErrorHanlder handler = new EceptionCountingErrorHanlder();
+ XmlConfigurationParser parser = new XmlConfigurationParser(handler);
+ for (String file : testFiles)
+ {
+ System.out.println("file = " + file);
+ parser.parseFile(BASE_DIR_FOR_CONFIG + File.separator + file);
+ assert handler.noErrors() : "error during parsing";
+ }
+ }
+
+ private static class EceptionCountingErrorHanlder implements ErrorHandler
+ {
+ List<SAXParseException> exceptionList = new ArrayList<SAXParseException>();
+
+ public void warning(SAXParseException exception) throws SAXException
+ {
+ handleDefault(exception);
+ }
+
+ public void error(SAXParseException exception) throws SAXException
+ {
+ handleDefault(exception);
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException
+ {
+ handleDefault(exception);
+ }
+
+ private void handleDefault(SAXParseException exception)
+ {
+ System.out.println("Error :" + exception.getMessage());
+ exceptionList.add(exception);
+ }
+
+ boolean noErrors()
+ {
+ return exceptionList.isEmpty();
+ }
+ }
+}
Modified: core/trunk/src/test/resources/configs/buddy-replication-cache.xml
===================================================================
--- core/trunk/src/test/resources/configs/buddy-replication-cache.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/buddy-replication-cache.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<startup stateRetrievalTimeout="20000"/>
Modified: core/trunk/src/test/resources/configs/clonable-config.xml
===================================================================
--- core/trunk/src/test/resources/configs/clonable-config.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/clonable-config.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
<locking isolationLevel="SERIALIZABLE" lockAcquisitionTimeout="1" nodeLockingScheme="optimistic"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<startup fetchInMemoryState="false" stateRetrievalTimeout="3"/>
Modified: core/trunk/src/test/resources/configs/local-lru-eviction.xml
===================================================================
--- core/trunk/src/test/resources/configs/local-lru-eviction.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/local-lru-eviction.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
+
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="15000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<startup stateRetrievalTimeout="20000"/>
Modified: core/trunk/src/test/resources/configs/local-passivation.xml
===================================================================
--- core/trunk/src/test/resources/configs/local-passivation.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/local-passivation.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
+
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="15000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<startup stateRetrievalTimeout="20000"/>
Modified: core/trunk/src/test/resources/configs/local-tx.xml
===================================================================
--- core/trunk/src/test/resources/configs/local-tx.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/local-tx.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
+
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="15000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<serialization useRegionBasedMarshalling="false"/>
Modified: core/trunk/src/test/resources/configs/mixedPolicy-eviction.xml
===================================================================
--- core/trunk/src/test/resources/configs/mixedPolicy-eviction.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/mixedPolicy-eviction.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
+
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="15000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<startup stateRetrievalTimeout="20000"/>
Modified: core/trunk/src/test/resources/configs/mux.xml
===================================================================
--- core/trunk/src/test/resources/configs/mux.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/mux.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
+
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<startup stateRetrievalTimeout="20000"/>
Modified: core/trunk/src/test/resources/configs/parser-test.xml
===================================================================
--- core/trunk/src/test/resources/configs/parser-test.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/parser-test.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -2,8 +2,10 @@
<!-- file used for functional test of the xml parser -->
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
+
<locking isolationLevel="REPEATABLE_READ" lockParentForChildInsertRemove="true" lockAcquisitionTimeout="10234"
nodeLockingScheme="mvcc" allowWriteSkew="true" concurrencyLevel="21"/>
Modified: core/trunk/src/test/resources/configs/policyPerRegion-eviction.xml
===================================================================
--- core/trunk/src/test/resources/configs/policyPerRegion-eviction.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/policyPerRegion-eviction.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="15000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<startup stateRetrievalTimeout="20000"/>
@@ -32,6 +33,7 @@
<pbcast.FLUSH timeout="0"/>
</jgroupsConfig>
</transport>
+
<eviction wakeUpInterval="5000">
<root policyClass="org.jboss.cache.eviction.LRUPolicy">
<attribute name="maxNodes">5000</attribute>
Modified: core/trunk/src/test/resources/configs/replSync.xml
===================================================================
--- core/trunk/src/test/resources/configs/replSync.xml 2008-07-07 21:27:37 UTC (rev 6200)
+++ core/trunk/src/test/resources/configs/replSync.xml 2008-07-07 23:13:35 UTC (rev 6201)
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="file:///C:/projects/cache/branches/za_trunk/src/main/resources/jbosscache-config.xsd">
<locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<serialization useRegionBasedMarshalling="true"/>
@@ -32,6 +33,7 @@
<pbcast.FLUSH timeout="0"/>
</jgroupsConfig>
</transport>
+
<replication>
<sync replTimeout="15000"/>
</replication>
15 years, 10 months
JBoss Cache SVN: r6200 - in core/trunk/src/main/java/org/jboss/cache: interceptors and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-07 17:27:37 -0400 (Mon, 07 Jul 2008)
New Revision: 6200
Added:
core/trunk/src/main/java/org/jboss/cache/InternalNode.java
Removed:
core/trunk/src/main/java/org/jboss/cache/mvcc/InternalNode.java
Modified:
core/trunk/src/main/java/org/jboss/cache/DataContainer.java
core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
core/trunk/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java
core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
Log:
Moved InternalNode to a more logical package
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainer.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainer.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -1,7 +1,6 @@
package org.jboss.cache;
import org.jboss.cache.marshall.NodeData;
-import org.jboss.cache.mvcc.InternalNode;
import java.util.List;
import java.util.Set;
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -10,7 +10,6 @@
import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.lock.LockManager;
import org.jboss.cache.marshall.NodeData;
-import org.jboss.cache.mvcc.InternalNode;
import java.util.ArrayList;
import java.util.Collections;
Copied: core/trunk/src/main/java/org/jboss/cache/InternalNode.java (from rev 6186, core/trunk/src/main/java/org/jboss/cache/mvcc/InternalNode.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InternalNode.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/InternalNode.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -0,0 +1,132 @@
+package org.jboss.cache;
+
+import org.jboss.cache.lock.NodeLock;
+import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.transaction.GlobalTransaction;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * An internal node interface, that represents nodes that directly form the tree structure in the cache. This is as opposed
+ * to {@link Node} and it's {@link NodeSPI} sub-interface, which are typically implemented by delegates which then delegate calls
+ * to internal nodes, potentially after passing the call up an interceptor chain.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface InternalNode<K, V>
+{
+ NodeSPI getParent();
+
+ CacheSPI getCache();
+
+ boolean isChildrenLoaded();
+
+ void setChildrenLoaded(boolean flag);
+
+ Object getDirect(Object key);
+
+ Map getDataDirect();
+
+ Object putDirect(Object key, Object value);
+
+ NodeSPI getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean notify);
+
+ Object removeDirect(Object key);
+
+ void addChildDirect(NodeSPI child);
+
+ NodeSPI addChildDirect(Fqn f);
+
+ NodeSPI addChildDirect(Fqn f, boolean notify);
+
+ NodeSPI addChildDirect(Object o, boolean notify);
+
+ void clearDataDirect();
+
+ NodeSPI getChildDirect(Fqn fqn);
+
+ Set<Object> getChildrenNamesDirect();
+
+ Set<Object> getKeysDirect();
+
+ boolean removeChildDirect(Object childName);
+
+ boolean removeChildDirect(Fqn f);
+
+ Map<Object, Node<K, V>> getChildrenMapDirect();
+
+ void setChildrenMapDirect(Map<Object, Node<K, V>> children);
+
+ void putAllDirect(Map data);
+
+ void removeChildrenDirect();
+
+ void setVersion(DataVersion version);
+
+ DataVersion getVersion();
+
+ Fqn getFqn();
+
+ void setFqn(Fqn fqn);
+
+ NodeSPI getChildDirect(Object childName);
+
+ Set<NodeSPI> getChildrenDirect();
+
+ boolean hasChildrenDirect();
+
+ Set<NodeSPI> getChildrenDirect(boolean includeMarkedForRemoval);
+
+ boolean isDataLoaded();
+
+ void setDataLoaded(boolean dataLoaded);
+
+ boolean isValid();
+
+ void setValid(boolean valid, boolean recursive);
+
+ boolean isLockForChildInsertRemove();
+
+ void setLockForChildInsertRemove(boolean lockForChildInsertRemove);
+
+ void setInternalState(Map state);
+
+ Map getInternalState(boolean onlyInternalState);
+
+ void releaseObjectReferences(boolean recursive);
+
+ boolean isDeleted();
+
+ void markAsDeleted(boolean marker);
+
+ void markAsDeleted(boolean marker, boolean recursive);
+
+ void setResident(boolean resident);
+
+ boolean isResident();
+
+ /**
+ * Creates a new instance of the same type and copies internal state. Note that a shallow copy is made for all fields
+ * except the data map, where a new map is created.
+ *
+ * @return a copy.
+ */
+ InternalNode copy();
+
+ NodeLock getLock();
+
+ void addChild(Object nodeName, Node<K, V> nodeToAdd);
+
+ void printDetails(StringBuilder sb, int indent);
+
+ /**
+ * Very similar to getChildrenMapDirect() except that if the internal map is null, it initialises the map if init is true.
+ *
+ * @param init if true, will init internal data structures.
+ * @return a Map or null.
+ */
+ Map<Object, Node<K, V>> getChildrenMapDirect(boolean init);
+}
Modified: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -17,7 +17,6 @@
import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockStrategyFactory;
-import org.jboss.cache.mvcc.InternalNode;
import org.jboss.cache.mvcc.NodeReference;
import org.jboss.cache.mvcc.NullMarkerNode;
import org.jboss.cache.mvcc.ReadCommittedNode;
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -15,7 +15,6 @@
import org.jboss.cache.lock.IdentityLock;
import org.jboss.cache.lock.LockStrategyFactory;
import org.jboss.cache.marshall.MarshalledValue;
-import org.jboss.cache.mvcc.InternalNode;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -3,6 +3,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
+import org.jboss.cache.InternalNode;
import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.commands.VisitableCommand;
@@ -33,7 +34,6 @@
import org.jboss.cache.lock.LockManager;
import static org.jboss.cache.lock.LockType.WRITE;
import org.jboss.cache.lock.TimeoutException;
-import org.jboss.cache.mvcc.InternalNode;
import org.jboss.cache.mvcc.NullMarkerNode;
import org.jboss.cache.mvcc.ReadCommittedNode;
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -3,12 +3,12 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.InternalNode;
import org.jboss.cache.Node;
import org.jboss.cache.NodeNotValidException;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Option;
import org.jboss.cache.lock.NodeLock;
-import org.jboss.cache.mvcc.InternalNode;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
Deleted: core/trunk/src/main/java/org/jboss/cache/mvcc/InternalNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/InternalNode.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/InternalNode.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -1,133 +0,0 @@
-package org.jboss.cache.mvcc;
-
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.lock.NodeLock;
-import org.jboss.cache.optimistic.DataVersion;
-import org.jboss.cache.transaction.GlobalTransaction;
-
-import java.util.Map;
-import java.util.Set;
-
-/**
- * // TODO Document this
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
-public interface InternalNode<K, V>
-{
- NodeSPI getParent();
-
- CacheSPI getCache();
-
- boolean isChildrenLoaded();
-
- void setChildrenLoaded(boolean flag);
-
- Object getDirect(Object key);
-
- Map getDataDirect();
-
- Object putDirect(Object key, Object value);
-
- NodeSPI getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean notify);
-
- Object removeDirect(Object key);
-
- void addChildDirect(NodeSPI child);
-
- NodeSPI addChildDirect(Fqn f);
-
- NodeSPI addChildDirect(Fqn f, boolean notify);
-
- NodeSPI addChildDirect(Object o, boolean notify);
-
- void clearDataDirect();
-
- NodeSPI getChildDirect(Fqn fqn);
-
- Set<Object> getChildrenNamesDirect();
-
- Set<Object> getKeysDirect();
-
- boolean removeChildDirect(Object childName);
-
- boolean removeChildDirect(Fqn f);
-
- Map<Object, Node<K, V>> getChildrenMapDirect();
-
- void setChildrenMapDirect(Map<Object, Node<K, V>> children);
-
- void putAllDirect(Map data);
-
- void removeChildrenDirect();
-
- void setVersion(DataVersion version);
-
- DataVersion getVersion();
-
- Fqn getFqn();
-
- void setFqn(Fqn fqn);
-
- NodeSPI getChildDirect(Object childName);
-
- Set<NodeSPI> getChildrenDirect();
-
- boolean hasChildrenDirect();
-
- Set<NodeSPI> getChildrenDirect(boolean includeMarkedForRemoval);
-
- boolean isDataLoaded();
-
- void setDataLoaded(boolean dataLoaded);
-
- boolean isValid();
-
- void setValid(boolean valid, boolean recursive);
-
- boolean isLockForChildInsertRemove();
-
- void setLockForChildInsertRemove(boolean lockForChildInsertRemove);
-
- void setInternalState(Map state);
-
- Map getInternalState(boolean onlyInternalState);
-
- void releaseObjectReferences(boolean recursive);
-
- boolean isDeleted();
-
- void markAsDeleted(boolean marker);
-
- void markAsDeleted(boolean marker, boolean recursive);
-
- void setResident(boolean resident);
-
- boolean isResident();
-
- /**
- * Creates a new instance of the same type and copies internal state. Note that a shallow copy is made for all fields
- * except the data map, where a new map is created.
- *
- * @return a copy.
- */
- InternalNode copy();
-
- NodeLock getLock();
-
- void addChild(Object nodeName, Node<K, V> nodeToAdd);
-
- void printDetails(StringBuilder sb, int indent);
-
- /**
- * Very similar to getChildrenMapDirect() except that if the internal map is null, it initialises the map if init is true.
- *
- * @param init if true, will init internal data structures.
- * @return a Map or null.
- */
- Map<Object, Node<K, V>> getChildrenMapDirect(boolean init);
-}
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -2,6 +2,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.InternalNode;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.lock.NodeLock;
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -1,6 +1,7 @@
package org.jboss.cache.mvcc;
import org.jboss.cache.DataContainer;
+import org.jboss.cache.InternalNode;
import org.jboss.cache.NodeFactory;
import org.jboss.cache.invocation.InvocationContext;
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -2,6 +2,7 @@
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
+import org.jboss.cache.InternalNode;
import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.NodeSPI;
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java 2008-07-07 21:21:24 UTC (rev 6199)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java 2008-07-07 21:27:37 UTC (rev 6200)
@@ -2,6 +2,7 @@
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
+import org.jboss.cache.InternalNode;
import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.invocation.InvocationContext;
15 years, 10 months
JBoss Cache SVN: r6199 - in core/trunk/src: main/java/org/jboss/cache/config and 11 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-07 17:21:24 -0400 (Mon, 07 Jul 2008)
New Revision: 6199
Added:
core/trunk/src/main/java/org/jboss/cache/LegacyRegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferManager.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
Removed:
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/Region.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
core/trunk/src/main/java/org/jboss/cache/factories/BootstrapFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java
core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferGenerator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferIntegrator.java
core/trunk/src/test/java/org/jboss/cache/config/EvictionRegionConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
Log:
reorganised region managers and state transfer managers to allow for mvcc customisation
Modified: core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -194,7 +194,7 @@
* From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
* {@link org.jboss.cache.factories.annotations.Inject} annotation.
*
- * @return the {@link org.jboss.cache.RegionManager}
+ * @return the {@link RegionManager}
*/
RegionManager getRegionManager();
Added: core/trunk/src/main/java/org/jboss/cache/LegacyRegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/LegacyRegionManagerImpl.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/LegacyRegionManagerImpl.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -0,0 +1,20 @@
+package org.jboss.cache;
+
+import net.jcip.annotations.ThreadSafe;
+
+/**
+ * For optimistic and pessimistically locked caches
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 2.0.0
+ */
+@ThreadSafe
+public class LegacyRegionManagerImpl extends RegionManagerImpl
+{
+ @Override
+ protected Object getOwnerForLock()
+ {
+ Object owner = cache.getCurrentTransaction();
+ return owner == null ? Thread.currentThread() : owner;
+ }
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -26,7 +26,7 @@
import org.jboss.cache.marshall.Marshaller;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.remoting.jgroups.ChannelMessageListener;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionTable;
import org.jboss.cache.util.ThreadGate;
@@ -448,7 +448,7 @@
public void fetchPartialState(List<Address> sources, Fqn sourceTarget, Fqn integrationTarget) throws Exception
{
- String encodedStateId = sourceTarget + StateTransferManager.PARTIAL_STATE_DELIMITER + integrationTarget;
+ String encodedStateId = sourceTarget + DefaultStateTransferManager.PARTIAL_STATE_DELIMITER + integrationTarget;
fetchPartialState(sources, encodedStateId);
}
Modified: core/trunk/src/main/java/org/jboss/cache/Region.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Region.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/Region.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -28,7 +28,7 @@
* <p/>
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
- * @see org.jboss.cache.RegionManager
+ * @see RegionManager
* @since 2.0.0
*/
public interface Region extends Comparable<Region>
Deleted: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,929 +0,0 @@
-package org.jboss.cache;
-
-import net.jcip.annotations.ThreadSafe;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import static org.jboss.cache.Region.Type.*;
-import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-import org.jboss.cache.buddyreplication.BuddyManager;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.EvictionTimerTask;
-import org.jboss.cache.factories.annotations.Destroy;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.NonVolatile;
-import org.jboss.cache.factories.annotations.Start;
-import org.jboss.cache.factories.annotations.Stop;
-import org.jboss.cache.lock.LockManager;
-import static org.jboss.cache.lock.LockType.WRITE;
-import org.jgroups.Address;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Manages multiple {@link Region}s for a Cache instance.
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
- * @since 2.0.0
- */
-@ThreadSafe
-@NonVolatile
-public class RegionManager
-{
- /**
- * The default region used in XML configuration files when defining eviction policies. Any
- * eviction settings bound under this 'default' Fqn is appplied to {@link org.jboss.cache.Fqn#ROOT} internally so
- * any region that is not explicitly defined comes under the settings defined for this default.
- */
- public static final Fqn<?> DEFAULT_REGION = Fqn.fromString("/_default_");
-
- /**
- * A registry of regions that have been defined.
- */
- private final Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn, Region>();
- private boolean defaultInactive;
- private final Log log = LogFactory.getLog(RegionManager.class);
- private CacheSPI cache;
- private boolean usingEvictions;
- private EvictionConfig evictionConfig;
- private final EvictionTimerTask evictionTimerTask = new EvictionTimerTask();
-
- protected final Set<Fqn> activationChangeNodes = Collections.synchronizedSet(new HashSet<Fqn>());
- protected Configuration configuration;
- protected RPCManager rpcManager;
- private LockManager lockManager;
- private BuddyFqnTransformer buddyFqnTransformer;
- private boolean isUsingBR;
-
- @Inject
- void injectDependencies(CacheSPI cache, Configuration configuration, RPCManager rpcManager, LockManager lockManager,
- BuddyFqnTransformer transformer)
- {
- this.cache = cache;
- this.rpcManager = rpcManager;
- this.configuration = configuration;
- this.lockManager = lockManager;
- this.buddyFqnTransformer = transformer;
- }
-
- @Start
- protected void start()
- {
- log.trace("Starting region manager");
- isUsingBR = configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled();
- if (configuration.getEvictionConfig() != null
- && configuration.getEvictionConfig().isValidConfig())
- {
- // validate individual region configs now
- for (EvictionRegionConfig erc : configuration.getEvictionConfig().getEvictionRegionConfigs())
- {
- EvictionPolicyConfig epc = erc.getEvictionPolicyConfig();
- if (epc != null) epc.validate();
- }
-
- setEvictionConfig(configuration.getEvictionConfig());
- setUsingEvictions(true);
- }
- else
- {
- setUsingEvictions(false);
- log.debug("Not using an EvictionPolicy");
- }
-
- setDefaultInactive(configuration.isInactiveOnStartup());
-
- if (isUsingEvictions()) startEvictionThread();
- }
-
- @Stop
- protected void stop()
- {
- if (isUsingEvictions()) stopEvictionThread();
- }
-
- @Destroy
- protected void destroy()
- {
- regionsRegistry.clear();
- activationChangeNodes.clear();
- }
-
- /**
- * @return true if evictions are being processed.
- */
- public boolean isUsingEvictions()
- {
- return usingEvictions;
- }
-
- /**
- * @return true if replication is by default inactive for new {@link Region}s.
- */
- public boolean isDefaultInactive()
- {
- return defaultInactive;
- }
-
- /**
- * Sets if replication for new {@link Region}s is by default inactive.
- */
- public void setDefaultInactive(boolean defaultInactive)
- {
- this.defaultInactive = defaultInactive;
- Region defaultRegion = regionsRegistry.get(Fqn.ROOT);
- if (defaultRegion != null) defaultRegion.setActive(!defaultInactive);
- }
-
- /**
- * Helper utility that checks for a {@link ClassLoader} registered for the
- * given {@link Fqn}, and if found sets it as the TCCL. If the given Fqn is
- * under the _BUDDY_BACKUP_ region, the equivalent region in the main
- * cache is used to find the {@link ClassLoader}.
- *
- * @param fqn Fqn pointing to a region for which a special classloader
- * may have been registered.
- */
- public void setContextClassLoaderAsCurrent(Fqn fqn)
- {
- if (fqn.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN))
- {
- if (fqn.size() <= 2)
- {
- fqn = Fqn.ROOT;
- }
- else
- {
- fqn = fqn.getSubFqn(2, fqn.size());
- }
- }
- Region region = getRegion(fqn, false);
- ClassLoader regionCL = (region == null) ? null : region.getClassLoader();
- if (regionCL != null)
- {
- Thread.currentThread().setContextClassLoader(regionCL);
- }
-
- }
-
- /**
- * Returns a region by {@link Fqn}, creating it optionally if absent. If the region does not exist and <tt>createIfAbsent</tt>
- * is <tt>false</tt>, a parent region which may apply to the {@link Fqn} is sought.
- * <p/>
- * Note that this takes into account the fact that this may be a Buddy Backup Fqn. If it is, the actual Fqn is calculated
- * and used instead.
- */
- public Region getRegion(Fqn fqn, boolean createIfAbsent)
- {
- return getRegion(fqn, ANY, createIfAbsent);
- }
-
- /**
- * Retrieves a valid marshalling {@link Region} after taking into account that this may be a Buddy Backup Fqn.
- * If the fqn passed in is null, the region has been deactivated or if a region cannot be found, this method returns a null.
- *
- * @param fqn of the region to locate
- * @return a region
- */
- public Region getValidMarshallingRegion(Fqn fqn)
- {
- if (fqn == null) return null;
- return getRegion(fqn, Region.Type.MARSHALLING, false);
- }
-
- /**
- * An overloaded form of {@link #getRegion(Fqn,boolean)} that takes an additional {@link org.jboss.cache.Region.Type}
- * parameter to force regions of a specific type.
- * <p/>
- * Note that this takes into account the fact that this may be a Buddy Backup Fqn. If it is, the actual Fqn is calculated
- * and used instead.
- *
- * @see org.jboss.cache.Region.Type
- */
- public Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent)
- {
- if (isUsingBR && fqn != null && buddyFqnTransformer.isBackupFqn(fqn))
- {
- fqn = buddyFqnTransformer.getActualFqn(fqn);
- }
-
- if (log.isTraceEnabled()) log.trace("Contents of RegionsRegistry: " + regionsRegistry);
- Fqn fqnToUse = fqn;
- if (DEFAULT_REGION.equals(fqnToUse)) fqnToUse = Fqn.ROOT;
- // first see if a region for this specific Fqn exists
- if (regionsRegistry.containsKey(fqnToUse))
- {
- Region r = regionsRegistry.get(fqnToUse);
-
- // this is a very poor way of telling whether a region is a marshalling one or an eviction one. :-(
- // mandates that class loaders be registered for marshalling regions.
- if (type == ANY
- || (type == MARSHALLING && r.getClassLoader() != null)
- || (type == EVICTION && r.getEvictionPolicyConfig() != null))
- {
- return r;
- }
- }
-
- // if not, attempt to create one ...
- if (createIfAbsent)
- {
- Region r = new RegionImpl(fqnToUse, this);
- regionsRegistry.put(fqnToUse, r);
- if (type == MARSHALLING)
- {
- // insert current class loader into region so at least it is recognised as a marshalling region
- r.registerContextClassLoader(getClass().getClassLoader());
- }
- return r;
- }
-
- // else try and find a parent which has a defined region, may return null if nothing is defined.
- Region nextBestThing = null;
- Fqn nextFqn = fqnToUse;
-
- while (nextBestThing == null)
- {
- nextFqn = nextFqn.getParent();
- if (regionsRegistry.containsKey(nextFqn))
- {
- Region r = regionsRegistry.get(nextFqn);
- if (log.isTraceEnabled()) log.trace("Trying next region " + nextFqn + " and got " + r);
-
- // this is a very poor way of telling whether a region is a marshalling one or an eviction one. :-(
- // mandates that class loaders be registered for marshalling regions.
- if (type == ANY
- || (type == MARSHALLING && r.getClassLoader() != null)
- || (type == EVICTION && r.getEvictionPolicyConfig() != null))
- {
- nextBestThing = r;
- }
- }
- if (nextFqn.isRoot()) break;
- }
-
- // test if the default region has been defined. If not, and if the request
- // is for an eviction region, return null
- if (type == EVICTION && nextBestThing != null && nextBestThing.getFqn().isRoot() && !regionsRegistry.containsKey(Fqn.ROOT))
- {
- log.trace("No default eviction region; returning null");
- nextBestThing = null;
- }
-
- return nextBestThing;
- }
-
- /**
- * Returns a region using Fqn.fromString(fqn), calling {@link #getRegion(Fqn,boolean)}
- *
- * @param fqn
- * @param createIfAbsent
- * @see #getRegion(Fqn,boolean)
- */
- public Region getRegion(String fqn, boolean createIfAbsent)
- {
- return getRegion(Fqn.fromString(fqn), createIfAbsent);
- }
-
- /**
- * Removes a {@link org.jboss.cache.Region} identified by the given fqn.
- *
- * @param fqn fqn of the region to remove
- * @return true if such a region existed and was removed.
- */
- public boolean removeRegion(Fqn fqn)
- {
- Region r = regionsRegistry.remove(fqn);
- if (r == null) return false;
-
- if (isUsingEvictions() && r.getEvictionPolicy() != null)
- {
- evictionTimerTask.removeRegionToProcess(r);
- }
- return true;
- }
-
- /**
- * @return the eviction timer task object associated with this Region Manager.
- */
- protected EvictionTimerTask getEvictionTimerTask()
- {
- return evictionTimerTask;
- }
-
- /**
- * Activates unmarshalling of replication messages for the region
- * rooted in the given Fqn.
- * <p/>
- * <strong>NOTE:</strong> This method will cause the creation of a node
- * in the local cache at <code>subtreeFqn</code> whether or not that
- * node exists anywhere else in the cluster. If the node does not exist
- * elsewhere, the local node will be empty. The creation of this node will
- * not be replicated.
- * <p/>
- *
- * @param fqn representing the region to be activated.
- * @throws RegionNotEmptyException if the node <code>fqn</code>
- * exists and already has either data or children
- */
- public void activate(Fqn fqn) throws RegionNotEmptyException
- {
- activate(fqn, false);
- }
-
- /**
- * Attempts to activate a given region rooted at a given Fqn, similar to {@link #activate(Fqn)} except
- * that if the fqn is currently already in use (probably already been activated) this method is a no-op.
- *
- * @param fqn which represents the region to activate
- */
- public void activateIfEmpty(Fqn fqn)
- {
- activate(fqn, true);
- }
-
- private void activate(Fqn fqn, boolean suppressRegionNotEmptyException)
- {
- try
- {
- if (log.isTraceEnabled()) log.trace("Activating region " + fqn);
- Region r = getRegion(fqn, false);
- if (r != null)
- {
- if (!defaultInactive && r.getClassLoader() == null)
- {
- // This region's state will no match that of a non-existent one
- // So, there is no reason to keep this region any more
-
- // (Brian) We shouldn't do this anymore; now outside code
- // can have a ref to the region!!
- removeRegion(fqn);
- }
- else
- {
- //r.activate();
- r.setStatus(Region.Status.ACTIVATING);
- if (configuration.isFetchInMemoryState())
- {
- activateRegion(r.getFqn(), suppressRegionNotEmptyException);
- }
- r.setActive(true);
- }
- }
- else if (defaultInactive)
- {
- // "Active" region is not the default, so create a region
- r = getRegion(fqn, true);
- // FIXME - persistent state transfer counts too!
- r.setStatus(Region.Status.ACTIVATING);
- if (configuration.isFetchInMemoryState())
- {
- activateRegion(r.getFqn(), suppressRegionNotEmptyException);
- }
- r.setActive(true);
- }
- }
- catch (RuntimeException re)
- {
- throw re;
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Causes the cache to transfer state for the subtree rooted at
- * <code>subtreeFqn</code> and to begin accepting replication messages
- * for that subtree.
- * <p/>
- * <strong>NOTE:</strong> This method will cause the creation of a node
- * in the local cache at <code>subtreeFqn</code> whether or not that
- * node exists anywhere else in the cluster. If the node does not exist
- * elsewhere, the local node will be empty. The creation of this node will
- * not be replicated.
- *
- * @param fqn Fqn string indicating the uppermost node in the
- * portion of the cache that should be activated.
- * @throws RegionNotEmptyException if the node <code>subtreeFqn</code>
- * exists and has either data or children
- */
- private void activateRegion(Fqn fqn, boolean suppressRegionNotEmptyException)
- {
- // Check whether the node already exists and has data
- Node subtreeRoot = cache.peek(fqn, false, false);
-
- /*
- * Commented out on Nov 16,2006 Manik&Vladimir
- *
- * if (!(cache.isNodeEmpty(subtreeRoot)))
- {
- throw new RegionNotEmptyException("Node " + subtreeRoot.getFqn() + " already exists and is not empty");
- }*/
-
- if (isActivatingDeactivating(fqn))
- {
- throw new CacheException("Region " + subtreeRoot.getFqn() + " is already being activated/deactivated");
- }
-
- if (log.isDebugEnabled())
- {
- log.debug("activating " + fqn);
- }
-
- try
- {
-
- // Add this fqn to the set of those we are activating
- // so calls to _getState for the fqn can return quickly
- activationChangeNodes.add(fqn);
-
- BuddyManager buddyManager = cache.getBuddyManager();
- // Request partial state from the cluster and integrate it
- if (buddyManager == null)
- {
- // Get the state from any node that has it and put it
- // in the main cache
- if (subtreeRoot == null)
- {
- // We'll update this node with the state we receive
- // need to obtain all necessary locks.
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- subtreeRoot = cache.getRoot().addChild(fqn);
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
- }
-
- List<Address> members = cache.getMembers();
-
- // Don't bother trying to fetch state if we are in LOCAL mode
- if (members != null && !members.isEmpty())
- rpcManager.fetchPartialState(members, subtreeRoot.getFqn());
- }
- else if (!buddyFqnTransformer.isBackupFqn(fqn))
- {
- // Get the state from each DataOwner and integrate in their
- // respective buddy backup cache
- List<Address> buddies = buddyManager.getBackupDataOwners();
- for (Address buddy : buddies)
- {
- List<Address> sources = new ArrayList<Address>(1);
- if (!cache.getMembers().contains(buddy))
- continue;
- sources.add(buddy);
- Fqn buddyRoot = buddyFqnTransformer.getBackupFqn(buddy, fqn);
- subtreeRoot = cache.peek(buddyRoot, false, false);
- if (subtreeRoot == null)
- {
- // We'll update this node with the state we receive
- // need to obtain all necessary locks.
- // needs to be a LOCAL call!
- NodeSPI root = cache.getRoot();
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- subtreeRoot = root.addChild(buddyRoot);
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
- }
- rpcManager.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
- }
- }
- else
- {
- log.info("Attempting to activate a backup region. Not attempting to retrieve any state as this will be pushed.");
- }
- }
- catch (Throwable t)
- {
- log.error("failed to activate " + fqn, t);
-
- // "Re-deactivate" the region
- try
- {
- inactivateRegion(fqn);
- }
- catch (Exception e)
- {
- log.error("failed inactivating " + fqn, e);
- // just swallow this one and throw the first one
- }
-
- // Throw the exception on, wrapping if necessary
- if (t instanceof RegionNotEmptyException)
- {
- if (!suppressRegionNotEmptyException) throw (RegionNotEmptyException) t;
- }
- else if (t instanceof CacheException)
- {
- throw (CacheException) t;
- }
- else
- {
- throw new CacheException(t.getClass().getName() + " " +
- t.getLocalizedMessage(), t);
- }
- }
- finally
- {
- activationChangeNodes.remove(fqn);
- }
- }
-
- /**
- * Convenienve method. If the region defined by fqn does not exist, {@link #isDefaultInactive()} is returned, otherwise
- * !{@link Region#isActive()} is returned.
- *
- * @param fqn fqn to test
- * @return true if inactive
- */
- public boolean isInactive(Fqn fqn)
- {
- Region region = getRegion(fqn, false);
- return region == null ? defaultInactive : !region.isActive();
- }
-
-
- /**
- * Causes the cache to stop accepting replication events for the subtree
- * rooted at <code>subtreeFqn</code> and evict all nodes in that subtree.
- * <p/>
- * This is legacy code and should not be called directly. This is a private method for now and will be refactored out.
- * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
- * <p/>
- *
- * @param fqn Fqn string indicating the uppermost node in the
- * portion of the cache that should be activated.
- * @throws RegionNameConflictException if <code>subtreeFqn</code> indicates
- * a node that is part of another
- * subtree that is being specially
- * managed (either by activate/inactiveRegion()
- * or by registerClassLoader())
- * @throws CacheException if there is a problem evicting nodes
- * @throws IllegalStateException if {@link org.jboss.cache.config.Configuration#isUseRegionBasedMarshalling()} is <code>false</code>
- */
- private void inactivateRegion(Fqn fqn) throws CacheException
- {
- if (isActivatingDeactivating(fqn))
- {
- throw new CacheException("Region " + fqn + " is already being activated/deactivated");
- }
-
- NodeSPI parent = null;
- NodeSPI subtreeRoot = null;
- boolean parentLocked = false;
- boolean subtreeLocked = false;
-
- try
- {
- // Record that this fqn is in status change, so can't provide state
- activationChangeNodes.add(fqn);
-
- if (!isInactive(fqn))
- {
- deactivate(fqn);
- }
-
- // Create a list with the Fqn in the main cache and any buddy backup trees
- BuddyManager buddyManager = cache.getBuddyManager();
- ArrayList<Fqn> list = new ArrayList<Fqn>();
- list.add(fqn);
-
- if (buddyManager != null)
- {
- Set buddies = cache.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, false, false).getChildrenNames();
- if (buddies != null)
- {
- for (Object buddy : buddies)
- {
- list.add(buddyFqnTransformer.getBackupFqn((String) buddy, fqn));
- }
- }
- }
-
- long stateFetchTimeout = cache.getConfiguration().getLockAcquisitionTimeout() + 5000;
- // Remove the subtree from the main cache and any buddy backup trees
- for (Fqn subtree : list)
- {
- subtreeRoot = cache.peek(subtree, false);
- if (subtreeRoot != null)
- {
- // Acquire locks
-
- Object owner = getOwnerForLock();
- subtreeLocked = lockManager.lockAll(subtreeRoot, WRITE, owner, stateFetchTimeout);
-
- // Lock the parent, as we're about to write to it
- parent = subtreeRoot.getParentDirect();
- if (parent != null) parentLocked = lockManager.lock(parent.getFqn(), WRITE, owner, stateFetchTimeout);
-
- // Remove the subtree
- cache.evict(subtree, true);
- //cache._evictSubtree(subtree);
-
- // Release locks
- if (parent != null)
- {
- log.debug("forcing release of locks in parent");
- lockManager.unlockAll(parent);
- }
-
- parentLocked = false;
-
- log.debug("forcing release of all locks in subtree");
- lockManager.unlockAll(subtreeRoot);
- subtreeLocked = false;
- }
- }
- }
- catch (InterruptedException e)
- {
- throw new CacheException(e);
- }
- finally
- {
- // If we didn't succeed, undo the marshalling change
- // NO. Since we inactivated, we may have missed changes
- //if (!success && !inactive)
- // marshaller_.activate(subtreeFqn);
-
- // If necessary, release locks
- if (parentLocked)
- {
- log.debug("forcing release of locks in parent");
- try
- {
- if (parent != null) lockManager.unlockAll(parent);
- }
- catch (Throwable t)
- {
- log.error("failed releasing locks", t);
- }
- }
- if (subtreeLocked)
- {
- log.debug("forcing release of all locks in subtree");
- try
- {
- if (subtreeRoot != null) lockManager.unlockAll(subtreeRoot);
- }
- catch (Throwable t)
- {
- log.error("failed releasing locks", t);
- }
- }
-
- activationChangeNodes.remove(fqn);
- }
- }
-
- private Object getOwnerForLock()
- {
- Object owner = cache.getCurrentTransaction();
- return owner == null ? Thread.currentThread() : owner;
- }
-
-
- /**
- * <p/>
- * This is legacy code and should not be called directly. This is a private method for now and will be refactored out.
- * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
- * <p/>
- *
- * @param fqn fqn of the region
- * @return true if the region defined by the fqn is in the process of activating/deactivating
- */
- private boolean isActivatingDeactivating(Fqn fqn)
- {
- return activationChangeNodes.contains(fqn);
- }
-
- /**
- * Returns true if the region exists
- *
- * @param fqn FQN of the region
- * @param type type of region to search for
- * @return true if the region exists
- */
- public boolean hasRegion(Fqn fqn, Region.Type type)
- {
- Region r = regionsRegistry.get(fqn);
- if (r == null) return false;
- switch (type)
- {
- case ANY:
- return true;
- case EVICTION:
- return r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r);
- case MARSHALLING:
- return r.isActive() && r.getClassLoader() != null;
- }
- // should never reach here?
- return false;
- }
-
- /**
- * Disables unmarshalling of replication messages for the region
- * rooted in the given Fqn.
- *
- * @param fqn
- */
- public void deactivate(Fqn fqn)
- {
- try
- {
- Region region = getRegion(fqn, false);
-
- if (region != null)
- {
- if (defaultInactive && region.getClassLoader() == null)
- {
- // This region's state will no match that of a non-existent one
- // So, there is no reason to keep this region any more
-
- // FIXME (Brian) We shouldn't do this anymore; now outside code can have a ref to the region!!
- removeRegion(fqn);
- }
- else
- {
- //region.deactivate();
- region.setActive(false);
- // FIXME - we should always clean up; otherwise stale data is in memory!
- if (cache.getConfiguration().isFetchInMemoryState())
- {
- inactivateRegion(fqn);
- }
- }
- }
- else if (!defaultInactive)
- {
- region = getRegion(fqn, true);
- region.setActive(false);
- // FIXME - we should always clean up; otherwise stale data is in memory!
- if (cache.getConfiguration().isFetchInMemoryState())
- {
- inactivateRegion(fqn);
- }
- }
- }
- catch (RuntimeException re)
- {
- throw re;
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Resets the region manager's regions registry
- */
- public void reset()
- {
- regionsRegistry.clear();
- }
-
- /**
- * Returns an ordered list of all regions.
- * Note that the ordered list returned is sorted according to the natural order defined in the {@link Comparable} interface, which {@link org.jboss.cache.Region} extends.
- *
- * @param type Type of region to return
- * @return an ordered list of all regions, based on the type requested.
- */
- public List<Region> getAllRegions(Region.Type type)
- {
- List<Region> regions;
-
- if (type != ANY)
- {
- regions = new ArrayList<Region>();
- // we need to loop thru the regions and only select specific regions to rtn.
- for (Region r : regionsRegistry.values())
- {
- if ((type == EVICTION && r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
- (type == MARSHALLING && r.isActive() && r.getClassLoader() != null))
- regions.add(r);
- }
- }
- else
- {
- // put all regions
- regions = new ArrayList<Region>(regionsRegistry.values());
- }
-
- Collections.sort(regions);
-
- return regions;
- }
-
- /**
- * Sets if evictions are processed.
- */
- public void setUsingEvictions(boolean usingEvictions)
- {
- this.usingEvictions = usingEvictions;
- }
-
- /**
- * Sets the eviction configuration.
- */
- public void setEvictionConfig(EvictionConfig evictionConfig)
- {
- this.evictionConfig = evictionConfig;
-
- // JBAS-1288
- // Try to establish a default region if there isn't one already
- boolean needDefault;
- List<EvictionRegionConfig> ercs = evictionConfig.getEvictionRegionConfigs();
- // Only add a default region if there are no regions. This is
- // contrary to the idea that there *must* be a default region, but some
- // unit tests fail w/ APPROACH 1, so for now we go with this approach.
- needDefault = ercs.size() == 0;
-
- if (needDefault)
- {
- // This may throw ConfigurationException if there is no default
- // eviction policy class
- EvictionRegionConfig dflt = evictionConfig.createDefaultEvictionRegionConfig();
- ercs.add(0, dflt); // put it first
- // Need to pass this back into the evictionConfig so it knows
- // about the new region
- evictionConfig.setEvictionRegionConfigs(ercs);
- }
-
- // create regions for the regions defined in the evictionConfig.
- // scan to be sure the _default_ region isn't added twice
- boolean setDefault = false;
- for (EvictionRegionConfig erc : ercs)
- {
- Fqn fqn = erc.getRegionFqn();
- if (log.isTraceEnabled()) log.trace("Creating eviction region " + fqn);
-
- if (fqn.equals(DEFAULT_REGION))
- {
- if (setDefault)
- {
- throw new ConfigurationException("A default region for evictions has already been set for this cache");
- }
- if (log.isTraceEnabled()) log.trace("Applying settings for " + DEFAULT_REGION + " to Fqn.ROOT");
- fqn = Fqn.ROOT;
- setDefault = true;
- }
- Region r = getRegion(fqn, true);
- r.setEvictionPolicy(erc.getEvictionPolicyConfig());
- }
- }
-
- /**
- * Starts the eviction processing thread.
- */
- public void startEvictionThread()
- {
- evictionTimerTask.init(evictionConfig.getWakeupInterval());
- }
-
- /**
- * Stops the eviction processing thread
- */
- public void stopEvictionThread()
- {
- evictionTimerTask.stop();
- }
-
-
- /**
- * Returns a string containing debug information on every region.
- *
- * @return Regions as a string
- */
- public String dumpRegions()
- {
- StringBuilder sb = new StringBuilder();
- for (Region r : regionsRegistry.values())
- {
- sb.append("\tRegion ").append(r);
- sb.append("\n");
- }
- return sb.toString();
- }
-
- /**
- * Returns a string containing debug information on every region.
- */
- @Override
- public String toString()
- {
- return "RegionManager " + dumpRegions();
- }
-
- public CacheSPI getCache()
- {
- return cache;
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -0,0 +1,179 @@
+package org.jboss.cache;
+
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.eviction.EvictionTimerTask;
+
+import java.util.List;
+
+/**
+ * Manages regions.
+ * <p/>
+ * Prior to 3.0.0, this was a concrete class. An interface was introduced in 3.0.0 for enhanced flexibility.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface RegionManager
+{
+ /**
+ * @return true if evictions are being processed.
+ */
+ boolean isUsingEvictions();
+
+ /**
+ * @return true if replication is by default inactive for new {@link org.jboss.cache.Region}s.
+ */
+ boolean isDefaultInactive();
+
+ /**
+ * Sets if replication for new {@link org.jboss.cache.Region}s is by default inactive.
+ */
+ void setDefaultInactive(boolean defaultInactive);
+
+ /**
+ * Helper utility that checks for a {@link ClassLoader} registered for the
+ * given {@link org.jboss.cache.Fqn}, and if found sets it as the TCCL. If the given Fqn is
+ * under the _BUDDY_BACKUP_ region, the equivalent region in the main
+ * cache is used to find the {@link ClassLoader}.
+ *
+ * @param fqn Fqn pointing to a region for which a special classloader
+ * may have been registered.
+ */
+ void setContextClassLoaderAsCurrent(Fqn fqn);
+
+ /**
+ * Returns a region by {@link org.jboss.cache.Fqn}, creating it optionally if absent. If the region does not exist and <tt>createIfAbsent</tt>
+ * is <tt>false</tt>, a parent region which may apply to the {@link org.jboss.cache.Fqn} is sought.
+ * <p/>
+ * Note that this takes into account the fact that this may be a Buddy Backup Fqn. If it is, the actual Fqn is calculated
+ * and used instead.
+ */
+ Region getRegion(Fqn fqn, boolean createIfAbsent);
+
+ /**
+ * Retrieves a valid marshalling {@link org.jboss.cache.Region} after taking into account that this may be a Buddy Backup Fqn.
+ * If the fqn passed in is null, the region has been deactivated or if a region cannot be found, this method returns a null.
+ *
+ * @param fqn of the region to locate
+ * @return a region
+ */
+ Region getValidMarshallingRegion(Fqn fqn);
+
+ /**
+ * An overloaded form of {@link #getRegion(org.jboss.cache.Fqn,boolean)} that takes an additional {@link org.jboss.cache.Region.Type}
+ * parameter to force regions of a specific type.
+ * <p/>
+ * Note that this takes into account the fact that this may be a Buddy Backup Fqn. If it is, the actual Fqn is calculated
+ * and used instead.
+ *
+ * @see org.jboss.cache.Region.Type
+ */
+ Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent);
+
+ /**
+ * Returns a region using Fqn.fromString(fqn), calling {@link #getRegion(org.jboss.cache.Fqn,boolean)}
+ *
+ * @param fqn
+ * @param createIfAbsent
+ * @see #getRegion(org.jboss.cache.Fqn,boolean)
+ */
+ Region getRegion(String fqn, boolean createIfAbsent);
+
+ /**
+ * Removes a {@link Region} identified by the given fqn.
+ *
+ * @param fqn fqn of the region to remove
+ * @return true if such a region existed and was removed.
+ */
+ boolean removeRegion(Fqn fqn);
+
+ /**
+ * Activates unmarshalling of replication messages for the region
+ * rooted in the given Fqn.
+ * <p/>
+ * <strong>NOTE:</strong> This method will cause the creation of a node
+ * in the local cache at <code>subtreeFqn</code> whether or not that
+ * node exists anywhere else in the cluster. If the node does not exist
+ * elsewhere, the local node will be empty. The creation of this node will
+ * not be replicated.
+ * <p/>
+ *
+ * @param fqn representing the region to be activated.
+ * @throws org.jboss.cache.RegionNotEmptyException
+ * if the node <code>fqn</code>
+ * exists and already has either data or children
+ */
+ void activate(Fqn fqn) throws RegionNotEmptyException;
+
+ /**
+ * Attempts to activate a given region rooted at a given Fqn, similar to {@link #activate(org.jboss.cache.Fqn)} except
+ * that if the fqn is currently already in use (probably already been activated) this method is a no-op.
+ *
+ * @param fqn which represents the region to activate
+ */
+ void activateIfEmpty(Fqn fqn);
+
+ /**
+ * Convenienve method. If the region defined by fqn does not exist, {@link #isDefaultInactive()} is returned, otherwise
+ * !{@link org.jboss.cache.Region#isActive()} is returned.
+ *
+ * @param fqn fqn to test
+ * @return true if inactive
+ */
+ boolean isInactive(Fqn fqn);
+
+ /**
+ * Returns true if the region exists
+ *
+ * @param fqn FQN of the region
+ * @param type type of region to search for
+ * @return true if the region exists
+ */
+ boolean hasRegion(Fqn fqn, Region.Type type);
+
+ /**
+ * Disables unmarshalling of replication messages for the region
+ * rooted in the given Fqn.
+ *
+ * @param fqn
+ */
+ void deactivate(Fqn fqn);
+
+ /**
+ * Resets the region manager's regions registry
+ */
+ void reset();
+
+ /**
+ * Returns an ordered list of all regions.
+ * Note that the ordered list returned is sorted according to the natural order defined in the {@link Comparable} interface, which {@link Region} extends.
+ *
+ * @param type Type of region to return
+ * @return an ordered list of all regions, based on the type requested.
+ */
+ List<Region> getAllRegions(Region.Type type);
+
+ /**
+ * Sets if evictions are processed.
+ */
+ void setUsingEvictions(boolean usingEvictions);
+
+ /**
+ * Sets the eviction configuration.
+ */
+ void setEvictionConfig(EvictionConfig evictionConfig);
+
+ /**
+ * Returns a string containing debug information on every region.
+ *
+ * @return Regions as a string
+ */
+ String dumpRegions();
+
+ CacheSPI getCache();
+
+ /**
+ * @return the eviction timer task attached to the region manager
+ */
+ EvictionTimerTask getEvictionTimerTask();
+}
Copied: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java (from rev 6183, core/trunk/src/main/java/org/jboss/cache/RegionManager.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -0,0 +1,789 @@
+package org.jboss.cache;
+
+import net.jcip.annotations.ThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import static org.jboss.cache.Region.Type.*;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.eviction.EvictionTimerTask;
+import org.jboss.cache.factories.annotations.Destroy;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.factories.annotations.Stop;
+import org.jboss.cache.lock.LockManager;
+import static org.jboss.cache.lock.LockType.WRITE;
+import org.jgroups.Address;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * The default region manager, used with MVCC locking.
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 3.0.0
+ */
+@ThreadSafe
+public class RegionManagerImpl implements RegionManager
+{
+ /**
+ * The default region used in XML configuration files when defining eviction policies. Any
+ * eviction settings bound under this 'default' Fqn is appplied to {@link org.jboss.cache.Fqn#ROOT} internally so
+ * any region that is not explicitly defined comes under the settings defined for this default.
+ */
+ public static final Fqn<?> DEFAULT_REGION = Fqn.fromString("/_default_");
+
+ /**
+ * A registry of regions that have been defined.
+ */
+ private final Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn, Region>();
+ private boolean defaultInactive;
+ private final Log log = LogFactory.getLog(RegionManagerImpl.class);
+ CacheSPI cache;
+ private boolean usingEvictions;
+ private EvictionConfig evictionConfig;
+ private final EvictionTimerTask evictionTimerTask = new EvictionTimerTask();
+
+ protected final Set<Fqn> activationChangeNodes = Collections.synchronizedSet(new HashSet<Fqn>());
+ protected Configuration configuration;
+ protected RPCManager rpcManager;
+ protected LockManager lockManager;
+ private BuddyFqnTransformer buddyFqnTransformer;
+ private boolean isUsingBR;
+
+ @Inject
+ void injectDependencies(CacheSPI cache, Configuration configuration, RPCManager rpcManager, LockManager lockManager,
+ BuddyFqnTransformer transformer)
+ {
+ this.cache = cache;
+ this.rpcManager = rpcManager;
+ this.configuration = configuration;
+ this.lockManager = lockManager;
+ this.buddyFqnTransformer = transformer;
+ }
+
+ @Start
+ protected void start()
+ {
+ log.trace("Starting region manager");
+ isUsingBR = configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled();
+ if (configuration.getEvictionConfig() != null
+ && configuration.getEvictionConfig().isValidConfig())
+ {
+ // validate individual region configs now
+ for (EvictionRegionConfig erc : configuration.getEvictionConfig().getEvictionRegionConfigs())
+ {
+ EvictionPolicyConfig epc = erc.getEvictionPolicyConfig();
+ if (epc != null) epc.validate();
+ }
+
+ setEvictionConfig(configuration.getEvictionConfig());
+ setUsingEvictions(true);
+ }
+ else
+ {
+ setUsingEvictions(false);
+ log.debug("Not using an EvictionPolicy");
+ }
+
+ setDefaultInactive(configuration.isInactiveOnStartup());
+
+ if (isUsingEvictions()) evictionTimerTask.init(evictionConfig.getWakeupInterval());
+ }
+
+ @Stop
+ protected void stop()
+ {
+ if (isUsingEvictions()) evictionTimerTask.stop();
+ }
+
+ @Destroy
+ protected void destroy()
+ {
+ regionsRegistry.clear();
+ activationChangeNodes.clear();
+ }
+
+ public boolean isUsingEvictions()
+ {
+ return usingEvictions;
+ }
+
+ public boolean isDefaultInactive()
+ {
+ return defaultInactive;
+ }
+
+ public void setDefaultInactive(boolean defaultInactive)
+ {
+ this.defaultInactive = defaultInactive;
+ Region defaultRegion = regionsRegistry.get(Fqn.ROOT);
+ if (defaultRegion != null) defaultRegion.setActive(!defaultInactive);
+ }
+
+ public void setContextClassLoaderAsCurrent(Fqn fqn)
+ {
+ if (fqn.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN))
+ {
+ if (fqn.size() <= 2)
+ {
+ fqn = Fqn.ROOT;
+ }
+ else
+ {
+ fqn = fqn.getSubFqn(2, fqn.size());
+ }
+ }
+ Region region = getRegion(fqn, false);
+ ClassLoader regionCL = (region == null) ? null : region.getClassLoader();
+ if (regionCL != null)
+ {
+ Thread.currentThread().setContextClassLoader(regionCL);
+ }
+
+ }
+
+ public Region getRegion(Fqn fqn, boolean createIfAbsent)
+ {
+ return getRegion(fqn, ANY, createIfAbsent);
+ }
+
+ public Region getValidMarshallingRegion(Fqn fqn)
+ {
+ if (fqn == null) return null;
+ return getRegion(fqn, Region.Type.MARSHALLING, false);
+ }
+
+ public Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent)
+ {
+ if (isUsingBR && fqn != null && buddyFqnTransformer.isBackupFqn(fqn))
+ {
+ fqn = buddyFqnTransformer.getActualFqn(fqn);
+ }
+
+ if (log.isTraceEnabled()) log.trace("Contents of RegionsRegistry: " + regionsRegistry);
+ Fqn fqnToUse = fqn;
+ if (DEFAULT_REGION.equals(fqnToUse)) fqnToUse = Fqn.ROOT;
+ // first see if a region for this specific Fqn exists
+ if (regionsRegistry.containsKey(fqnToUse))
+ {
+ Region r = regionsRegistry.get(fqnToUse);
+
+ // this is a very poor way of telling whether a region is a marshalling one or an eviction one. :-(
+ // mandates that class loaders be registered for marshalling regions.
+ if (type == ANY
+ || (type == MARSHALLING && r.getClassLoader() != null)
+ || (type == EVICTION && r.getEvictionPolicyConfig() != null))
+ {
+ return r;
+ }
+ }
+
+ // if not, attempt to create one ...
+ if (createIfAbsent)
+ {
+ Region r = new RegionImpl(fqnToUse, this);
+ regionsRegistry.put(fqnToUse, r);
+ if (type == MARSHALLING)
+ {
+ // insert current class loader into region so at least it is recognised as a marshalling region
+ r.registerContextClassLoader(getClass().getClassLoader());
+ }
+ return r;
+ }
+
+ // else try and find a parent which has a defined region, may return null if nothing is defined.
+ Region nextBestThing = null;
+ Fqn nextFqn = fqnToUse;
+
+ while (nextBestThing == null)
+ {
+ nextFqn = nextFqn.getParent();
+ if (regionsRegistry.containsKey(nextFqn))
+ {
+ Region r = regionsRegistry.get(nextFqn);
+ if (log.isTraceEnabled()) log.trace("Trying next region " + nextFqn + " and got " + r);
+
+ // this is a very poor way of telling whether a region is a marshalling one or an eviction one. :-(
+ // mandates that class loaders be registered for marshalling regions.
+ if (type == ANY
+ || (type == MARSHALLING && r.getClassLoader() != null)
+ || (type == EVICTION && r.getEvictionPolicyConfig() != null))
+ {
+ nextBestThing = r;
+ }
+ }
+ if (nextFqn.isRoot()) break;
+ }
+
+ // test if the default region has been defined. If not, and if the request
+ // is for an eviction region, return null
+ if (type == EVICTION && nextBestThing != null && nextBestThing.getFqn().isRoot() && !regionsRegistry.containsKey(Fqn.ROOT))
+ {
+ log.trace("No default eviction region; returning null");
+ nextBestThing = null;
+ }
+
+ return nextBestThing;
+ }
+
+ public Region getRegion(String fqn, boolean createIfAbsent)
+ {
+ return getRegion(Fqn.fromString(fqn), createIfAbsent);
+ }
+
+ public boolean removeRegion(Fqn fqn)
+ {
+ Region r = regionsRegistry.remove(fqn);
+ if (r == null) return false;
+
+ if (isUsingEvictions() && r.getEvictionPolicy() != null)
+ {
+ evictionTimerTask.removeRegionToProcess(r);
+ }
+ return true;
+ }
+
+ public EvictionTimerTask getEvictionTimerTask()
+ {
+ return evictionTimerTask;
+ }
+
+ public void activate(Fqn fqn) throws RegionNotEmptyException
+ {
+ activate(fqn, false);
+ }
+
+ public void activateIfEmpty(Fqn fqn)
+ {
+ activate(fqn, true);
+ }
+
+ private void activate(Fqn fqn, boolean suppressRegionNotEmptyException)
+ {
+ try
+ {
+ if (log.isTraceEnabled()) log.trace("Activating region " + fqn);
+ Region r = getRegion(fqn, false);
+ if (r != null)
+ {
+ if (!defaultInactive && r.getClassLoader() == null)
+ {
+ // This region's state will no match that of a non-existent one
+ // So, there is no reason to keep this region any more
+
+ // (Brian) We shouldn't do this anymore; now outside code
+ // can have a ref to the region!!
+ removeRegion(fqn);
+ }
+ else
+ {
+ //r.activate();
+ r.setStatus(Region.Status.ACTIVATING);
+ if (configuration.isFetchInMemoryState())
+ {
+ activateRegion(r.getFqn(), suppressRegionNotEmptyException);
+ }
+ r.setActive(true);
+ }
+ }
+ else if (defaultInactive)
+ {
+ // "Active" region is not the default, so create a region
+ r = getRegion(fqn, true);
+ // FIXME - persistent state transfer counts too!
+ r.setStatus(Region.Status.ACTIVATING);
+ if (configuration.isFetchInMemoryState())
+ {
+ activateRegion(r.getFqn(), suppressRegionNotEmptyException);
+ }
+ r.setActive(true);
+ }
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Causes the cache to transfer state for the subtree rooted at
+ * <code>subtreeFqn</code> and to begin accepting replication messages
+ * for that subtree.
+ * <p/>
+ * <strong>NOTE:</strong> This method will cause the creation of a node
+ * in the local cache at <code>subtreeFqn</code> whether or not that
+ * node exists anywhere else in the cluster. If the node does not exist
+ * elsewhere, the local node will be empty. The creation of this node will
+ * not be replicated.
+ *
+ * @param fqn Fqn string indicating the uppermost node in the
+ * portion of the cache that should be activated.
+ * @throws RegionNotEmptyException if the node <code>subtreeFqn</code>
+ * exists and has either data or children
+ */
+ private void activateRegion(Fqn fqn, boolean suppressRegionNotEmptyException)
+ {
+ // Check whether the node already exists and has data
+ Node subtreeRoot = cache.peek(fqn, false, false);
+
+ /*
+ * Commented out on Nov 16,2006 Manik&Vladimir
+ *
+ * if (!(cache.isNodeEmpty(subtreeRoot)))
+ {
+ throw new RegionNotEmptyException("Node " + subtreeRoot.getFqn() + " already exists and is not empty");
+ }*/
+
+ if (isActivatingDeactivating(fqn))
+ {
+ throw new CacheException("Region " + subtreeRoot.getFqn() + " is already being activated/deactivated");
+ }
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("activating " + fqn);
+ }
+
+ try
+ {
+
+ // Add this fqn to the set of those we are activating
+ // so calls to _getState for the fqn can return quickly
+ activationChangeNodes.add(fqn);
+
+ BuddyManager buddyManager = cache.getBuddyManager();
+ // Request partial state from the cluster and integrate it
+ if (buddyManager == null)
+ {
+ // Get the state from any node that has it and put it
+ // in the main cache
+ if (subtreeRoot == null)
+ {
+ // We'll update this node with the state we receive
+ // need to obtain all necessary locks.
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ subtreeRoot = cache.getRoot().addChild(fqn);
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ }
+
+ List<Address> members = cache.getMembers();
+
+ // Don't bother trying to fetch state if we are in LOCAL mode
+ if (members != null && !members.isEmpty())
+ rpcManager.fetchPartialState(members, subtreeRoot.getFqn());
+ }
+ else if (!buddyFqnTransformer.isBackupFqn(fqn))
+ {
+ // Get the state from each DataOwner and integrate in their
+ // respective buddy backup cache
+ List<Address> buddies = buddyManager.getBackupDataOwners();
+ for (Address buddy : buddies)
+ {
+ List<Address> sources = new ArrayList<Address>(1);
+ if (!cache.getMembers().contains(buddy))
+ continue;
+ sources.add(buddy);
+ Fqn buddyRoot = buddyFqnTransformer.getBackupFqn(buddy, fqn);
+ subtreeRoot = cache.peek(buddyRoot, false, false);
+ if (subtreeRoot == null)
+ {
+ // We'll update this node with the state we receive
+ // need to obtain all necessary locks.
+ // needs to be a LOCAL call!
+ NodeSPI root = cache.getRoot();
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ subtreeRoot = root.addChild(buddyRoot);
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ }
+ rpcManager.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
+ }
+ }
+ else
+ {
+ log.info("Attempting to activate a backup region. Not attempting to retrieve any state as this will be pushed.");
+ }
+ }
+ catch (Throwable t)
+ {
+ log.error("failed to activate " + fqn, t);
+
+ // "Re-deactivate" the region
+ try
+ {
+ inactivateRegion(fqn);
+ }
+ catch (Exception e)
+ {
+ log.error("failed inactivating " + fqn, e);
+ // just swallow this one and throw the first one
+ }
+
+ // Throw the exception on, wrapping if necessary
+ if (t instanceof RegionNotEmptyException)
+ {
+ if (!suppressRegionNotEmptyException) throw (RegionNotEmptyException) t;
+ }
+ else if (t instanceof CacheException)
+ {
+ throw (CacheException) t;
+ }
+ else
+ {
+ throw new CacheException(t.getClass().getName() + " " +
+ t.getLocalizedMessage(), t);
+ }
+ }
+ finally
+ {
+ activationChangeNodes.remove(fqn);
+ }
+ }
+
+ public boolean isInactive(Fqn fqn)
+ {
+ Region region = getRegion(fqn, false);
+ return region == null ? defaultInactive : !region.isActive();
+ }
+
+
+ /**
+ * Causes the cache to stop accepting replication events for the subtree
+ * rooted at <code>subtreeFqn</code> and evict all nodes in that subtree.
+ * <p/>
+ * This is legacy code and should not be called directly. This is a private method for now and will be refactored out.
+ * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
+ * <p/>
+ *
+ * @param fqn Fqn string indicating the uppermost node in the
+ * portion of the cache that should be activated.
+ * @throws RegionNameConflictException if <code>subtreeFqn</code> indicates
+ * a node that is part of another
+ * subtree that is being specially
+ * managed (either by activate/inactiveRegion()
+ * or by registerClassLoader())
+ * @throws CacheException if there is a problem evicting nodes
+ * @throws IllegalStateException if {@link org.jboss.cache.config.Configuration#isUseRegionBasedMarshalling()} is <code>false</code>
+ */
+ private void inactivateRegion(Fqn fqn) throws CacheException
+ {
+ if (isActivatingDeactivating(fqn))
+ {
+ throw new CacheException("Region " + fqn + " is already being activated/deactivated");
+ }
+
+ NodeSPI parent = null;
+ NodeSPI subtreeRoot = null;
+ boolean parentLocked = false;
+ boolean subtreeLocked = false;
+
+ try
+ {
+ // Record that this fqn is in status change, so can't provide state
+ activationChangeNodes.add(fqn);
+
+ if (!isInactive(fqn))
+ {
+ deactivate(fqn);
+ }
+
+ // Create a list with the Fqn in the main cache and any buddy backup trees
+ BuddyManager buddyManager = cache.getBuddyManager();
+ ArrayList<Fqn> list = new ArrayList<Fqn>();
+ list.add(fqn);
+
+ if (buddyManager != null)
+ {
+ Set buddies = cache.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, false, false).getChildrenNames();
+ if (buddies != null)
+ {
+ for (Object buddy : buddies)
+ {
+ list.add(buddyFqnTransformer.getBackupFqn((String) buddy, fqn));
+ }
+ }
+ }
+
+ long stateFetchTimeout = cache.getConfiguration().getLockAcquisitionTimeout() + 5000;
+ // Remove the subtree from the main cache and any buddy backup trees
+ for (Fqn subtree : list)
+ {
+ subtreeRoot = cache.peek(subtree, false);
+ if (subtreeRoot != null)
+ {
+ // Acquire locks
+ subtreeLocked = lockManager.lockAll(subtreeRoot, WRITE, getOwnerForLock(), stateFetchTimeout);
+
+ // Lock the parent, as we're about to write to it
+ parent = subtreeRoot.getParentDirect();
+ if (parent != null)
+ parentLocked = lockManager.lockAll(parent, WRITE, getOwnerForLock(), stateFetchTimeout);
+
+ // Remove the subtree
+ cache.evict(subtree, true);
+ //cache._evictSubtree(subtree);
+
+ // Release locks
+ if (parent != null)
+ {
+ log.debug("forcing release of locks in parent");
+ lockManager.unlockAll(parent);
+ }
+
+ parentLocked = false;
+
+ log.debug("forcing release of all locks in subtree");
+ lockManager.unlockAll(subtreeRoot);
+ subtreeLocked = false;
+ }
+ }
+ }
+ catch (InterruptedException e)
+ {
+ throw new CacheException(e);
+ }
+ finally
+ {
+ // If we didn't succeed, undo the marshalling change
+ // NO. Since we inactivated, we may have missed changes
+ //if (!success && !inactive)
+ // marshaller_.activate(subtreeFqn);
+
+ // If necessary, release locks
+ if (parentLocked)
+ {
+ log.debug("forcing release of locks in parent");
+ try
+ {
+ if (parent != null) lockManager.unlockAll(parent);
+ }
+ catch (Throwable t)
+ {
+ log.error("failed releasing locks", t);
+ }
+ }
+ if (subtreeLocked)
+ {
+ log.debug("forcing release of all locks in subtree");
+ try
+ {
+ if (subtreeRoot != null) lockManager.unlockAll(subtreeRoot);
+ }
+ catch (Throwable t)
+ {
+ log.error("failed releasing locks", t);
+ }
+ }
+
+ activationChangeNodes.remove(fqn);
+ }
+ }
+
+ // MVCC deduces lock owners implicitly.
+ protected Object getOwnerForLock()
+ {
+ return null;
+ }
+
+ /**
+ * <p/>
+ * This is legacy code and should not be called directly. This is a private method for now and will be refactored out.
+ * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
+ * <p/>
+ *
+ * @param fqn fqn of the region
+ * @return true if the region defined by the fqn is in the process of activating/deactivating
+ */
+ private boolean isActivatingDeactivating(Fqn fqn)
+ {
+ return activationChangeNodes.contains(fqn);
+ }
+
+ public boolean hasRegion(Fqn fqn, Region.Type type)
+ {
+ Region r = regionsRegistry.get(fqn);
+ if (r == null) return false;
+ switch (type)
+ {
+ case ANY:
+ return true;
+ case EVICTION:
+ return r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r);
+ case MARSHALLING:
+ return r.isActive() && r.getClassLoader() != null;
+ }
+ // should never reach here?
+ return false;
+ }
+
+ public void deactivate(Fqn fqn)
+ {
+ try
+ {
+ Region region = getRegion(fqn, false);
+
+ if (region != null)
+ {
+ if (defaultInactive && region.getClassLoader() == null)
+ {
+ // This region's state will no match that of a non-existent one
+ // So, there is no reason to keep this region any more
+
+ // FIXME (Brian) We shouldn't do this anymore; now outside code can have a ref to the region!!
+ removeRegion(fqn);
+ }
+ else
+ {
+ //region.deactivate();
+ region.setActive(false);
+ // FIXME - we should always clean up; otherwise stale data is in memory!
+ if (cache.getConfiguration().isFetchInMemoryState())
+ {
+ inactivateRegion(fqn);
+ }
+ }
+ }
+ else if (!defaultInactive)
+ {
+ region = getRegion(fqn, true);
+ region.setActive(false);
+ // FIXME - we should always clean up; otherwise stale data is in memory!
+ if (cache.getConfiguration().isFetchInMemoryState())
+ {
+ inactivateRegion(fqn);
+ }
+ }
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void reset()
+ {
+ regionsRegistry.clear();
+ }
+
+ public List<Region> getAllRegions(Region.Type type)
+ {
+ List<Region> regions;
+
+ if (type != ANY)
+ {
+ regions = new ArrayList<Region>();
+ // we need to loop thru the regions and only select specific regions to rtn.
+ for (Region r : regionsRegistry.values())
+ {
+ if ((type == EVICTION && r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
+ (type == MARSHALLING && r.isActive() && r.getClassLoader() != null))
+ regions.add(r);
+ }
+ }
+ else
+ {
+ // put all regions
+ regions = new ArrayList<Region>(regionsRegistry.values());
+ }
+
+ Collections.sort(regions);
+
+ return regions;
+ }
+
+ public void setUsingEvictions(boolean usingEvictions)
+ {
+ this.usingEvictions = usingEvictions;
+ }
+
+ public void setEvictionConfig(EvictionConfig evictionConfig)
+ {
+ this.evictionConfig = evictionConfig;
+
+ // JBAS-1288
+ // Try to establish a default region if there isn't one already
+ boolean needDefault;
+ List<EvictionRegionConfig> ercs = evictionConfig.getEvictionRegionConfigs();
+ // Only add a default region if there are no regions. This is
+ // contrary to the idea that there *must* be a default region, but some
+ // unit tests fail w/ APPROACH 1, so for now we go with this approach.
+ needDefault = ercs.size() == 0;
+
+ if (needDefault)
+ {
+ // This may throw ConfigurationException if there is no default
+ // eviction policy class
+ EvictionRegionConfig dflt = evictionConfig.createDefaultEvictionRegionConfig();
+ ercs.add(0, dflt); // put it first
+ // Need to pass this back into the evictionConfig so it knows
+ // about the new region
+ evictionConfig.setEvictionRegionConfigs(ercs);
+ }
+
+ // create regions for the regions defined in the evictionConfig.
+ // scan to be sure the _default_ region isn't added twice
+ boolean setDefault = false;
+ for (EvictionRegionConfig erc : ercs)
+ {
+ Fqn fqn = erc.getRegionFqn();
+ if (log.isTraceEnabled()) log.trace("Creating eviction region " + fqn);
+
+ if (fqn.equals(DEFAULT_REGION))
+ {
+ if (setDefault)
+ {
+ throw new ConfigurationException("A default region for evictions has already been set for this cache");
+ }
+ if (log.isTraceEnabled()) log.trace("Applying settings for " + DEFAULT_REGION + " to Fqn.ROOT");
+ fqn = Fqn.ROOT;
+ setDefault = true;
+ }
+ Region r = getRegion(fqn, true);
+ r.setEvictionPolicy(erc.getEvictionPolicyConfig());
+ }
+ }
+
+ public String dumpRegions()
+ {
+ StringBuilder sb = new StringBuilder();
+ for (Region r : regionsRegistry.values())
+ {
+ sb.append("\tRegion ").append(r);
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns a string containing debug information on every region.
+ */
+ @Override
+ public String toString()
+ {
+ return "RegionManager " + dumpRegions();
+ }
+
+ public CacheSPI getCache()
+ {
+ return cache;
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -21,10 +21,9 @@
*/
package org.jboss.cache.config;
-import org.jboss.cache.RegionManager;
import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.util.Util;
import java.util.ArrayList;
import java.util.List;
@@ -45,7 +44,9 @@
@Deprecated
private int wakeupIntervalSeconds = WAKEUP_DEFAULT;
- /** value expressed in millis */
+ /**
+ * value expressed in millis
+ */
@Dynamic
private long wakeupInterval = WAKEUP_DEFAULT * 1000;
@@ -83,13 +84,13 @@
/**
* Creates an EvictionRegionConfig for the
- * {@link RegionManager.DEFAULT_REGION "_default_"} region using the
+ * {@link org.jboss.cache.RegionManagerImpl.DEFAULT_REGION "_default_"} region using the
* {@link #getDefaultEvictionPolicyClass(String) default eviction policy class}. Throws a
* {@link ConfigurationException} if
* {@link #setDefaultEvictionPolicyClass(String) a default eviction policy class}
* has not been set.
*
- * @return an EvictionRegionConfig whose FQN is {@link RegionManager.DEFAULT_REGION}
+ * @return an EvictionRegionConfig whose FQN is {@link org.jboss.cache.RegionManagerImpl.DEFAULT_REGION}
* and whose EvictionPolicyConfig is the default config for the
* default eviction policy class.
* @throws ConfigurationException if a
@@ -107,7 +108,7 @@
EvictionRegionConfig erc = new EvictionRegionConfig();
EvictionPolicyConfig epc = policy.getEvictionConfigurationClass().newInstance();
erc.setEvictionPolicyConfig(epc);
- erc.setRegionFqn(RegionManager.DEFAULT_REGION);
+ erc.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
return erc;
}
catch (Exception e)
@@ -157,18 +158,22 @@
this.evictionRegionConfigs = evictionRegionConfigs;
}
- /** value expressed in millis */
+ /**
+ * value expressed in millis
+ */
public long getWakeupInterval()
{
return wakeupInterval;
}
- /** value expressed in millis */
+ /**
+ * value expressed in millis
+ */
public void setWakeupInterval(long wakeupInterval)
{
testImmutability("WakeupInterval");
this.wakeupInterval = wakeupInterval;
- this.wakeupIntervalSeconds = (int)wakeupInterval/1000;
+ this.wakeupIntervalSeconds = (int) wakeupInterval / 1000;
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,20 +1,20 @@
package org.jboss.cache.config.parsing.element;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.config.parsing.XmlParserBase;
import org.jboss.cache.config.parsing.ParsedAttributes;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.XmlParserBase;
import org.jboss.cache.eviction.EvictionPolicy;
import org.jboss.cache.util.Util;
-import org.jboss.cache.RegionManager;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import java.util.ArrayList;
import java.util.List;
-import java.util.ArrayList;
/**
* Knows how to parse the <b>eviction</b> xml element.
@@ -44,7 +44,7 @@
if (rootRegion != null)
{
EvictionRegionConfig erc = getEvictionRegionConfig(rootRegion, defaultPolicyClass, defaultEvQueueSize);
- erc.setRegionName(RegionManager.DEFAULT_REGION.toString());
+ erc.setRegionName(RegionManagerImpl.DEFAULT_REGION.toString());
evictionRegionConfigs.add(erc);
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/BootstrapFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/BootstrapFactory.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/BootstrapFactory.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -7,7 +7,7 @@
import org.jboss.cache.factories.annotations.NonVolatile;
/**
- * // TODO: MANIK: Document this
+ * Factory for setting up bootstrap components
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.2.0
@@ -28,8 +28,8 @@
protected <T> T construct(Class<T> componentType)
{
if (componentType.isAssignableFrom(CacheSPI.class) ||
- componentType.isAssignableFrom(Configuration.class) ||
- componentType.isAssignableFrom(ComponentRegistry.class))
+ componentType.isAssignableFrom(Configuration.class) ||
+ componentType.isAssignableFrom(ComponentRegistry.class))
{
return componentType.cast(cacheSPI);
}
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,115 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.buddyreplication.BuddyGroup;
-import org.jboss.cache.commands.DataCommand;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.commands.WriteCommand;
-import org.jboss.cache.commands.read.ExistsCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.read.GetDataMapCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetKeysCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.read.GravitateDataCommand;
-import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
-import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand;
-import org.jboss.cache.commands.remote.ClusteredGetCommand;
-import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
-import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
-import org.jboss.cache.commands.remote.ReplicateCommand;
-import org.jboss.cache.commands.tx.CommitCommand;
-import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
-import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.commands.write.*;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jgroups.Address;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Factory for all types of cache commands.
- * Here are some of the purposes of this class:
- * <pre>
- * - not creating <code>CacheCommands</code> directly (i.e. through new usage) as this would reduce unit testability
- * - reduce the coupling between commands and other components. e.g. considering a commands that needs to knwo whether
- * locking type is optimistic, we will pass in a 'optimistic' boolean flag rather than entire Configuration object
- * </pre>
- * <p/>
- * <b>Note:</b> As of 3.0, this is now an interface.
- * <p/>
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 2.2
- */
-public interface CommandsFactory
-{
- PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data);
-
- PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value);
-
- PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value);
-
- ReplicateCommand buildReplicateCommand(ReplicableCommand command);
-
- ReplicateCommand buildReplicateCommand(List<ReplicableCommand> modifications);
-
- PrepareCommand buildPrepareCommand(GlobalTransaction gtx, WriteCommand command, boolean onePhaseCommit);
-
- PrepareCommand buildPrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address address, boolean onePhaseCommit);
-
- CommitCommand buildCommitCommand(GlobalTransaction gtx);
-
- DataGravitationCleanupCommand buildDataGravitationCleanupCommand(Fqn primaryFqn, Fqn backupFqn);
-
- GravitateDataCommand buildGravitateDataCommand(Fqn fqn, Boolean searchSubtrees);
-
- RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn);
-
- ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn);
-
- EvictCommand buildEvictFqnCommand(Fqn fqn);
-
- InvalidateCommand buildInvalidateCommand(Fqn fqn);
-
- RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn, Object key);
-
- GetDataMapCommand buildGetDataMapCommand(Fqn fqn);
-
- ExistsCommand buildExistsNodeCommand(Fqn fqn);
-
- GetKeyValueCommand buildGetKeyValueCommand(Fqn<?> fqn, Object key, boolean sendNodeEvent);
-
- GetNodeCommand buildGetNodeCommand(Fqn fqn);
-
- GetKeysCommand buildGetKeysCommand(Fqn fqn);
-
- GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn);
-
- MoveCommand buildMoveCommand(Fqn from, Fqn to);
-
- RollbackCommand buildRollbackCommand(GlobalTransaction gtx);
-
- OptimisticPrepareCommand buildOptimisticPrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address address, boolean onePhaseCommit);
-
- AnnounceBuddyPoolNameCommand buildAnnounceBuddyPoolNameCommand(Address address, String buddyPoolName);
-
- RemoveFromBuddyGroupCommand buildRemoveFromBuddyGroupCommand(String groupName);
-
- AssignToBuddyGroupCommand buildAssignToBuddyGroupCommand(BuddyGroup group, Map<Fqn, byte[]> state);
-
- ClusteredGetCommand buildClusteredGetCommand(Boolean searchBackupSubtrees, DataCommand dataCommand);
-
- CreateNodeCommand buildCreateNodeCommand(Fqn fqn);
-
- /**
- * Builds a cache command based on the ID passed in and an object array of parameters
- *
- * @param id id of the command to build
- * @param parameters parameters attached to the command
- * @return a newly constructed cache command
- */
- ReplicableCommand fromStream(int id, Object[] parameters);
-}
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,511 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DataContainer;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.RPCManager;
-import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-import org.jboss.cache.buddyreplication.BuddyGroup;
-import org.jboss.cache.buddyreplication.BuddyManager;
-import org.jboss.cache.commands.DataCommand;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.commands.WriteCommand;
-import org.jboss.cache.commands.read.ExistsCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.read.GetDataMapCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetKeysCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.read.GravitateDataCommand;
-import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
-import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand;
-import org.jboss.cache.commands.remote.ClusteredGetCommand;
-import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
-import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
-import org.jboss.cache.commands.remote.ReplicateCommand;
-import org.jboss.cache.commands.tx.CommitCommand;
-import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
-import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.CreateNodeCommand;
-import org.jboss.cache.commands.write.EvictCommand;
-import org.jboss.cache.commands.write.InvalidateCommand;
-import org.jboss.cache.commands.write.MoveCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.commands.write.VersionedInvalidateCommand;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.interceptors.InterceptorChain;
-import org.jboss.cache.notifications.Notifier;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionTable;
-import org.jgroups.Address;
-
-import javax.transaction.TransactionManager;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-/**
- * This is the implementation to use for most commands and most locking schemes.
- */
-public class CommandsFactoryImpl implements CommandsFactory
-{
- protected RPCManager rpcManager;
- protected DataContainer dataContainer;
- protected Notifier notifier;
- protected InterceptorChain invoker;
- protected BuddyManager buddyManager;
- protected TransactionTable transactionTable;
- protected CacheSPI cacheSpi;
- protected Configuration configuration;
- protected TransactionManager txManager;
- protected BuddyFqnTransformer buddyFqnTransformer;
-
- public CommandsFactoryImpl()
- {
- }
-
- @Inject
- public void initialize(RPCManager rpc, DataContainer dataContainer, Notifier notifier, BuddyManager buddyManager,
- InterceptorChain invoker, TransactionTable transactionTable, CacheSPI cacheSpi,
- Configuration configuration, TransactionManager txManager, BuddyFqnTransformer buddyFqnTransformer)
- {
- this.rpcManager = rpc;
- this.dataContainer = dataContainer;
- this.notifier = notifier;
- this.buddyManager = buddyManager;
- this.invoker = invoker;
- this.transactionTable = transactionTable;
- this.cacheSpi = cacheSpi;
- this.configuration = configuration;
- this.txManager = txManager;
- this.buddyFqnTransformer = buddyFqnTransformer;
- }
-
- public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data)
- {
- PutDataMapCommand cmd = new PutDataMapCommand(gtx, fqn, data);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
- {
- PutKeyValueCommand cmd = new PutKeyValueCommand(gtx, fqn, key, value);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
- {
- PutForExternalReadCommand cmd = new PutForExternalReadCommand(gtx, fqn, key, value);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public ReplicateCommand buildReplicateCommand(ReplicableCommand command)
- {
- ReplicateCommand cmd = new ReplicateCommand(command);
- cmd.initialize(invoker);
- return cmd;
- }
-
- public ReplicateCommand buildReplicateCommand(List<ReplicableCommand> modifications)
- {
- ReplicateCommand cmd = new ReplicateCommand(modifications);
- cmd.initialize(invoker);
- return cmd;
- }
-
- public PrepareCommand buildPrepareCommand(GlobalTransaction gtx, WriteCommand command, boolean onePhaseCommit)
- {
- return buildPrepareCommand(gtx, Collections.singletonList(command), rpcManager.getLocalAddress(), onePhaseCommit);
- }
-
- public PrepareCommand buildPrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address address, boolean onePhaseCommit)
- {
- return new PrepareCommand(gtx, modifications, address, onePhaseCommit);
- }
-
- public CommitCommand buildCommitCommand(GlobalTransaction gtx)
- {
- return new CommitCommand(gtx);
- }
-
- public DataGravitationCleanupCommand buildDataGravitationCleanupCommand(Fqn primaryFqn, Fqn backupFqn)
- {
- DataGravitationCleanupCommand command = new DataGravitationCleanupCommand(primaryFqn, backupFqn);
- command.initialize(buddyManager, invoker, transactionTable, this, dataContainer, buddyFqnTransformer);
- return command;
- }
-
- public GravitateDataCommand buildGravitateDataCommand(Fqn fqn, Boolean searchSubtrees)
- {
- GravitateDataCommand command = new GravitateDataCommand(fqn, searchSubtrees, rpcManager.getLocalAddress());
- command.initialize(dataContainer, cacheSpi, buddyFqnTransformer);
- return command;
- }
-
- public EvictCommand buildEvictFqnCommand(Fqn fqn)
- {
- EvictCommand command = new EvictCommand(fqn);
- command.initialize(notifier, dataContainer);
- return command;
- }
-
- public InvalidateCommand buildInvalidateCommand(Fqn fqn)
- {
- if (configuration.getNodeLockingScheme().isVersionedScheme())
- {
- VersionedInvalidateCommand command = new VersionedInvalidateCommand(fqn);
- command.initialize(txManager);
- command.initialize(cacheSpi, dataContainer, notifier);
- return command;
- }
- else
- {
- InvalidateCommand command = new InvalidateCommand(fqn);
- command.initialize(cacheSpi, dataContainer, notifier);
- return command;
- }
- }
-
- public GetDataMapCommand buildGetDataMapCommand(Fqn fqn)
- {
- GetDataMapCommand command = new GetDataMapCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public ExistsCommand buildExistsNodeCommand(Fqn fqn)
- {
- ExistsCommand command = new ExistsCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public GetKeyValueCommand buildGetKeyValueCommand(Fqn<?> fqn, Object key, boolean sendNodeEvent)
- {
- GetKeyValueCommand command = new GetKeyValueCommand(fqn, key, sendNodeEvent);
- command.initialize(dataContainer, notifier);
- return command;
- }
-
- public GetNodeCommand buildGetNodeCommand(Fqn fqn)
- {
- GetNodeCommand command = new GetNodeCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public GetKeysCommand buildGetKeysCommand(Fqn fqn)
- {
- GetKeysCommand command = new GetKeysCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn)
- {
- GetChildrenNamesCommand command = new GetChildrenNamesCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public RollbackCommand buildRollbackCommand(GlobalTransaction gtx)
- {
- return new RollbackCommand(gtx);
- }
-
- public OptimisticPrepareCommand buildOptimisticPrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address address, boolean onePhaseCommit)
- {
- return new OptimisticPrepareCommand(gtx, modifications, address, onePhaseCommit);
- }
-
- public AnnounceBuddyPoolNameCommand buildAnnounceBuddyPoolNameCommand(Address address, String buddyPoolName)
- {
- AnnounceBuddyPoolNameCommand command = new AnnounceBuddyPoolNameCommand(address, buddyPoolName);
- command.initialize(buddyManager);
- return command;
- }
-
- public RemoveFromBuddyGroupCommand buildRemoveFromBuddyGroupCommand(String groupName)
- {
- RemoveFromBuddyGroupCommand command = new RemoveFromBuddyGroupCommand(groupName);
- command.initialize(buddyManager);
- return command;
- }
-
- public AssignToBuddyGroupCommand buildAssignToBuddyGroupCommand(BuddyGroup group, Map<Fqn, byte[]> state)
- {
- AssignToBuddyGroupCommand command = new AssignToBuddyGroupCommand(group, state);
- command.initialize(buddyManager);
- return command;
- }
-
- public ClusteredGetCommand buildClusteredGetCommand(Boolean searchBackupSubtrees, DataCommand dataCommand)
- {
- ClusteredGetCommand command = new ClusteredGetCommand(searchBackupSubtrees, dataCommand);
- command.initialize(dataContainer, invoker);
- return command;
- }
-
- public RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn)
- {
- RemoveNodeCommand cmd = new RemoveNodeCommand(gtx, fqn);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn)
- {
- ClearDataCommand cmd = new ClearDataCommand(gtx, fqn);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn, Object key)
- {
- RemoveKeyCommand cmd = new RemoveKeyCommand(tx, fqn, key);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public MoveCommand buildMoveCommand(Fqn from, Fqn to)
- {
- MoveCommand cmd = new MoveCommand(from, to);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public CreateNodeCommand buildCreateNodeCommand(Fqn fqn)
- {
- CreateNodeCommand command = new CreateNodeCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public ReplicableCommand fromStream(int id, Object[] parameters)
- {
- ReplicableCommand command;
- switch (id)
- {
- case ExistsCommand.METHOD_ID:
- {
- ExistsCommand result = new ExistsCommand();
- result.initialize(dataContainer);
- command = result;
- break;
- }
- case GetChildrenNamesCommand.METHOD_ID:
- {
- GetChildrenNamesCommand returnValue = new GetChildrenNamesCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case GetDataMapCommand.METHOD_ID:
- {
- GetDataMapCommand returnValue = new GetDataMapCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case GetKeysCommand.METHOD_ID:
- {
- GetKeysCommand returnValue = new GetKeysCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case GetKeyValueCommand.METHOD_ID:
- {
- GetKeyValueCommand returnValue = new GetKeyValueCommand();
- returnValue.initialize(dataContainer, notifier);
- command = returnValue;
- break;
- }
- case GetNodeCommand.METHOD_ID:
- {
- GetNodeCommand returnValue = new GetNodeCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case MoveCommand.METHOD_ID:
- {
- MoveCommand returnValue = new MoveCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutDataMapCommand.METHOD_ID:
- case PutDataMapCommand.ERASE_METHOD_ID:
- case PutDataMapCommand.ERASE_VERSIONED_METHOD_ID:
- case PutDataMapCommand.VERSIONED_METHOD_ID:
- {
- PutDataMapCommand returnValue = new PutDataMapCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutKeyValueCommand.METHOD_ID:
- case PutKeyValueCommand.VERSIONED_METHOD_ID:
- {
- PutKeyValueCommand returnValue = new PutKeyValueCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutForExternalReadCommand.METHOD_ID:
- case PutForExternalReadCommand.VERSIONED_METHOD_ID:
- {
- PutForExternalReadCommand returnValue = new PutForExternalReadCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case ClearDataCommand.METHOD_ID:
- case ClearDataCommand.VERSIONED_METHOD_ID:
- {
- ClearDataCommand returnValue = new ClearDataCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case RemoveKeyCommand.METHOD_ID:
- case RemoveKeyCommand.VERSIONED_METHOD_ID:
- {
- RemoveKeyCommand returnValue = new RemoveKeyCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
-
- case RemoveNodeCommand.METHOD_ID:
- case RemoveNodeCommand.VERSIONED_METHOD_ID:
- {
- RemoveNodeCommand returnValue = new RemoveNodeCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case CreateNodeCommand.METHOD_ID:
- {
- CreateNodeCommand returnValue = new CreateNodeCommand(null);
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- // --- transactional method calls
-
- case PrepareCommand.METHOD_ID:
- {
- command = new PrepareCommand();
- break;
- }
-
- case OptimisticPrepareCommand.METHOD_ID:
- {
- command = new OptimisticPrepareCommand();
- break;
- }
-
- case CommitCommand.METHOD_ID:
- {
- command = new CommitCommand();
- break;
- }
-
- case RollbackCommand.METHOD_ID:
- {
- command = new RollbackCommand();
- break;
- }
-
- // --- replicate methods
- case ReplicateCommand.MULTIPLE_METHOD_ID:
- case ReplicateCommand.SINGLE_METHOD_ID:
- {
- ReplicateCommand returnValue = new ReplicateCommand();
- returnValue.initialize(invoker);
- command = returnValue;
- break;
- }
-
- case InvalidateCommand.METHOD_ID:
- {
- if (configuration.getNodeLockingScheme().isVersionedScheme())
- {
- VersionedInvalidateCommand returnValue = new VersionedInvalidateCommand();
- returnValue.initialize(txManager);
- returnValue.initialize(cacheSpi, dataContainer, notifier);
- command = returnValue;
- }
- else
- {
- InvalidateCommand returnValue = new InvalidateCommand();
- returnValue.initialize(cacheSpi, dataContainer, notifier);
- command = returnValue;
- }
- break;
- }
-
- case ClusteredGetCommand.METHOD_ID:
- {
- ClusteredGetCommand returnValue = new ClusteredGetCommand();
- returnValue.initialize(dataContainer, invoker);
- command = returnValue;
- break;
- }
- // ---- Buddy replication - group organisation commands
- case AnnounceBuddyPoolNameCommand.METHOD_ID:
- {
- AnnounceBuddyPoolNameCommand returnValue = new AnnounceBuddyPoolNameCommand();
- returnValue.initialize(buddyManager);
- command = returnValue;
- break;
- }
- case AssignToBuddyGroupCommand.METHOD_ID:
- {
- AssignToBuddyGroupCommand returnValue = new AssignToBuddyGroupCommand();
- returnValue.initialize(buddyManager);
- command = returnValue;
- break;
- }
- case RemoveFromBuddyGroupCommand.METHOD_ID:
- {
- RemoveFromBuddyGroupCommand returnValue = new RemoveFromBuddyGroupCommand();
- returnValue.initialize(buddyManager);
- command = returnValue;
- break;
- }
- case DataGravitationCleanupCommand.METHOD_ID:
- {
- DataGravitationCleanupCommand returnValue = new DataGravitationCleanupCommand();
- returnValue.initialize(buddyManager, invoker, transactionTable, this, dataContainer, buddyFqnTransformer);
- command = returnValue;
- break;
- }
- case GravitateDataCommand.METHOD_ID:
- {
- GravitateDataCommand returnValue = new GravitateDataCommand(rpcManager.getLocalAddress());
- returnValue.initialize(dataContainer, cacheSpi, buddyFqnTransformer);
- command = returnValue;
- break;
- }
- default:
- throw new CacheException("Unknown command id " + id + "!");
- }
-
- command.setParameters(id, parameters);
- return command;
- }
-}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -176,6 +176,8 @@
s.add(LockManagerFactory.class);
s.add(ContextMetaFactory.class);
s.add(CommandsMetaFactory.class);
+ s.add(StateTransferManagerFactory.class);
+ s.add(RegionManagerFactory.class);
return s;
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,7 +1,6 @@
package org.jboss.cache.factories;
import org.jboss.cache.DataContainer;
-import org.jboss.cache.RegionManager;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
@@ -13,7 +12,6 @@
import org.jboss.cache.marshall.VersionAwareMarshaller;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.remoting.jgroups.ChannelMessageListener;
-import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.TransactionTable;
/**
@@ -22,7 +20,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.1.0
*/
-@DefaultFactoryFor(classes = {StateTransferManager.class, RegionManager.class, Notifier.class,
+@DefaultFactoryFor(classes = {Notifier.class,
ChannelMessageListener.class, CacheLoaderManager.class, Marshaller.class, InvocationContextContainer.class,
CacheInvocationDelegate.class, TransactionTable.class, DataContainer.class,
LockStrategyFactory.class, BuddyFqnTransformer.class})
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,22 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.legacy.write.LegacyEvictCommand;
-import org.jboss.cache.commands.write.EvictCommand;
-
-/**
- * Extends the default commands factory impl for optimistic locking.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
-public class OptimisticCommandsFactoryImpl extends CommandsFactoryImpl
-{
- @Override
- public EvictCommand buildEvictFqnCommand(Fqn fqn)
- {
- EvictCommand command = new LegacyEvictCommand(fqn);
- command.initialize(notifier, dataContainer);
- return command;
- }
-}
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,199 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.commands.legacy.read.PessGetChildrenNamesCommand;
-import org.jboss.cache.commands.legacy.write.PessClearDataCommand;
-import org.jboss.cache.commands.legacy.write.PessCreateNodeCommand;
-import org.jboss.cache.commands.legacy.write.PessMoveCommand;
-import org.jboss.cache.commands.legacy.write.PessPutDataMapCommand;
-import org.jboss.cache.commands.legacy.write.PessPutForExternalReadCommand;
-import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
-import org.jboss.cache.commands.legacy.write.PessRemoveKeyCommand;
-import org.jboss.cache.commands.legacy.write.PessRemoveNodeCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.CreateNodeCommand;
-import org.jboss.cache.commands.write.MoveCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.transaction.GlobalTransaction;
-
-import java.util.Map;
-
-/**
- * This specific implementation of {@link org.jboss.cache.factories.CommandsFactory} specifically creates
- * pessimistic commands where appropriate, with the ability to roll back.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @see org.jboss.cache.commands.legacy.ReversibleCommand
- * @since 3.0
- */
-public class PessimisticCommandsFactoryImpl extends OptimisticCommandsFactoryImpl
-{
- @Override
- public GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn)
- {
- GetChildrenNamesCommand command = new PessGetChildrenNamesCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- @Override
- public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data)
- {
- PutDataMapCommand cmd = new PessPutDataMapCommand(gtx, fqn, data);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
- {
- PutKeyValueCommand cmd = new PessPutKeyValueCommand(gtx, fqn, key, value);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
- {
- PutForExternalReadCommand cmd = new PessPutForExternalReadCommand(gtx, fqn, key, value);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn)
- {
- RemoveNodeCommand cmd = new PessRemoveNodeCommand(gtx, fqn);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn)
- {
- ClearDataCommand cmd = new PessClearDataCommand(gtx, fqn);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn, Object key)
- {
- RemoveKeyCommand cmd = new PessRemoveKeyCommand(tx, fqn, key);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public MoveCommand buildMoveCommand(Fqn from, Fqn to)
- {
- MoveCommand cmd = new PessMoveCommand(from, to);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public CreateNodeCommand buildCreateNodeCommand(Fqn fqn)
- {
- CreateNodeCommand command = new PessCreateNodeCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- @Override
- public ReplicableCommand fromStream(int id, Object[] parameters)
- {
- ReplicableCommand command;
- boolean skipSetParams = false;
- switch (id)
- {
- case GetChildrenNamesCommand.METHOD_ID:
- {
- GetChildrenNamesCommand returnValue = new PessGetChildrenNamesCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case MoveCommand.METHOD_ID:
- {
- MoveCommand returnValue = new PessMoveCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutDataMapCommand.METHOD_ID:
- case PutDataMapCommand.ERASE_METHOD_ID:
- case PutDataMapCommand.ERASE_VERSIONED_METHOD_ID:
- case PutDataMapCommand.VERSIONED_METHOD_ID:
- {
- PutDataMapCommand returnValue = new PessPutDataMapCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutKeyValueCommand.METHOD_ID:
- case PutKeyValueCommand.VERSIONED_METHOD_ID:
- {
- PutKeyValueCommand returnValue = new PessPutKeyValueCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutForExternalReadCommand.METHOD_ID:
- case PutForExternalReadCommand.VERSIONED_METHOD_ID:
- {
- PutForExternalReadCommand returnValue = new PessPutForExternalReadCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case ClearDataCommand.METHOD_ID:
- case ClearDataCommand.VERSIONED_METHOD_ID:
- {
- ClearDataCommand returnValue = new PessClearDataCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case RemoveKeyCommand.METHOD_ID:
- case RemoveKeyCommand.VERSIONED_METHOD_ID:
- {
- RemoveKeyCommand returnValue = new PessRemoveKeyCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
-
- case RemoveNodeCommand.METHOD_ID:
- case RemoveNodeCommand.VERSIONED_METHOD_ID:
- {
- RemoveNodeCommand returnValue = new PessRemoveNodeCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case CreateNodeCommand.METHOD_ID:
- {
- CreateNodeCommand returnValue = new PessCreateNodeCommand(null);
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- default:
- // pass up to superclass
- command = super.fromStream(id, parameters);
- skipSetParams = true;
- }
- if (!skipSetParams)
- {
- command.setParameters(id, parameters);
- }
- return command;
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -0,0 +1,28 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.LegacyRegionManagerImpl;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
+import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+
+/**
+ * Creates region managers
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+@DefaultFactoryFor(classes = RegionManager.class)
+public class RegionManagerFactory extends ComponentFactory
+{
+ @SuppressWarnings("unchecked")
+ protected <T> T construct(Class<T> componentType)
+ {
+ switch (configuration.getNodeLockingScheme())
+ {
+ case MVCC:
+ return (T) new RegionManagerImpl();
+ default:
+ return (T) new LegacyRegionManagerImpl();
+ }
+ }
+}
\ No newline at end of file
Added: core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -0,0 +1,28 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
+import org.jboss.cache.statetransfer.LegacyStateTransferManager;
+import org.jboss.cache.statetransfer.StateTransferManager;
+
+/**
+ * Constructs {@link org.jboss.cache.statetransfer.StateTransferManager} instances.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+@DefaultFactoryFor(classes = StateTransferManager.class)
+public class StateTransferManagerFactory extends ComponentFactory
+{
+ @SuppressWarnings("unchecked")
+ protected <T> T construct(Class<T> componentType)
+ {
+ switch (configuration.getNodeLockingScheme())
+ {
+ case MVCC:
+ return (T) new DefaultStateTransferManager();
+ default:
+ return (T) new LegacyStateTransferManager();
+ }
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -224,7 +224,7 @@
public void unlockAll(NodeSPI node)
{
- throw new UnsupportedOperationException("Not supported in this impl.");
+ unlockAll(node, null);
}
public boolean ownsLock(Fqn fqn, LockType lockType, Object owner)
Modified: core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -7,6 +7,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.NonVolatile;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.util.ExposedByteArrayOutputStream;
import org.jboss.util.stream.MarshalledValueInputStream;
@@ -186,10 +187,10 @@
String sourceRoot = state_id;
byte[] result;
- boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
if (hasDifferentSourceAndIntegrationRoots)
{
- sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
+ sourceRoot = state_id.split(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER)[0];
}
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
@@ -234,10 +235,10 @@
{
String sourceRoot = state_id;
MarshalledValueOutputStream out = null;
- boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
if (hasDifferentSourceAndIntegrationRoots)
{
- sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
+ sourceRoot = state_id.split(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER)[0];
}
try
{
@@ -293,10 +294,10 @@
MarshalledValueInputStream in = null;
String targetRoot = state_id;
- boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
if (hasDifferentSourceAndIntegrationRoots)
{
- targetRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[1];
+ targetRoot = state_id.split(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER)[1];
}
try
{
@@ -335,10 +336,10 @@
if (log.isTraceEnabled()) log.trace("**** Receiving state for " + stateId);
String targetRoot = stateId;
MarshalledValueInputStream in = null;
- boolean hasDifferentSourceAndIntegrationRoots = stateId.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ boolean hasDifferentSourceAndIntegrationRoots = stateId.indexOf(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
if (hasDifferentSourceAndIntegrationRoots)
{
- targetRoot = stateId.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[1];
+ targetRoot = stateId.split(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER)[1];
}
if (istream == null)
{
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -42,7 +42,7 @@
}
public void generateState(ObjectOutputStream out, Node rootNode, boolean generateTransient,
- boolean generatePersistent, boolean suppressErrors) throws Throwable
+ boolean generatePersistent, boolean suppressErrors) throws Exception
{
Fqn fqn = rootNode.getFqn();
try
@@ -109,10 +109,10 @@
}
delimitStream(out);
}
- catch (Throwable t)
+ catch (Exception e)
{
- cache.getMarshaller().objectToObjectStream(new NodeDataExceptionMarker(t, cache.getLocalAddress()), out);
- throw t;
+ cache.getMarshaller().objectToObjectStream(new NodeDataExceptionMarker(e, cache.getLocalAddress()), out);
+ throw e;
}
}
@@ -124,7 +124,7 @@
*/
protected void delimitStream(ObjectOutputStream out) throws Exception
{
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, out);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, out);
}
/**
Copied: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java (from rev 6183, core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -0,0 +1,231 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.statetransfer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.RegionEmptyException;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.loader.CacheLoaderManager;
+import org.jboss.cache.marshall.InactiveRegionException;
+import org.jboss.cache.marshall.Marshaller;
+import org.jboss.cache.marshall.NodeData;
+import org.jboss.cache.marshall.NodeDataMarker;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * The default state transfer manager to be used when using MVCC locking.
+ */
+public class DefaultStateTransferManager implements StateTransferManager
+{
+ protected final static Log log = LogFactory.getLog(DefaultStateTransferManager.class);
+
+ public static final NodeData STREAMING_DELIMITER_NODE = new NodeDataMarker();
+
+ public static final String PARTIAL_STATE_DELIMITER = "_PARTIAL_STATE_DELIMITER";
+
+ protected CacheSPI cache;
+ protected Marshaller marshaller;
+ protected RegionManager regionManager;
+ protected Configuration configuration;
+ private CacheLoaderManager cacheLoaderManager;
+ private boolean fetchTransientState;
+ private boolean fetchPersistentState;
+ private long stateRetrievalTimeout;
+
+
+ @Inject
+ public void injectDependencies(CacheSPI cache, Marshaller marshaller, RegionManager regionManager, Configuration configuration, CacheLoaderManager cacheLoaderManager)
+ {
+ this.cache = cache;
+ this.regionManager = regionManager;
+ this.marshaller = marshaller;
+ this.configuration = configuration;
+ this.cacheLoaderManager = cacheLoaderManager;
+ }
+
+ @Start(priority = 99)
+ public void start()
+ {
+ fetchTransientState = configuration.isFetchInMemoryState();
+ fetchPersistentState = cacheLoaderManager != null && cacheLoaderManager.isFetchPersistentState();
+ stateRetrievalTimeout = configuration.getStateRetrievalTimeout();
+ }
+
+ public void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force, boolean suppressErrors) throws Exception
+ {
+ // can't give state for regions currently being activated/inactivated
+ boolean canProvideState = (!regionManager.isInactive(fqn) && cache.peek(fqn, false) != null);
+
+ if (canProvideState && (fetchPersistentState || fetchTransientState))
+ {
+ marshaller.objectToObjectStream(true, out);
+ StateTransferGenerator generator = getStateTransferGenerator();
+ long startTime = System.currentTimeMillis();
+ NodeSPI rootNode = cache.peek(fqn, false, false);
+
+ try
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("locking the " + fqn + " subtree to return the in-memory (transient) state");
+ }
+ acquireLocksForStateTransfer(rootNode, timeout, force);
+ generator.generateState(out, rootNode, fetchTransientState, fetchPersistentState, suppressErrors);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Successfully generated state in " + (System.currentTimeMillis() - startTime) + " msec");
+ }
+ }
+ finally
+ {
+ releaseStateTransferLocks(rootNode);
+ }
+ }
+ else
+ {
+ marshaller.objectToObjectStream(false, out);
+ Exception e = null;
+ if (!canProvideState)
+ {
+ String exceptionMessage = "Cache instance at " + cache.getLocalAddress() + " cannot provide state for fqn " + fqn + ".";
+
+ if (regionManager.isInactive(fqn))
+ {
+ exceptionMessage += " Region for fqn " + fqn + " is inactive.";
+ e = new InactiveRegionException(exceptionMessage);
+ }
+ // this is not really an exception. Just provide empty state. The exception is just a signal. Yes, lousy. - JBCACHE-1349
+ if (cache.peek(fqn, false, false) == null)
+ {
+ e = new RegionEmptyException();
+ }
+ }
+ if (!fetchPersistentState && !fetchTransientState)
+ {
+ e = new CacheException("Cache instance at " + cache.getLocalAddress() + " is not configured to provide state");
+ }
+ marshaller.objectToObjectStream(e, out);
+ if (e != null) throw e;
+ }
+ }
+
+ public void setState(ObjectInputStream in, Fqn targetRoot) throws Exception
+ {
+ NodeSPI target = cache.peek(targetRoot, false, false);
+ if (target == null)
+ {
+ // Create the integration root, but do not replicate
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+
+ //needed for BR state transfers
+ cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
+ cache.put(targetRoot, null);
+ target = cache.peek(targetRoot, false, false);
+ }
+ Object o = marshaller.objectFromObjectStream(in);
+ Boolean hasState = (Boolean) o;
+ if (hasState)
+ {
+ setState(in, target);
+ }
+ else
+ {
+ throw new CacheException("Cache instance at " + cache.getLocalAddress()
+ + " cannot integrate state since state provider could not provide state due to " + marshaller.objectFromObjectStream(in));
+ }
+ }
+
+ /**
+ * Set the portion of the cache rooted in <code>targetRoot</code>
+ * to match the given state. Updates the contents of <code>targetRoot</code>
+ * to reflect those in <code>new_state</code>.
+ * <p/>
+ * <strong>NOTE:</strong> This method performs no locking of nodes; it
+ * is up to the caller to lock <code>targetRoot</code> before calling
+ * this method.
+ *
+ * @param state a serialized byte[][] array where element 0 is the
+ * transient state (or null) , and element 1 is the
+ * persistent state (or null)
+ * @param targetRoot node into which the state should be integrated
+ */
+ private void setState(ObjectInputStream state, NodeSPI targetRoot) throws Exception
+ {
+ long startTime = System.currentTimeMillis();
+
+ try
+ {
+ // Acquire a lock on the root node
+ acquireLocksForStateTransfer(targetRoot, stateRetrievalTimeout, true);
+
+ /*
+ * Vladimir/Manik/Brian (Dec 7,2006)
+ *
+ * integrator.integrateState(in,targetRoot, cl) will call cache.put for each
+ * node read from stream. Having option override below allows nodes read
+ * to be directly stored into a tree since we bypass interceptor chain.
+ *
+ */
+
+// Option option = new Option();
+// option.setBypassInterceptorChain(true);
+// cache.getInvocationContext().setOptionOverrides(option);
+//
+ StateTransferIntegrator integrator = getStateTransferIntegrator(state, targetRoot.getFqn());
+ if (log.isDebugEnabled())
+ {
+ log.debug("starting state integration at node " + targetRoot);
+ }
+ integrator.integrateState(state, targetRoot);
+ if (log.isDebugEnabled())
+ {
+ log.debug("successfully integrated state in " + (System.currentTimeMillis() - startTime) + " msec");
+ }
+ }
+ finally
+ {
+ releaseStateTransferLocks(targetRoot);
+ }
+ }
+
+
+ /**
+ * Acquires locks on a root node for an owner for state transfer.
+ */
+ protected void acquireLocksForStateTransfer(NodeSPI root, long timeout, boolean force) throws InterruptedException
+ {
+ // no op
+ }
+
+ /**
+ * Releases all state transfer locks acquired.
+ */
+ protected void releaseStateTransferLocks(NodeSPI root)
+ {
+ // no op
+ }
+
+ protected StateTransferGenerator getStateTransferGenerator()
+ {
+ return StateTransferFactory.getStateTransferGenerator(cache);
+ }
+
+ protected StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream istream, Fqn fqn) throws Exception
+ {
+ return StateTransferFactory.getStateTransferIntegrator(istream, fqn, cache);
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferManager.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferManager.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -0,0 +1,66 @@
+package org.jboss.cache.statetransfer;
+
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.lock.LockManager;
+import static org.jboss.cache.lock.LockType.READ;
+import org.jboss.cache.lock.TimeoutException;
+
+/**
+ * This is to support legacy locking schemes such as Pessimistic and Optimistic locking.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class LegacyStateTransferManager extends DefaultStateTransferManager
+{
+ protected LockManager lockManager;
+
+ @Inject
+ public void injectLockManager(LockManager lockManager)
+ {
+ this.lockManager = lockManager;
+ }
+
+ @Override
+ protected void acquireLocksForStateTransfer(NodeSPI root, long timeout, boolean force) throws InterruptedException
+ {
+ try
+ {
+ lockManager.lockAll(root, READ, getLockOwner(), timeout, true);
+ }
+ catch (TimeoutException te)
+ {
+ log.error("Caught TimeoutException acquiring locks on region " +
+ root.getFqn(), te);
+ if (force)
+ {
+ throw te;
+ }
+ else
+ {
+ throw te;
+ }
+ }
+ }
+
+ @Override
+ protected void releaseStateTransferLocks(NodeSPI root)
+ {
+ try
+ {
+ lockManager.unlockAll(root, getLockOwner());
+ }
+ catch (Throwable t)
+ {
+ log.error("failed releasing locks", t);
+ }
+ }
+
+ private Object getLockOwner()
+ {
+ Object owner = cache.getCurrentTransaction();
+ if (owner == null) owner = Thread.currentThread();
+ return owner;
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferGenerator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferGenerator.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferGenerator.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -10,10 +10,11 @@
import java.io.ObjectOutputStream;
+/**
+ * @since 1.2.4
+ */
public interface StateTransferGenerator
{
+ void generateState(ObjectOutputStream stream, Node rootNode, boolean generateTransient, boolean generatePersistent, boolean suppressErrors) throws Exception;
- void generateState(ObjectOutputStream stream, Node rootNode, boolean generateTransient,
- boolean generatePersistent, boolean suppressErrors) throws Throwable;
-
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferIntegrator.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferIntegrator.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -10,6 +10,9 @@
import java.io.ObjectInputStream;
+/**
+ * @since 1.2.4
+ */
public interface StateTransferIntegrator
{
Deleted: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,334 +0,0 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.statetransfer;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.RegionEmptyException;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.NonVolatile;
-import org.jboss.cache.loader.CacheLoaderManager;
-import org.jboss.cache.lock.LockManager;
-import static org.jboss.cache.lock.LockType.READ;
-import org.jboss.cache.lock.TimeoutException;
-import org.jboss.cache.marshall.InactiveRegionException;
-import org.jboss.cache.marshall.Marshaller;
-import org.jboss.cache.marshall.NodeData;
-import org.jboss.cache.marshall.NodeDataMarker;
-
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-@NonVolatile
-public class StateTransferManager
-{
- protected final static Log log = LogFactory.getLog(StateTransferManager.class);
-
- public static final NodeData STREAMING_DELIMITER_NODE = new NodeDataMarker();
-
- public static final String PARTIAL_STATE_DELIMITER = "_PARTIAL_STATE_DELIMITER";
-
- private CacheSPI cache;
- private Marshaller marshaller;
- private RegionManager regionManager;
- private Configuration configuration;
- private LockManager lockManager;
-
- public StateTransferManager()
- {
- }
-
- @Inject
- public void injectDependencies(CacheSPI cache, Marshaller marshaller, RegionManager regionManager, Configuration configuration, LockManager lockManager)
- {
- this.cache = cache;
- this.regionManager = regionManager;
- this.marshaller = marshaller;
- this.configuration = configuration;
- this.lockManager = lockManager;
- }
-
- public StateTransferManager(CacheSPI cache)
- {
- this.cache = cache;
- }
-
- /**
- * Writes the state for the portion of the tree named by <code>fqn</code> to
- * the provided OutputStream.
- * <p/>
- * <p/>
- *
- * @param out stream to write state to
- * @param fqn Fqn indicating the uppermost node in the
- * portion of the tree whose state should be returned.
- * @param timeout max number of ms this method should wait to acquire
- * a read lock on the nodes being transferred
- * @param force if a read lock cannot be acquired after
- * <code>timeout</code> ms, should the lock acquisition
- * be forced, and any existing transactions holding locks
- * on the nodes be rolled back? <strong>NOTE:</strong>
- * In release 1.2.4, this parameter has no effect.
- * @param suppressErrors should any Throwable thrown be suppressed?
- * @throws Throwable in event of error
- */
- public void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force, boolean suppressErrors) throws Throwable
- {
- // can't give state for regions currently being activated/inactivated
- boolean canProvideState = (!regionManager.isInactive(fqn) && cache.peek(fqn, false) != null);
-
- boolean fetchTransientState = configuration.isFetchInMemoryState();
- CacheLoaderManager cacheLoaderManager = cache.getCacheLoaderManager();
- boolean fetchPersistentState = cacheLoaderManager != null && cacheLoaderManager.isFetchPersistentState();
-
- if (canProvideState && (fetchPersistentState || fetchTransientState))
- {
- marshaller.objectToObjectStream(true, out);
- StateTransferGenerator generator = getStateTransferGenerator();
- Object owner = getOwnerForLock();
- long startTime = System.currentTimeMillis();
- NodeSPI rootNode = cache.peek(fqn, false, false);
-
- try
- {
- if (log.isDebugEnabled())
- {
- log.debug("locking the " + fqn + " subtree to return the in-memory (transient) state");
- }
- acquireLocksForStateTransfer(rootNode, owner, timeout, true, force);
- generator.generateState(out, rootNode, fetchTransientState, fetchPersistentState, suppressErrors);
- if (log.isDebugEnabled())
- {
- log.debug("Successfully generated state in " + (System.currentTimeMillis() - startTime) + " msec");
- }
- }
- finally
- {
- releaseStateTransferLocks(rootNode, owner, true);
- }
- }
- else
- {
- marshaller.objectToObjectStream(false, out);
- Exception e = null;
- if (!canProvideState)
- {
- String exceptionMessage = "Cache instance at " + cache.getLocalAddress() + " cannot provide state for fqn " + fqn + ".";
-
- if (regionManager.isInactive(fqn))
- {
- exceptionMessage += " Region for fqn " + fqn + " is inactive.";
- e = new InactiveRegionException(exceptionMessage);
- }
- // this is not really an exception. Just provide empty state. The exception is just a signal. Yes, lousy. - JBCACHE-1349
- if (cache.peek(fqn, false, false) == null)
- {
- e = new RegionEmptyException();
- }
- }
- if (!fetchPersistentState && !fetchTransientState)
- {
- e = new CacheException("Cache instance at " + cache.getLocalAddress() + " is not configured to provide state");
- }
- marshaller.objectToObjectStream(e, out);
- if (e != null) throw e;
- }
- }
-
- /**
- * Set the portion of the cache rooted in <code>targetRoot</code>
- * to match the given state. Updates the contents of <code>targetRoot</code>
- * to reflect those in <code>new_state</code>.
- * <p/>
- * <strong>NOTE:</strong> This method performs no locking of nodes; it
- * is up to the caller to lock <code>targetRoot</code> before calling
- * this method.
- * <p/>
- * This method will use any {@link ClassLoader} needed as defined by the active {@link org.jboss.cache.Region}
- * in the {@link org.jboss.cache.RegionManager}, pertaining to the targetRoot passed in.
- *
- * @param in an input stream containing the state
- * @param targetRoot fqn of the node into which the state should be integrated
- * @throws Exception In event of error
- */
- public void setState(ObjectInputStream in, Fqn targetRoot) throws Exception
- {
- NodeSPI target = cache.peek(targetRoot, false, false);
- if (target == null)
- {
- // Create the integration root, but do not replicate
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
-
- //needed for BR state transfers
- cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
- cache.put(targetRoot, null);
- target = cache.peek(targetRoot, false, false);
- }
- Object o = marshaller.objectFromObjectStream(in);
- Boolean hasState = (Boolean) o;
- if (hasState)
- {
- setState(in, target);
- }
- else
- {
- throw new CacheException("Cache instance at " + cache.getLocalAddress()
- + " cannot integrate state since state provider could not provide state due to " + marshaller.objectFromObjectStream(in));
- }
- }
-
- /**
- * Set the portion of the cache rooted in <code>targetRoot</code>
- * to match the given state. Updates the contents of <code>targetRoot</code>
- * to reflect those in <code>new_state</code>.
- * <p/>
- * <strong>NOTE:</strong> This method performs no locking of nodes; it
- * is up to the caller to lock <code>targetRoot</code> before calling
- * this method.
- *
- * @param state a serialized byte[][] array where element 0 is the
- * transient state (or null) , and element 1 is the
- * persistent state (or null)
- * @param targetRoot node into which the state should be integrated
- */
- private void setState(ObjectInputStream state, NodeSPI targetRoot) throws Exception
- {
- Object owner = getOwnerForLock();
- long timeout = configuration.getStateRetrievalTimeout();
- long startTime = System.currentTimeMillis();
-
- try
- {
- // Acquire a lock on the root node
- acquireLocksForStateTransfer(targetRoot, owner, timeout, true, true);
-
- /*
- * Vladimir/Manik/Brian (Dec 7,2006)
- *
- * integrator.integrateState(in,targetRoot, cl) will call cache.put for each
- * node read from stream. Having option override below allows nodes read
- * to be directly stored into a tree since we bypass interceptor chain.
- *
- */
-
-// Option option = new Option();
-// option.setBypassInterceptorChain(true);
-// cache.getInvocationContext().setOptionOverrides(option);
-//
- StateTransferIntegrator integrator = getStateTransferIntegrator(state, targetRoot.getFqn());
- if (log.isDebugEnabled())
- {
- log.debug("starting state integration at node " + targetRoot);
- }
- integrator.integrateState(state, targetRoot);
- if (log.isDebugEnabled())
- {
- log.debug("successfully integrated state in " + (System.currentTimeMillis() - startTime) + " msec");
- }
- }
- finally
- {
- releaseStateTransferLocks(targetRoot, owner, true);
- }
- }
-
-
- /**
- * Acquires locks on a root node for an owner for state transfer.
- */
- protected void acquireLocksForStateTransfer(NodeSPI root,
- Object lockOwner,
- long timeout,
- boolean lockChildren,
- boolean force)
- throws Exception
- {
- try
- {
- if (lockChildren)
- {
- lockManager.lockAll(root, READ, lockOwner, timeout, true);
- }
- else
- {
- lockManager.lock(Fqn.ROOT, READ, lockOwner, timeout);
- }
- }
- catch (TimeoutException te)
- {
- log.error("Caught TimeoutException acquiring locks on region " +
- root.getFqn(), te);
- if (force)
- {
- // Until we have FLUSH in place, don't force locks
- // forceAcquireLock(root, lockOwner, lockChildren);
- throw te;
-
- }
- else
- {
- throw te;
- }
- }
- }
-
- /**
- * Releases all state transfer locks acquired.
- *
- * @see #acquireLocksForStateTransfer
- */
- protected void releaseStateTransferLocks(NodeSPI root,
- Object lockOwner,
- boolean childrenLocked)
- {
- try
- {
- if (childrenLocked)
- {
- lockManager.unlockAll(root, lockOwner);
- }
- else
- {
- lockManager.unlock(Fqn.ROOT, lockOwner);
- }
- }
- catch (Throwable t)
- {
- log.error("failed releasing locks", t);
- }
- }
-
- protected StateTransferGenerator getStateTransferGenerator()
- {
- return StateTransferFactory.getStateTransferGenerator(cache);
- }
-
- protected StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream istream, Fqn fqn) throws Exception
- {
- return StateTransferFactory.getStateTransferIntegrator(istream, fqn, cache);
- }
-
- /**
- * Returns an object suitable for use in node locking, either the current
- * transaction or the current thread if there is no transaction.
- */
- private Object getOwnerForLock()
- {
- Object owner = cache.getCurrentTransaction();
- if (owner == null)
- {
- owner = Thread.currentThread();
- }
- return owner;
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -0,0 +1,58 @@
+package org.jboss.cache.statetransfer;
+
+import org.jboss.cache.Fqn;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * This interface handles requests to generate or integrate state from neighbouring caches in a cluster.
+ * <p/>
+ * This has existed prior to 3.0.0 as a concrete class. An interface was introduced in 3.0.0 to provide more flexibility
+ * in state transfer implementations.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface StateTransferManager
+{
+ /**
+ * Writes the state for the portion of the tree named by <code>fqn</code> to
+ * the provided OutputStream.
+ * <p/>
+ * <p/>
+ *
+ * @param out stream to write state to
+ * @param fqn Fqn indicating the uppermost node in the
+ * portion of the tree whose state should be returned.
+ * @param timeout max number of millis this method should wait to acquire
+ * any locks, if necessary, on the nodes being transferred
+ * @param force if locks are needed and cannot be acquired after
+ * <code>timeout</code> millis, should the lock acquisition
+ * be forced, and any existing transactions holding locks
+ * on the nodes be rolled back?
+ * @param suppressErrors if true, all exceptions are logged but not propagated.
+ * @throws Exception in event of error
+ */
+ void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force, boolean suppressErrors) throws Exception;
+
+ /**
+ * Set the portion of the cache rooted in <code>targetRoot</code>
+ * to match the given state. Updates the contents of <code>targetRoot</code>
+ * to reflect those in <code>new_state</code>.
+ * <p/>
+ * <strong>NOTE:</strong> This method performs no locking of nodes; it
+ * is up to the caller to lock <code>targetRoot</code> before calling
+ * this method.
+ * <p/>
+ * This method will use any {@link ClassLoader} needed as defined by the active {@link org.jboss.cache.Region}
+ * in the {@link org.jboss.cache.RegionManager}, pertaining to the targetRoot passed in.
+ *
+ * @param in an input stream containing the state
+ * @param targetRoot fqn of the node into which the state should be integrated
+ * @throws Exception In event of error
+ */
+ void setState(ObjectInputStream in, Fqn targetRoot) throws Exception;
+
+}
Modified: core/trunk/src/test/java/org/jboss/cache/config/EvictionRegionConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/EvictionRegionConfigurationTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/config/EvictionRegionConfigurationTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -7,18 +7,17 @@
package org.jboss.cache.config;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManagerImpl;
+import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.eviction.LRUPolicy;
import static org.testng.AssertJUnit.fail;
+import org.testng.annotations.Test;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.eviction.LRUPolicy;
-import org.testng.annotations.Test;
-
/**
* @author <a href="mailto:brian.stansberry@jboss.org">Brian Stansberry</a>
*/
@@ -29,27 +28,27 @@
* This test duplicates the way the JBoss Microcontainer goes about
* building up an eviction config, and checks that at the
* end of the process there is only one _default_ region configured.
- *
+ *
* @throws Exception
*/
public void testDuplicateDefaultRegion() throws Exception
{
EvictionConfig ec = new EvictionConfig();
ec.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
-
+
List<EvictionRegionConfig> ercs = ec.getEvictionRegionConfigs();
-
+
EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionFqn(RegionManager.DEFAULT_REGION);
+ erc.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
EvictionPolicy policy = LRUPolicy.class.newInstance();
erc.setEvictionPolicyConfig(policy.getEvictionConfigurationClass().newInstance());
-
+
ercs.add(erc);
-
+
ec.setEvictionRegionConfigs(ercs);
-
+
ercs = ec.getEvictionRegionConfigs();
-
+
Set<Fqn> fqns = new HashSet<Fqn>();
for (EvictionRegionConfig cfg : ercs)
{
@@ -57,6 +56,6 @@
fail("duplicate region fqn " + cfg.getRegionFqn());
fqns.add(cfg.getRegionFqn());
}
-
+
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,15 +1,15 @@
package org.jboss.cache.config.parsing;
-import org.testng.annotations.Test;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.eviction.MRUConfiguration;
-import org.jboss.cache.eviction.LRUConfiguration;
+import org.testng.annotations.Test;
import org.w3c.dom.Element;
/**
@@ -115,8 +115,8 @@
" </eviction>";
EvictionConfig evConfig = getEvictionConfig(xml);
EvictionRegionConfig evictionRegionConfig = evConfig.getEvictionRegionConfigs().get(0);
- assert evictionRegionConfig.getRegionName().equals(RegionManager.DEFAULT_REGION.toString());
- assert evictionRegionConfig.getRegionName().equals(RegionManager.DEFAULT_REGION.toString());
+ assert evictionRegionConfig.getRegionName().equals(RegionManagerImpl.DEFAULT_REGION.toString());
+ assert evictionRegionConfig.getRegionName().equals(RegionManagerImpl.DEFAULT_REGION.toString());
assert ((LRUConfiguration) evictionRegionConfig.getEvictionPolicyConfig()).getTimeToLiveSeconds() == 1000;
assert ((LRUConfiguration) evictionRegionConfig.getEvictionPolicyConfig()).getTimeToLive() == 1000000;
}
@@ -140,7 +140,8 @@
{
getEvictionConfig(xml);
assert false : "exception expected as wake up interval is not set";
- } catch (ConfigurationException e)
+ }
+ catch (ConfigurationException e)
{
//expected
}
@@ -162,7 +163,8 @@
{
getEvictionConfig(xml);
assert false : "missing policy in both default and region, exception expected.";
- } catch (MissingPolicyException e)
+ }
+ catch (MissingPolicyException e)
{
//expected
}
@@ -174,7 +176,8 @@
try
{
el = XmlConfigHelper.stringToElement(xml);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new ConfigurationException(e);
}
@@ -197,8 +200,9 @@
try
{
getEvictionConfig(xml);
- assert false : " excewption expectecd as root does not have a eviction policy defined";
- } catch (MissingPolicyException e)
+ assert false : " excewption expectecd as root does not have a eviction policy defined";
+ }
+ catch (MissingPolicyException e)
{
//expected
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -21,69 +21,69 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionPolicyConfig;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
/**
* Tests BaseEvictionAlgorithm class.
- *
+ *
* @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
*/
@Test(groups = "functional")
public class BaseEvictionAlgorithmTest
{
- private static final Log log = LogFactory.getLog(BaseEvictionAlgorithmTest.class);
-
+ private static final Log log = LogFactory.getLog(BaseEvictionAlgorithmTest.class);
+
private RegionManager regionManager;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
}
-
+
public void testFillUpRecycleQueue() throws Exception
{
final int recycleQueueCapacity = 10;
/* override recycle queue capacity to make the test shorter */
BaseEvictionAlgorithm algorithm = new MockEvictionAlgorithm(recycleQueueCapacity);
-
+
Region region = regionManager.getRegion("/a/b/c", true);
region.setEvictionPolicy(new MockEvictionPolicyConfig());
-
- for (int i = 0; i < (recycleQueueCapacity + 1); i ++)
+
+ for (int i = 0; i < (recycleQueueCapacity + 1); i++)
{
Fqn<String> fqn = Fqn.fromString("/a/b/c/" + Integer.toString(i + 1));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
}
-
+
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Void> future = executor.submit(new ProcessEvictionRegion(region, algorithm));
-
+
try
{
future.get(20, TimeUnit.SECONDS);
}
- catch(TimeoutException te)
+ catch (TimeoutException te)
{
log.error("Region eviction processing did not finish on time", te);
fail("Region eviction processing should have finished by now, something is wrong. Recycle queue may have filled up.");
@@ -93,16 +93,18 @@
log.info("recycle queue size: " + algorithm.recycleQueue.size());
}
}
-
- /** Classes **/
-
+
+ /**
+ * Classes *
+ */
+
public static class MockEvictionAlgorithm extends BaseEvictionAlgorithm
{
public MockEvictionAlgorithm(int recycleQueueCapacity)
{
recycleQueue = new LinkedBlockingQueue<Fqn>(recycleQueueCapacity);
}
-
+
@Override
protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
{
@@ -115,12 +117,12 @@
/* all node entries need evicting */
return true;
}
-
+
}
public static class MockEvictionPolicy extends BaseEvictionPolicy
{
-
+
@Override
public void evict(Fqn fqn) throws Exception
{
@@ -143,7 +145,7 @@
return MockEvictionPolicyConfig.class;
}
}
-
+
public static class MockEvictionPolicyConfig implements EvictionPolicyConfig
{
@@ -160,15 +162,15 @@
public void validate() throws ConfigurationException
{
/* no op */
- }
+ }
}
-
+
public class ProcessEvictionRegion implements Callable<Void>
{
private Region region;
-
+
private EvictionAlgorithm algorithm;
-
+
public ProcessEvictionRegion(Region region, EvictionAlgorithm algorithm)
{
this.region = region;
@@ -181,12 +183,12 @@
{
algorithm.process(region);
}
- catch(EvictionException e)
+ catch (EvictionException e)
{
log.error("Eviction exception reported", e);
fail("Eviction exception reported" + e);
}
-
+
return null;
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -6,15 +6,16 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-
-import java.util.Iterator;
-
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.Iterator;
+
/**
* @author Daniel Huang
* @version $Revision$
@@ -29,7 +30,7 @@
public void setUp() throws Exception
{
algo = new ElementSizeAlgorithm();
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
ElementSizeConfiguration config = new ElementSizeConfiguration();
// We have to setCache maxElementsPerNode!!
config.setMaxElementsPerNode(0);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -6,16 +6,17 @@
*/
package org.jboss.cache.eviction;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Region;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.util.Iterator;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
-import org.jboss.cache.RegionManager;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
/**
* Unit tests for FIFOAlgorithm.
*
@@ -36,7 +37,7 @@
FIFOConfiguration config = new FIFOConfiguration();
// We have to setCache maxNodes!!
config.setMaxNodes(0);
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -9,6 +9,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -32,7 +33,7 @@
{
algo = new LFUAlgorithm();
LFUConfiguration config = new LFUConfiguration();
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
// doesn't this need a cache?!?? :-/
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -5,6 +5,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
@@ -34,7 +35,7 @@
// We have to setCache timeToLiveSeconds!!
config.setTimeToLiveSeconds(0);
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -6,15 +6,14 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
/**
* Unit tests for MRUAlgorithm.
*
@@ -35,7 +34,7 @@
// We have to setCache maxNodes!!
config.setMaxNodes(0);
config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -3,23 +3,19 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParser;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.interceptors.EvictionInterceptor;
-import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
import javax.transaction.TransactionManager;
import java.util.Iterator;
@@ -65,7 +61,7 @@
lruConfiguration.setMaxNodes(10);
lruConfiguration.setTimeToLive(0);
lruConfiguration.setMaxAge(0);
- EvictionRegionConfig erConfig1 = new EvictionRegionConfig(RegionManager.DEFAULT_REGION, lruConfiguration);
+ EvictionRegionConfig erConfig1 = new EvictionRegionConfig(RegionManagerImpl.DEFAULT_REGION, lruConfiguration);
LRUConfiguration lruConfiguration2 = new LRUConfiguration();
lruConfiguration2.setMaxNodes(10);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -3,15 +3,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParser;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
import java.util.List;
@@ -44,7 +40,7 @@
public void testCreateRegion()
{
- RegionManager regionManager = new RegionManager();
+ RegionManager regionManager = new RegionManagerImpl();
regionManager.setUsingEvictions(true);
regionManager.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
@@ -58,7 +54,7 @@
public void testCreateRegion2()
{
- RegionManager regionManager = new RegionManager();
+ RegionManager regionManager = new RegionManagerImpl();
regionManager.setUsingEvictions(true);
regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
regionManager.getRegion(A_B, true).setEvictionPolicy(config);
@@ -83,7 +79,7 @@
public void testNoDefaultRegion()
{
- RegionManager regionManager = new RegionManager();
+ RegionManager regionManager = new RegionManagerImpl();
regionManager.setUsingEvictions(true);
regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
regionManager.getRegion(A_B, true).setEvictionPolicy(config);
@@ -93,7 +89,7 @@
public void testGetRegion()
{
- RegionManager regionManager = new RegionManager();
+ RegionManager regionManager = new RegionManagerImpl();
regionManager.setUsingEvictions(true);
regionManager.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
regionManager.getRegion(A_BC, true).setEvictionPolicy(config);
@@ -108,7 +104,7 @@
Fqn A_B_C_D_E = Fqn.fromString("/a/b/c/d/e/");
Fqn A_B_C_D = Fqn.fromString("/a/b/c/d/");
- RegionManager rm = new RegionManager();
+ RegionManager rm = new RegionManagerImpl();
rm.setUsingEvictions(true);
rm.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
rm.getRegion(A_B_C_D_E, true).setEvictionPolicy(config);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -1,14 +1,15 @@
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.EvictionConfig;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
/**
* @author Ben Wang, Feb 11, 2004
* @author Daniel Huang (dhuang(a)jboss.org)
@@ -23,7 +24,7 @@
public void setUp() throws Exception
{
algorithm = new LRUAlgorithm();
- regionManager_ = new RegionManager();
+ regionManager_ = new RegionManagerImpl();
regionManager_.getRegion("/a/b", true).setEvictionPolicy(new DummyEvictionConfiguration());
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -3,11 +3,11 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.marshall.NodeData;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.marshall.NodeData;
-import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.*;
@@ -116,7 +116,7 @@
MarshalledValueOutputStream newOs = new MarshalledValueOutputStream(newBaos);
newImpl.start();
newImpl.loadEntireState(newOs);
- newImpl.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, newOs);
+ newImpl.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, newOs);
newOs.close();
newImpl.remove(Fqn.ROOT);
assertNull(newImpl.get(Fqn.fromString("/a/b/c")));
@@ -147,7 +147,7 @@
MarshalledValueOutputStream newOs = new MarshalledValueOutputStream(newBaos);
newImpl.start();
newImpl.loadState(Fqn.fromString("/a/b"), newOs);
- newImpl.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, newOs);
+ newImpl.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, newOs);
newOs.close();
newImpl.remove(Fqn.fromString("/a/b"));
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -6,7 +6,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.assertEquals;
@@ -138,7 +138,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
//os.close();
assertTrue(baos.size() > 0);
loader.remove(X);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -9,7 +9,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.loader.bdbje.BdbjeCacheLoaderConfig;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.*;
@@ -530,7 +530,7 @@
loader.put(Fqn.fromString("/key0/\u0001"), null);
checkChildren(Fqn.fromString("/key0"),
new String[]{"a", "ab", "abc", "x", "xx", "xxx",
- "\u0000", "\u0001"});
+ "\u0000", "\u0001"});
loader.put(Fqn.fromString("/\u0001"), null);
checkChildren(Fqn.ROOT, new String[]{"key0", "key1", "\u0001"});
@@ -824,7 +824,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
@@ -956,7 +956,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
@@ -967,7 +967,7 @@
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
bais = new ByteArrayInputStream(baos.toByteArray());
@@ -978,7 +978,7 @@
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
assertEquals(null, loader.get(FQN));
@@ -998,7 +998,7 @@
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
assertTrue(baos.size() > STREAM_HEADER_LENGTH);
os.close();
@@ -1007,7 +1007,7 @@
/* Clear state. */
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
bais = new ByteArrayInputStream(baos.toByteArray());
is = new MarshalledValueInputStream(bais);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -11,7 +11,7 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.transaction.TransactionSetup;
import org.jboss.cache.util.TestingUtil;
import org.jboss.util.stream.MarshalledValueInputStream;
@@ -1816,7 +1816,7 @@
}
finally
{
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
assertTrue(baos.size() > 0);
state = baos.toByteArray();
@@ -2004,7 +2004,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadState(SUBTREE_FQN, os);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
assertTrue(baos.size() > 0);
loader.remove(SUBTREE_FQN);
@@ -2052,7 +2052,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadState(FQN, os);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
assertTrue(baos.size() > 0);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -2,6 +2,7 @@
import org.jboss.cache.CacheStatus;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.ComponentRegistry;
@@ -17,7 +18,7 @@
{
Configuration c = cr.getComponent(Configuration.class);
c.setReplVersionString(replVersion);
- return createVAMandRestartCache(new RegionManager());
+ return createVAMandRestartCache(new RegionManagerImpl());
}
protected VersionAwareMarshaller createVAMandRestartCache(RegionManager rm)
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -12,11 +12,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
-import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -9,6 +9,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.commands.remote.ClusteredGetCommand;
import org.testng.annotations.Test;
@@ -37,7 +38,7 @@
// need to test what's going on with
CacheMarshaller200 cm200 = new CacheMarshaller200();
c.setUseRegionBasedMarshalling(true);
- cm200.injectDependencies(new RegionManager(), c, getClass().getClassLoader());
+ cm200.injectDependencies(new RegionManagerImpl(), c, getClass().getClassLoader());
cm200.init();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -8,6 +8,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
@@ -41,7 +42,7 @@
c.setInactiveOnStartup(false);
c.setReplVersionString(currentVersion);
cr = new ComponentRegistry(c, new CacheInvocationDelegate());
- marshaller = createVAMandRestartCache(new RegionManager());
+ marshaller = createVAMandRestartCache(new RegionManagerImpl());
regionManager = cr.getComponent(RegionManager.class);
}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -5,8 +5,8 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -13,7 +13,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
@@ -92,7 +92,7 @@
List<EvictionRegionConfig> ercs = new ArrayList<EvictionRegionConfig>();
EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionFqn(RegionManager.DEFAULT_REGION);
+ erc.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
LRUConfiguration epc = new LRUConfiguration();
epc.setMaxNodes(0);
epc.setTimeToLiveSeconds(5);
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2008-07-07 20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2008-07-07 21:21:24 UTC (rev 6199)
@@ -13,7 +13,7 @@
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.util.TestingUtil;
import org.jboss.util.stream.MarshalledValueInputStream;
@@ -1510,7 +1510,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
- cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
+ cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
assertTrue(baos.size() > 0);
15 years, 10 months
JBoss Cache SVN: r6198 - core/trunk/src/main/java/org/jboss/cache/factories/annotations.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-07 16:50:09 -0400 (Mon, 07 Jul 2008)
New Revision: 6198
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/annotations/NonVolatile.java
Log:
Better documented
Modified: core/trunk/src/main/java/org/jboss/cache/factories/annotations/NonVolatile.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/annotations/NonVolatile.java 2008-07-07 20:19:19 UTC (rev 6197)
+++ core/trunk/src/main/java/org/jboss/cache/factories/annotations/NonVolatile.java 2008-07-07 20:50:09 UTC (rev 6198)
@@ -8,7 +8,9 @@
/**
* This annotation is used for components that will be registered in the {@link org.jboss.cache.factories.ComponentRegistry},
* that are resilient to changes in configuration. Examples are the {@link org.jboss.cache.CacheSPI} implementation used, which does
- * not change regardless of the configuration.
+ * not change regardless of the configuration. Components such as the {@link org.jboss.cache.lock.LockManager}, though, should
+ * <b>never</b> be marked as <tt>@NonVolatile</tt> since based on the configuration, different lock manager implementations
+ * may be selected. LockManager is, hence, <b>not</b> resilient to changes in the configuration.
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.2.0
15 years, 10 months
JBoss Cache SVN: r6197 - in core/trunk/src: main/java/org/jboss/cache/buddyreplication and 13 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-07 16:19:19 -0400 (Mon, 07 Jul 2008)
New Revision: 6197
Added:
core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactory.java
core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/commands/OptimisticCommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/commands/PessimisticCommandsFactoryImpl.java
Modified:
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java
core/trunk/src/main/java/org/jboss/cache/cluster/ReplicationQueue.java
core/trunk/src/main/java/org/jboss/cache/commands/ReplicableCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/lock/LockUtil.java
core/trunk/src/main/java/org/jboss/cache/lock/PessimisticNodeBasedLockManager.java
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java
Log:
Moved commands factories to the o.j.c.commands package. The factories package should just be for component factories such as the CommandsMetaFactory
Modified: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -6,9 +6,9 @@
*/
package org.jboss.cache;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.ComponentFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -9,8 +9,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.jboss.cache.AbstractNode.NodeFlags.*;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.write.CreateNodeCommand;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.lock.IdentityLock;
import org.jboss.cache.lock.LockStrategyFactory;
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -18,6 +18,7 @@
import org.jboss.cache.Region;
import org.jboss.cache.RegionEmptyException;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
@@ -28,7 +29,6 @@
import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Option;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.factories.annotations.Stop;
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -2,6 +2,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.commands.AbstractVisitor;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.WriteCommand;
import org.jboss.cache.commands.read.ExistsCommand;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
@@ -14,8 +15,16 @@
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.commands.write.*;
-import org.jboss.cache.factories.CommandsFactory;
+import org.jboss.cache.commands.write.ClearDataCommand;
+import org.jboss.cache.commands.write.CreateNodeCommand;
+import org.jboss.cache.commands.write.EvictCommand;
+import org.jboss.cache.commands.write.InvalidateCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.invocation.InvocationContext;
import java.util.ArrayList;
Modified: core/trunk/src/main/java/org/jboss/cache/cluster/ReplicationQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/cluster/ReplicationQueue.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/cluster/ReplicationQueue.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -3,10 +3,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.RPCManager;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.factories.annotations.Stop;
Copied: core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactory.java (from rev 6183, core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactory.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -0,0 +1,121 @@
+package org.jboss.cache.commands;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.commands.read.ExistsCommand;
+import org.jboss.cache.commands.read.GetChildrenNamesCommand;
+import org.jboss.cache.commands.read.GetDataMapCommand;
+import org.jboss.cache.commands.read.GetKeyValueCommand;
+import org.jboss.cache.commands.read.GetKeysCommand;
+import org.jboss.cache.commands.read.GetNodeCommand;
+import org.jboss.cache.commands.read.GravitateDataCommand;
+import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
+import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand;
+import org.jboss.cache.commands.remote.ClusteredGetCommand;
+import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
+import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
+import org.jboss.cache.commands.remote.ReplicateCommand;
+import org.jboss.cache.commands.tx.CommitCommand;
+import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
+import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.commands.write.ClearDataCommand;
+import org.jboss.cache.commands.write.CreateNodeCommand;
+import org.jboss.cache.commands.write.EvictCommand;
+import org.jboss.cache.commands.write.InvalidateCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jgroups.Address;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Factory for all types of cache commands.
+ * Here are some of the purposes of this class:
+ * <pre>
+ * - not creating <code>CacheCommands</code> directly (i.e. through new usage) as this would reduce unit testability
+ * - reduce the coupling between commands and other components. e.g. considering a commands that needs to knwo whether
+ * locking type is optimistic, we will pass in a 'optimistic' boolean flag rather than entire Configuration object
+ * </pre>
+ * <p/>
+ * <b>Note:</b> As of 3.0, this is now an interface.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public interface CommandsFactory
+{
+ PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data);
+
+ PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value);
+
+ PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value);
+
+ ReplicateCommand buildReplicateCommand(ReplicableCommand command);
+
+ ReplicateCommand buildReplicateCommand(List<ReplicableCommand> modifications);
+
+ PrepareCommand buildPrepareCommand(GlobalTransaction gtx, WriteCommand command, boolean onePhaseCommit);
+
+ PrepareCommand buildPrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address address, boolean onePhaseCommit);
+
+ CommitCommand buildCommitCommand(GlobalTransaction gtx);
+
+ DataGravitationCleanupCommand buildDataGravitationCleanupCommand(Fqn primaryFqn, Fqn backupFqn);
+
+ GravitateDataCommand buildGravitateDataCommand(Fqn fqn, Boolean searchSubtrees);
+
+ RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn);
+
+ ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn);
+
+ EvictCommand buildEvictFqnCommand(Fqn fqn);
+
+ InvalidateCommand buildInvalidateCommand(Fqn fqn);
+
+ RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn, Object key);
+
+ GetDataMapCommand buildGetDataMapCommand(Fqn fqn);
+
+ ExistsCommand buildExistsNodeCommand(Fqn fqn);
+
+ GetKeyValueCommand buildGetKeyValueCommand(Fqn<?> fqn, Object key, boolean sendNodeEvent);
+
+ GetNodeCommand buildGetNodeCommand(Fqn fqn);
+
+ GetKeysCommand buildGetKeysCommand(Fqn fqn);
+
+ GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn);
+
+ MoveCommand buildMoveCommand(Fqn from, Fqn to);
+
+ RollbackCommand buildRollbackCommand(GlobalTransaction gtx);
+
+ OptimisticPrepareCommand buildOptimisticPrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address address, boolean onePhaseCommit);
+
+ AnnounceBuddyPoolNameCommand buildAnnounceBuddyPoolNameCommand(Address address, String buddyPoolName);
+
+ RemoveFromBuddyGroupCommand buildRemoveFromBuddyGroupCommand(String groupName);
+
+ AssignToBuddyGroupCommand buildAssignToBuddyGroupCommand(BuddyGroup group, Map<Fqn, byte[]> state);
+
+ ClusteredGetCommand buildClusteredGetCommand(Boolean searchBackupSubtrees, DataCommand dataCommand);
+
+ CreateNodeCommand buildCreateNodeCommand(Fqn fqn);
+
+ /**
+ * Builds a cache command based on the ID passed in and an object array of parameters
+ *
+ * @param id id of the command to build
+ * @param parameters parameters attached to the command
+ * @return a newly constructed cache command
+ */
+ ReplicableCommand fromStream(int id, Object[] parameters);
+}
Copied: core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactoryImpl.java (from rev 6183, core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactoryImpl.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactoryImpl.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -0,0 +1,508 @@
+package org.jboss.cache.commands;
+
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.RPCManager;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.commands.read.ExistsCommand;
+import org.jboss.cache.commands.read.GetChildrenNamesCommand;
+import org.jboss.cache.commands.read.GetDataMapCommand;
+import org.jboss.cache.commands.read.GetKeyValueCommand;
+import org.jboss.cache.commands.read.GetKeysCommand;
+import org.jboss.cache.commands.read.GetNodeCommand;
+import org.jboss.cache.commands.read.GravitateDataCommand;
+import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
+import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand;
+import org.jboss.cache.commands.remote.ClusteredGetCommand;
+import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
+import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
+import org.jboss.cache.commands.remote.ReplicateCommand;
+import org.jboss.cache.commands.tx.CommitCommand;
+import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
+import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.commands.write.ClearDataCommand;
+import org.jboss.cache.commands.write.CreateNodeCommand;
+import org.jboss.cache.commands.write.EvictCommand;
+import org.jboss.cache.commands.write.InvalidateCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.cache.commands.write.VersionedInvalidateCommand;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.interceptors.InterceptorChain;
+import org.jboss.cache.notifications.Notifier;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.transaction.TransactionTable;
+import org.jgroups.Address;
+
+import javax.transaction.TransactionManager;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This is the implementation to use for most commands and most locking schemes.
+ */
+public class CommandsFactoryImpl implements CommandsFactory
+{
+ protected RPCManager rpcManager;
+ protected DataContainer dataContainer;
+ protected Notifier notifier;
+ protected InterceptorChain invoker;
+ protected BuddyManager buddyManager;
+ protected TransactionTable transactionTable;
+ protected CacheSPI cacheSpi;
+ protected Configuration configuration;
+ protected TransactionManager txManager;
+ protected BuddyFqnTransformer buddyFqnTransformer;
+
+ public CommandsFactoryImpl()
+ {
+ }
+
+ @Inject
+ public void initialize(RPCManager rpc, DataContainer dataContainer, Notifier notifier, BuddyManager buddyManager,
+ InterceptorChain invoker, TransactionTable transactionTable, CacheSPI cacheSpi,
+ Configuration configuration, TransactionManager txManager, BuddyFqnTransformer buddyFqnTransformer)
+ {
+ this.rpcManager = rpc;
+ this.dataContainer = dataContainer;
+ this.notifier = notifier;
+ this.buddyManager = buddyManager;
+ this.invoker = invoker;
+ this.transactionTable = transactionTable;
+ this.cacheSpi = cacheSpi;
+ this.configuration = configuration;
+ this.txManager = txManager;
+ this.buddyFqnTransformer = buddyFqnTransformer;
+ }
+
+ public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data)
+ {
+ PutDataMapCommand cmd = new PutDataMapCommand(gtx, fqn, data);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ public PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
+ {
+ PutKeyValueCommand cmd = new PutKeyValueCommand(gtx, fqn, key, value);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ public PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
+ {
+ PutForExternalReadCommand cmd = new PutForExternalReadCommand(gtx, fqn, key, value);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ public ReplicateCommand buildReplicateCommand(ReplicableCommand command)
+ {
+ ReplicateCommand cmd = new ReplicateCommand(command);
+ cmd.initialize(invoker);
+ return cmd;
+ }
+
+ public ReplicateCommand buildReplicateCommand(List<ReplicableCommand> modifications)
+ {
+ ReplicateCommand cmd = new ReplicateCommand(modifications);
+ cmd.initialize(invoker);
+ return cmd;
+ }
+
+ public PrepareCommand buildPrepareCommand(GlobalTransaction gtx, WriteCommand command, boolean onePhaseCommit)
+ {
+ return buildPrepareCommand(gtx, Collections.singletonList(command), rpcManager.getLocalAddress(), onePhaseCommit);
+ }
+
+ public PrepareCommand buildPrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address address, boolean onePhaseCommit)
+ {
+ return new PrepareCommand(gtx, modifications, address, onePhaseCommit);
+ }
+
+ public CommitCommand buildCommitCommand(GlobalTransaction gtx)
+ {
+ return new CommitCommand(gtx);
+ }
+
+ public DataGravitationCleanupCommand buildDataGravitationCleanupCommand(Fqn primaryFqn, Fqn backupFqn)
+ {
+ DataGravitationCleanupCommand command = new DataGravitationCleanupCommand(primaryFqn, backupFqn);
+ command.initialize(buddyManager, invoker, transactionTable, this, dataContainer, buddyFqnTransformer);
+ return command;
+ }
+
+ public GravitateDataCommand buildGravitateDataCommand(Fqn fqn, Boolean searchSubtrees)
+ {
+ GravitateDataCommand command = new GravitateDataCommand(fqn, searchSubtrees, rpcManager.getLocalAddress());
+ command.initialize(dataContainer, cacheSpi, buddyFqnTransformer);
+ return command;
+ }
+
+ public EvictCommand buildEvictFqnCommand(Fqn fqn)
+ {
+ EvictCommand command = new EvictCommand(fqn);
+ command.initialize(notifier, dataContainer);
+ return command;
+ }
+
+ public InvalidateCommand buildInvalidateCommand(Fqn fqn)
+ {
+ if (configuration.getNodeLockingScheme().isVersionedScheme())
+ {
+ VersionedInvalidateCommand command = new VersionedInvalidateCommand(fqn);
+ command.initialize(txManager);
+ command.initialize(cacheSpi, dataContainer, notifier);
+ return command;
+ }
+ else
+ {
+ InvalidateCommand command = new InvalidateCommand(fqn);
+ command.initialize(cacheSpi, dataContainer, notifier);
+ return command;
+ }
+ }
+
+ public GetDataMapCommand buildGetDataMapCommand(Fqn fqn)
+ {
+ GetDataMapCommand command = new GetDataMapCommand(fqn);
+ command.initialize(dataContainer);
+ return command;
+ }
+
+ public ExistsCommand buildExistsNodeCommand(Fqn fqn)
+ {
+ ExistsCommand command = new ExistsCommand(fqn);
+ command.initialize(dataContainer);
+ return command;
+ }
+
+ public GetKeyValueCommand buildGetKeyValueCommand(Fqn<?> fqn, Object key, boolean sendNodeEvent)
+ {
+ GetKeyValueCommand command = new GetKeyValueCommand(fqn, key, sendNodeEvent);
+ command.initialize(dataContainer, notifier);
+ return command;
+ }
+
+ public GetNodeCommand buildGetNodeCommand(Fqn fqn)
+ {
+ GetNodeCommand command = new GetNodeCommand(fqn);
+ command.initialize(dataContainer);
+ return command;
+ }
+
+ public GetKeysCommand buildGetKeysCommand(Fqn fqn)
+ {
+ GetKeysCommand command = new GetKeysCommand(fqn);
+ command.initialize(dataContainer);
+ return command;
+ }
+
+ public GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn)
+ {
+ GetChildrenNamesCommand command = new GetChildrenNamesCommand(fqn);
+ command.initialize(dataContainer);
+ return command;
+ }
+
+ public RollbackCommand buildRollbackCommand(GlobalTransaction gtx)
+ {
+ return new RollbackCommand(gtx);
+ }
+
+ public OptimisticPrepareCommand buildOptimisticPrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address address, boolean onePhaseCommit)
+ {
+ return new OptimisticPrepareCommand(gtx, modifications, address, onePhaseCommit);
+ }
+
+ public AnnounceBuddyPoolNameCommand buildAnnounceBuddyPoolNameCommand(Address address, String buddyPoolName)
+ {
+ AnnounceBuddyPoolNameCommand command = new AnnounceBuddyPoolNameCommand(address, buddyPoolName);
+ command.initialize(buddyManager);
+ return command;
+ }
+
+ public RemoveFromBuddyGroupCommand buildRemoveFromBuddyGroupCommand(String groupName)
+ {
+ RemoveFromBuddyGroupCommand command = new RemoveFromBuddyGroupCommand(groupName);
+ command.initialize(buddyManager);
+ return command;
+ }
+
+ public AssignToBuddyGroupCommand buildAssignToBuddyGroupCommand(BuddyGroup group, Map<Fqn, byte[]> state)
+ {
+ AssignToBuddyGroupCommand command = new AssignToBuddyGroupCommand(group, state);
+ command.initialize(buddyManager);
+ return command;
+ }
+
+ public ClusteredGetCommand buildClusteredGetCommand(Boolean searchBackupSubtrees, DataCommand dataCommand)
+ {
+ ClusteredGetCommand command = new ClusteredGetCommand(searchBackupSubtrees, dataCommand);
+ command.initialize(dataContainer, invoker);
+ return command;
+ }
+
+ public RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn)
+ {
+ RemoveNodeCommand cmd = new RemoveNodeCommand(gtx, fqn);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ public ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn)
+ {
+ ClearDataCommand cmd = new ClearDataCommand(gtx, fqn);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ public RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn, Object key)
+ {
+ RemoveKeyCommand cmd = new RemoveKeyCommand(tx, fqn, key);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ public MoveCommand buildMoveCommand(Fqn from, Fqn to)
+ {
+ MoveCommand cmd = new MoveCommand(from, to);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ public CreateNodeCommand buildCreateNodeCommand(Fqn fqn)
+ {
+ CreateNodeCommand command = new CreateNodeCommand(fqn);
+ command.initialize(dataContainer);
+ return command;
+ }
+
+ public ReplicableCommand fromStream(int id, Object[] parameters)
+ {
+ ReplicableCommand command;
+ switch (id)
+ {
+ case ExistsCommand.METHOD_ID:
+ {
+ ExistsCommand result = new ExistsCommand();
+ result.initialize(dataContainer);
+ command = result;
+ break;
+ }
+ case GetChildrenNamesCommand.METHOD_ID:
+ {
+ GetChildrenNamesCommand returnValue = new GetChildrenNamesCommand();
+ returnValue.initialize(dataContainer);
+ command = returnValue;
+ break;
+ }
+ case GetDataMapCommand.METHOD_ID:
+ {
+ GetDataMapCommand returnValue = new GetDataMapCommand();
+ returnValue.initialize(dataContainer);
+ command = returnValue;
+ break;
+ }
+ case GetKeysCommand.METHOD_ID:
+ {
+ GetKeysCommand returnValue = new GetKeysCommand();
+ returnValue.initialize(dataContainer);
+ command = returnValue;
+ break;
+ }
+ case GetKeyValueCommand.METHOD_ID:
+ {
+ GetKeyValueCommand returnValue = new GetKeyValueCommand();
+ returnValue.initialize(dataContainer, notifier);
+ command = returnValue;
+ break;
+ }
+ case GetNodeCommand.METHOD_ID:
+ {
+ GetNodeCommand returnValue = new GetNodeCommand();
+ returnValue.initialize(dataContainer);
+ command = returnValue;
+ break;
+ }
+ case MoveCommand.METHOD_ID:
+ {
+ MoveCommand returnValue = new MoveCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case PutDataMapCommand.METHOD_ID:
+ case PutDataMapCommand.ERASE_METHOD_ID:
+ case PutDataMapCommand.ERASE_VERSIONED_METHOD_ID:
+ case PutDataMapCommand.VERSIONED_METHOD_ID:
+ {
+ PutDataMapCommand returnValue = new PutDataMapCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case PutKeyValueCommand.METHOD_ID:
+ case PutKeyValueCommand.VERSIONED_METHOD_ID:
+ {
+ PutKeyValueCommand returnValue = new PutKeyValueCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case PutForExternalReadCommand.METHOD_ID:
+ case PutForExternalReadCommand.VERSIONED_METHOD_ID:
+ {
+ PutForExternalReadCommand returnValue = new PutForExternalReadCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case ClearDataCommand.METHOD_ID:
+ case ClearDataCommand.VERSIONED_METHOD_ID:
+ {
+ ClearDataCommand returnValue = new ClearDataCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case RemoveKeyCommand.METHOD_ID:
+ case RemoveKeyCommand.VERSIONED_METHOD_ID:
+ {
+ RemoveKeyCommand returnValue = new RemoveKeyCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+
+ case RemoveNodeCommand.METHOD_ID:
+ case RemoveNodeCommand.VERSIONED_METHOD_ID:
+ {
+ RemoveNodeCommand returnValue = new RemoveNodeCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case CreateNodeCommand.METHOD_ID:
+ {
+ CreateNodeCommand returnValue = new CreateNodeCommand(null);
+ returnValue.initialize(dataContainer);
+ command = returnValue;
+ break;
+ }
+ // --- transactional method calls
+
+ case PrepareCommand.METHOD_ID:
+ {
+ command = new PrepareCommand();
+ break;
+ }
+
+ case OptimisticPrepareCommand.METHOD_ID:
+ {
+ command = new OptimisticPrepareCommand();
+ break;
+ }
+
+ case CommitCommand.METHOD_ID:
+ {
+ command = new CommitCommand();
+ break;
+ }
+
+ case RollbackCommand.METHOD_ID:
+ {
+ command = new RollbackCommand();
+ break;
+ }
+
+ // --- replicate methods
+ case ReplicateCommand.MULTIPLE_METHOD_ID:
+ case ReplicateCommand.SINGLE_METHOD_ID:
+ {
+ ReplicateCommand returnValue = new ReplicateCommand();
+ returnValue.initialize(invoker);
+ command = returnValue;
+ break;
+ }
+
+ case InvalidateCommand.METHOD_ID:
+ {
+ if (configuration.getNodeLockingScheme().isVersionedScheme())
+ {
+ VersionedInvalidateCommand returnValue = new VersionedInvalidateCommand();
+ returnValue.initialize(txManager);
+ returnValue.initialize(cacheSpi, dataContainer, notifier);
+ command = returnValue;
+ }
+ else
+ {
+ InvalidateCommand returnValue = new InvalidateCommand();
+ returnValue.initialize(cacheSpi, dataContainer, notifier);
+ command = returnValue;
+ }
+ break;
+ }
+
+ case ClusteredGetCommand.METHOD_ID:
+ {
+ ClusteredGetCommand returnValue = new ClusteredGetCommand();
+ returnValue.initialize(dataContainer, invoker);
+ command = returnValue;
+ break;
+ }
+ // ---- Buddy replication - group organisation commands
+ case AnnounceBuddyPoolNameCommand.METHOD_ID:
+ {
+ AnnounceBuddyPoolNameCommand returnValue = new AnnounceBuddyPoolNameCommand();
+ returnValue.initialize(buddyManager);
+ command = returnValue;
+ break;
+ }
+ case AssignToBuddyGroupCommand.METHOD_ID:
+ {
+ AssignToBuddyGroupCommand returnValue = new AssignToBuddyGroupCommand();
+ returnValue.initialize(buddyManager);
+ command = returnValue;
+ break;
+ }
+ case RemoveFromBuddyGroupCommand.METHOD_ID:
+ {
+ RemoveFromBuddyGroupCommand returnValue = new RemoveFromBuddyGroupCommand();
+ returnValue.initialize(buddyManager);
+ command = returnValue;
+ break;
+ }
+ case DataGravitationCleanupCommand.METHOD_ID:
+ {
+ DataGravitationCleanupCommand returnValue = new DataGravitationCleanupCommand();
+ returnValue.initialize(buddyManager, invoker, transactionTable, this, dataContainer, buddyFqnTransformer);
+ command = returnValue;
+ break;
+ }
+ case GravitateDataCommand.METHOD_ID:
+ {
+ GravitateDataCommand returnValue = new GravitateDataCommand(rpcManager.getLocalAddress());
+ returnValue.initialize(dataContainer, cacheSpi, buddyFqnTransformer);
+ command = returnValue;
+ break;
+ }
+ default:
+ throw new CacheException("Unknown command id " + id + "!");
+ }
+
+ command.setParameters(id, parameters);
+ return command;
+ }
+}
Copied: core/trunk/src/main/java/org/jboss/cache/commands/OptimisticCommandsFactoryImpl.java (from rev 6183, core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/OptimisticCommandsFactoryImpl.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/commands/OptimisticCommandsFactoryImpl.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -0,0 +1,22 @@
+package org.jboss.cache.commands;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.legacy.write.LegacyEvictCommand;
+import org.jboss.cache.commands.write.EvictCommand;
+
+/**
+ * Extends the default commands factory impl for optimistic locking.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class OptimisticCommandsFactoryImpl extends CommandsFactoryImpl
+{
+ @Override
+ public EvictCommand buildEvictFqnCommand(Fqn fqn)
+ {
+ EvictCommand command = new LegacyEvictCommand(fqn);
+ command.initialize(notifier, dataContainer);
+ return command;
+ }
+}
Copied: core/trunk/src/main/java/org/jboss/cache/commands/PessimisticCommandsFactoryImpl.java (from rev 6183, core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/PessimisticCommandsFactoryImpl.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/commands/PessimisticCommandsFactoryImpl.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -0,0 +1,198 @@
+package org.jboss.cache.commands;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.legacy.read.PessGetChildrenNamesCommand;
+import org.jboss.cache.commands.legacy.write.PessClearDataCommand;
+import org.jboss.cache.commands.legacy.write.PessCreateNodeCommand;
+import org.jboss.cache.commands.legacy.write.PessMoveCommand;
+import org.jboss.cache.commands.legacy.write.PessPutDataMapCommand;
+import org.jboss.cache.commands.legacy.write.PessPutForExternalReadCommand;
+import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
+import org.jboss.cache.commands.legacy.write.PessRemoveKeyCommand;
+import org.jboss.cache.commands.legacy.write.PessRemoveNodeCommand;
+import org.jboss.cache.commands.read.GetChildrenNamesCommand;
+import org.jboss.cache.commands.write.ClearDataCommand;
+import org.jboss.cache.commands.write.CreateNodeCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.cache.transaction.GlobalTransaction;
+
+import java.util.Map;
+
+/**
+ * This specific implementation of {@link CommandsFactory} specifically creates
+ * pessimistic commands where appropriate, with the ability to roll back.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @see org.jboss.cache.commands.legacy.ReversibleCommand
+ * @since 3.0
+ */
+public class PessimisticCommandsFactoryImpl extends OptimisticCommandsFactoryImpl
+{
+ @Override
+ public GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn)
+ {
+ GetChildrenNamesCommand command = new PessGetChildrenNamesCommand(fqn);
+ command.initialize(dataContainer);
+ return command;
+ }
+
+ @Override
+ public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data)
+ {
+ PutDataMapCommand cmd = new PessPutDataMapCommand(gtx, fqn, data);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ @Override
+ public PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
+ {
+ PutKeyValueCommand cmd = new PessPutKeyValueCommand(gtx, fqn, key, value);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ @Override
+ public PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
+ {
+ PutForExternalReadCommand cmd = new PessPutForExternalReadCommand(gtx, fqn, key, value);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ @Override
+ public RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn)
+ {
+ RemoveNodeCommand cmd = new PessRemoveNodeCommand(gtx, fqn);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ @Override
+ public ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn)
+ {
+ ClearDataCommand cmd = new PessClearDataCommand(gtx, fqn);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ @Override
+ public RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn, Object key)
+ {
+ RemoveKeyCommand cmd = new PessRemoveKeyCommand(tx, fqn, key);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ @Override
+ public MoveCommand buildMoveCommand(Fqn from, Fqn to)
+ {
+ MoveCommand cmd = new PessMoveCommand(from, to);
+ cmd.initialize(notifier, dataContainer);
+ return cmd;
+ }
+
+ @Override
+ public CreateNodeCommand buildCreateNodeCommand(Fqn fqn)
+ {
+ CreateNodeCommand command = new PessCreateNodeCommand(fqn);
+ command.initialize(dataContainer);
+ return command;
+ }
+
+ @Override
+ public ReplicableCommand fromStream(int id, Object[] parameters)
+ {
+ ReplicableCommand command;
+ boolean skipSetParams = false;
+ switch (id)
+ {
+ case GetChildrenNamesCommand.METHOD_ID:
+ {
+ GetChildrenNamesCommand returnValue = new PessGetChildrenNamesCommand();
+ returnValue.initialize(dataContainer);
+ command = returnValue;
+ break;
+ }
+ case MoveCommand.METHOD_ID:
+ {
+ MoveCommand returnValue = new PessMoveCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case PutDataMapCommand.METHOD_ID:
+ case PutDataMapCommand.ERASE_METHOD_ID:
+ case PutDataMapCommand.ERASE_VERSIONED_METHOD_ID:
+ case PutDataMapCommand.VERSIONED_METHOD_ID:
+ {
+ PutDataMapCommand returnValue = new PessPutDataMapCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case PutKeyValueCommand.METHOD_ID:
+ case PutKeyValueCommand.VERSIONED_METHOD_ID:
+ {
+ PutKeyValueCommand returnValue = new PessPutKeyValueCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case PutForExternalReadCommand.METHOD_ID:
+ case PutForExternalReadCommand.VERSIONED_METHOD_ID:
+ {
+ PutForExternalReadCommand returnValue = new PessPutForExternalReadCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case ClearDataCommand.METHOD_ID:
+ case ClearDataCommand.VERSIONED_METHOD_ID:
+ {
+ ClearDataCommand returnValue = new PessClearDataCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case RemoveKeyCommand.METHOD_ID:
+ case RemoveKeyCommand.VERSIONED_METHOD_ID:
+ {
+ RemoveKeyCommand returnValue = new PessRemoveKeyCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+
+ case RemoveNodeCommand.METHOD_ID:
+ case RemoveNodeCommand.VERSIONED_METHOD_ID:
+ {
+ RemoveNodeCommand returnValue = new PessRemoveNodeCommand();
+ returnValue.initialize(notifier, dataContainer);
+ command = returnValue;
+ break;
+ }
+ case CreateNodeCommand.METHOD_ID:
+ {
+ CreateNodeCommand returnValue = new PessCreateNodeCommand(null);
+ returnValue.initialize(dataContainer);
+ command = returnValue;
+ break;
+ }
+ default:
+ // pass up to superclass
+ command = super.fromStream(id, parameters);
+ skipSetParams = true;
+ }
+ if (!skipSetParams)
+ {
+ command.setParameters(id, parameters);
+ }
+ return command;
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/ReplicableCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/ReplicableCommand.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/commands/ReplicableCommand.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -39,7 +39,7 @@
Object[] getParameters();
/**
- * Used by the {@link org.jboss.cache.factories.CommandsFactory} to create a command from raw data read off a stream.
+ * Used by the {@link CommandsFactory} to create a command from raw data read off a stream.
*
* @param commandId command id to set. This is usually unused but *could* be used in the event of a command having multiple IDs, such as {@link org.jboss.cache.commands.write.PutKeyValueCommand}.
* @param parameters object array of args
Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -7,10 +7,10 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.write.EvictCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.interceptors.InterceptorChain;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -1,5 +1,9 @@
package org.jboss.cache.factories;
+import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.cache.commands.CommandsFactoryImpl;
+import org.jboss.cache.commands.OptimisticCommandsFactoryImpl;
+import org.jboss.cache.commands.PessimisticCommandsFactoryImpl;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -6,10 +6,10 @@
import org.jboss.cache.RPCManager;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.cluster.ReplicationQueue;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.config.Option;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.interceptors.base.CommandInterceptor;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -13,6 +13,7 @@
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.buddyreplication.GravitateResult;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.DataCommand;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.read.ExistsCommand;
@@ -25,7 +26,6 @@
import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
import org.jboss.cache.commands.tx.CommitCommand;
import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.marshall.NodeData;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -8,6 +8,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.commands.AbstractVisitor;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.WriteCommand;
import org.jboss.cache.commands.tx.CommitCommand;
@@ -25,7 +26,6 @@
import org.jboss.cache.commands.write.VersionedInvalidateCommand;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.config.Option;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.invocation.InvocationContext;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -9,6 +9,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.commands.AbstractVisitor;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.VersionedDataCommand;
import org.jboss.cache.commands.VisitableCommand;
@@ -25,7 +26,6 @@
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.optimistic.DataVersion;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -9,6 +9,7 @@
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.DataCommand;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.WriteCommand;
@@ -28,7 +29,6 @@
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.base.PrePostProcessingCommandInterceptor;
import org.jboss.cache.invocation.InvocationContext;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -10,6 +10,7 @@
import org.jboss.cache.RPCManager;
import org.jboss.cache.ReplicationException;
import org.jboss.cache.commands.AbstractVisitor;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.WriteCommand;
@@ -25,7 +26,6 @@
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.config.Option;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.context.ContextFactory;
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -13,6 +13,7 @@
import org.jboss.cache.Version;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.buddyreplication.GravitateResult;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
import org.jboss.cache.commands.read.GetDataMapCommand;
import org.jboss.cache.commands.read.GetKeyValueCommand;
@@ -28,7 +29,6 @@
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Option;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.NonVolatile;
import org.jboss.cache.interceptors.base.CommandInterceptor;
Modified: core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -15,6 +15,7 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.RegionManager;
import org.jboss.cache.ReplicationException;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.DataCommand;
import org.jboss.cache.commands.read.ExistsCommand;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
@@ -22,7 +23,6 @@
import org.jboss.cache.commands.read.GetKeyValueCommand;
import org.jboss.cache.commands.remote.ClusteredGetCommand;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.lock.StripedLock;
import org.jgroups.Address;
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockUtil.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockUtil.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockUtil.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -4,10 +4,9 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.invocation.InvocationContext;
-import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionContext;
import org.jboss.cache.transaction.TransactionTable;
@@ -21,7 +20,7 @@
public abstract class LockUtil
{
- private final static Log log = LogFactory.getLog(StateTransferManager.class);
+ private final static Log log = LogFactory.getLog(LockUtil.class);
private static final boolean trace = log.isTraceEnabled();
private static interface TransactionLockStatus extends Status
Modified: core/trunk/src/main/java/org/jboss/cache/lock/PessimisticNodeBasedLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/PessimisticNodeBasedLockManager.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/lock/PessimisticNodeBasedLockManager.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -4,7 +4,7 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.factories.CommandsFactory;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.invocation.InvocationContext;
import static org.jboss.cache.lock.LockType.WRITE;
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -10,8 +10,8 @@
import org.jboss.cache.Region;
import static org.jboss.cache.Region.Status;
import org.jboss.cache.buddyreplication.GravitateResult;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -7,6 +7,7 @@
package org.jboss.cache.buddyreplication;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.CommandsFactoryImpl;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
import org.jboss.cache.commands.write.PutKeyValueCommand;
@@ -14,7 +15,6 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.parsing.element.BuddyElementParser;
-import org.jboss.cache.factories.CommandsFactoryImpl;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
Modified: core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -13,13 +13,13 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
-import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.read.GetKeyValueCommand;
import org.jboss.cache.commands.read.GetNodeCommand;
+import org.jboss.cache.commands.write.ClearDataCommand;
import org.jboss.cache.commands.write.PutDataMapCommand;
import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.config.EvictionConfig;
@@ -27,8 +27,8 @@
import org.jboss.cache.eviction.DummyEvictionConfiguration;
import org.jboss.cache.eviction.EvictedEventNode;
import org.jboss.cache.eviction.NodeEventType;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -1,11 +1,11 @@
package org.jboss.cache.marshall;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.cache.commands.CommandsFactoryImpl;
import org.jboss.cache.commands.WriteCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.factories.CommandsFactory;
-import org.jboss.cache.factories.CommandsFactoryImpl;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -5,13 +5,13 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.buddyreplication.GravitateResult;
+import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.cache.commands.CommandsFactoryImpl;
import org.jboss.cache.commands.DataCommand;
import org.jboss.cache.commands.read.GetKeyValueCommand;
import org.jboss.cache.commands.read.GravitateDataCommand;
import org.jboss.cache.commands.remote.ClusteredGetCommand;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.CommandsFactory;
-import org.jboss.cache.factories.CommandsFactoryImpl;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
Modified: core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java 2008-07-07 19:52:12 UTC (rev 6196)
+++ core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java 2008-07-07 20:19:19 UTC (rev 6197)
@@ -11,8 +11,8 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.VisitableCommand;
-import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.interceptors.InterceptorChain;
import org.jboss.cache.interceptors.base.CommandInterceptor;
15 years, 10 months
JBoss Cache SVN: r6196 - core/branches/2.1.X/src/test/java/org/jboss/cache/marshall.
by jbosscache-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2008-07-07 15:52:12 -0400 (Mon, 07 Jul 2008)
New Revision: 6196
Modified:
core/branches/2.1.X/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java
Log:
[JBCACHE-1357] Issue not present in 2.1.x but I still added the test case.
Modified: core/branches/2.1.X/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java
===================================================================
--- core/branches/2.1.X/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java 2008-07-07 19:46:19 UTC (rev 6195)
+++ core/branches/2.1.X/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java 2008-07-07 19:52:12 UTC (rev 6196)
@@ -3,6 +3,7 @@
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
import org.jboss.cache.Region;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
@@ -14,6 +15,8 @@
import org.jboss.cache.loader.FileCacheLoaderConfig;
import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -28,6 +31,7 @@
* not visible to the cache's default classloader.
*
* @author <a href="mailto:brian.stansberry@jboss.org">Brian Stansberry</a>
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
* @since 2.1.0
*/
@Test(groups = "functional")
@@ -65,7 +69,42 @@
{
cacheLoaderMarshallingTest(true);
}
+
+ public void testLoadNodesAtRootOfRegion() throws Exception
+ {
+ String rootRegionName = "/myregion";
+ String hereFqn = rootRegionName + "/here";
+
+ cache = createCache(true);
+ cache.start();
+ Region r = cache.getRegion(Fqn.fromString(rootRegionName), true);
+ r.registerContextClassLoader(Thread.currentThread().getContextClassLoader());
+ r.activate();
+
+ cache.put(rootRegionName, "a key", "a value");
+ cache.put(hereFqn, "another key", "another value");
+
+ r.deactivate();
+ r.unregisterContextClassLoader();
+
+ cache.stop();
+
+ cache.start();
+
+ r = cache.getRegion(Fqn.fromString(rootRegionName), true);
+ r.registerContextClassLoader(Thread.currentThread().getContextClassLoader());
+ r.activate();
+
+ Node<Object, Object> rootRegionNode = cache.getNode(rootRegionName);
+ Node<Object, Object> hereNode = cache.getNode(hereFqn);
+ assertNotNull(rootRegionNode);
+ assertNotNull(hereNode);
+
+ assertEquals(hereNode.get("another key"), "another value");
+ assertEquals(rootRegionNode.get("a key"), "a value");
+ }
+
private void cacheLoaderMarshallingTest(boolean useRegionBased) throws Exception
{
cache = createCache(useRegionBased);
15 years, 10 months
JBoss Cache SVN: r6195 - core/trunk/src/test/java/org/jboss/cache/marshall.
by jbosscache-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2008-07-07 15:46:19 -0400 (Mon, 07 Jul 2008)
New Revision: 6195
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java
Log:
[JBCACHE-1357] Issue not present in trunk but I still added the test case.
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java 2008-07-07 19:41:29 UTC (rev 6194)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java 2008-07-07 19:46:19 UTC (rev 6195)
@@ -3,6 +3,7 @@
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
import org.jboss.cache.Region;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
@@ -14,6 +15,8 @@
import org.jboss.cache.loader.FileCacheLoaderConfig;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -28,6 +31,7 @@
* not visible to the cache's default classloader.
*
* @author <a href="mailto:brian.stansberry@jboss.org">Brian Stansberry</a>
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
* @since 2.1.0
*/
@Test(groups = "functional")
@@ -65,7 +69,42 @@
{
cacheLoaderMarshallingTest(true);
}
+
+ public void testLoadNodesAtRootOfRegion() throws Exception
+ {
+ String rootRegionName = "/myregion";
+ String hereFqn = rootRegionName + "/here";
+
+ cache = createCache(true);
+ cache.start();
+ Region r = cache.getRegion(Fqn.fromString(rootRegionName), true);
+ r.registerContextClassLoader(Thread.currentThread().getContextClassLoader());
+ r.activate();
+
+ cache.put(rootRegionName, "a key", "a value");
+ cache.put(hereFqn, "another key", "another value");
+
+ r.deactivate();
+ r.unregisterContextClassLoader();
+
+ cache.stop();
+
+ cache.start();
+
+ r = cache.getRegion(Fqn.fromString(rootRegionName), true);
+ r.registerContextClassLoader(Thread.currentThread().getContextClassLoader());
+ r.activate();
+
+ Node<Object, Object> rootRegionNode = cache.getNode(rootRegionName);
+ Node<Object, Object> hereNode = cache.getNode(hereFqn);
+ assertNotNull(rootRegionNode);
+ assertNotNull(hereNode);
+
+ assertEquals(hereNode.get("another key"), "another value");
+ assertEquals(rootRegionNode.get("a key"), "a value");
+ }
+
private void cacheLoaderMarshallingTest(boolean useRegionBased) throws Exception
{
cache = createCache(useRegionBased);
15 years, 10 months