[jbosscache-commits] JBoss Cache SVN: r6256 - in core/trunk/src: main/java/org/jboss/cache/config and 6 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Mon Jul 14 10:39:46 EDT 2008
Author: manik.surtani at jboss.com
Date: 2008-07-14 10:39:46 -0400 (Mon, 14 Jul 2008)
New Revision: 6256
Added:
core/trunk/src/main/java/org/jboss/cache/AbstractNodeFactory.java
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
core/trunk/src/main/java/org/jboss/cache/PessimisticNodeFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/NodeMetaFactory.java
core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeFactory.java
core/trunk/src/main/java/org/jboss/cache/optimistic/OptimisticNodeFactory.java
Removed:
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
Modified:
core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
core/trunk/src/main/java/org/jboss/cache/InternalNode.java
core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/VersionedNode.java
core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/factories/RuntimeConfigAwareFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java
core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferFactory.java
core/trunk/src/test/java/org/jboss/cache/lock/AbstractLockManagerRecordingTest.java
Log:
Tidied up NodeFactory implementations
Copied: core/trunk/src/main/java/org/jboss/cache/AbstractNodeFactory.java (from rev 6255, core/trunk/src/main/java/org/jboss/cache/NodeFactory.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/AbstractNodeFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/AbstractNodeFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache;
+
+import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.ComponentRegistry;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.interceptors.InterceptorChain;
+import org.jboss.cache.invocation.InvocationContextContainer;
+import org.jboss.cache.invocation.NodeInvocationDelegate;
+import org.jboss.cache.lock.LockStrategyFactory;
+import org.jboss.cache.mvcc.ReadCommittedNode;
+import org.jboss.cache.optimistic.TransactionWorkspace;
+import org.jboss.cache.optimistic.WorkspaceNode;
+
+import java.util.Map;
+
+/**
+ * Generates new nodes based on the {@link CacheSPI} configuration.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ */
+public abstract class AbstractNodeFactory<K, V> implements NodeFactory<K, V>
+{
+ protected CacheSPI<K, V> cache;
+ protected boolean useVersionedNode;
+ protected Configuration configuration;
+ protected InvocationContextContainer invocationContextContainer;
+ protected InterceptorChain interceptorChain;
+ protected CommandsFactory commandsFactory;
+ protected LockStrategyFactory lockStrategyFactory;
+ protected ComponentRegistry componentRegistry;
+
+
+ @Inject
+ private void injectComponentRegistry(ComponentRegistry componentRegistry)
+ {
+ this.componentRegistry = componentRegistry;
+ }
+
+ @Inject
+ public void injectDependencies(CacheSPI<K, V> cache, Configuration configuration,
+ InvocationContextContainer invocationContextContainer,
+ InterceptorChain interceptorChain, CommandsFactory commandsFactory, LockStrategyFactory lockStrategyFactory)
+ {
+ this.cache = cache;
+ this.configuration = configuration;
+ this.invocationContextContainer = invocationContextContainer;
+ this.interceptorChain = interceptorChain;
+ this.commandsFactory = commandsFactory;
+ this.lockStrategyFactory = lockStrategyFactory;
+ }
+
+ public NodeSPI<K, V> createNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
+ {
+ UnversionedNode<K, V> internal = createInternalNode(childName, fqn, parent, data, mapSafe);
+
+ // always assume that new nodes do not have data loaded
+ internal.setDataLoaded(false);
+ NodeSPI<K, V> nid = createNodeInvocationDelegate(internal, false);
+
+ // back reference
+ internal.setDelegate(nid);
+ return nid;
+ }
+
+ protected UnversionedNode<K, V> createInternalNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
+ {
+ throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
+ }
+
+ public WorkspaceNode<K, V> createWrappedNode(NodeSPI<K, V> dataNode, TransactionWorkspace workspace)
+ {
+ throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
+ }
+
+ public ReadCommittedNode createWrappedNode(InternalNode<K, V> node)
+ {
+ throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
+ }
+
+ public NodeSPI<K, V> createRootNode()
+ {
+ return createNode(null, Fqn.ROOT, null, null, false);
+ }
+
+ public NodeSPI<K, V> createNodeInvocationDelegate(InternalNode<K, V> internalNode, boolean wrapWithNodeReference)
+ {
+ if (wrapWithNodeReference)
+ throw new UnsupportedOperationException("wrapWithNodeReferences is not supported in this impl!");
+ NodeInvocationDelegate<K, V> nid = new NodeInvocationDelegate<K, V>(internalNode);
+ nid.initialize(configuration, invocationContextContainer, componentRegistry, interceptorChain);
+ nid.injectDependencies(cache);
+ return nid;
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/AbstractNodeFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -68,7 +68,7 @@
{
if (trace) log.trace("Starting data container");
// create a new root temporarily.
- NodeSPI tempRoot = nodeFactory.createRootDataNode();
+ NodeSPI tempRoot = nodeFactory.createRootNode();
// if we don't already have a root or the new (temp) root is of a different class (optimistic vs pessimistic) to
// the current root, then we use the new one.
Modified: core/trunk/src/main/java/org/jboss/cache/InternalNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InternalNode.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/InternalNode.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -18,39 +18,39 @@
*/
public interface InternalNode<K, V>
{
- NodeSPI getParent();
+ NodeSPI<K, V> getParent();
- CacheSPI getCache();
+ CacheSPI<K, V> getCache();
boolean isChildrenLoaded();
void setChildrenLoaded(boolean flag);
- Object getDirect(Object key);
+ V getDirect(K key);
- Map getDataDirect();
+ Map<K, V> getDataDirect();
- Object putDirect(Object key, Object value);
+ V putDirect(K key, V value);
- NodeSPI getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean notify);
+ NodeSPI<K, V> getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean notify);
- Object removeDirect(Object key);
+ V removeDirect(K key);
void addChildDirect(NodeSPI child);
- NodeSPI addChildDirect(Fqn f);
+ NodeSPI<K, V> addChildDirect(Fqn f);
- NodeSPI addChildDirect(Fqn f, boolean notify);
+ NodeSPI<K, V> addChildDirect(Fqn f, boolean notify);
- NodeSPI addChildDirect(Object o, boolean notify);
+ NodeSPI<K, V> addChildDirect(Object o, boolean notify);
void clearDataDirect();
- NodeSPI getChildDirect(Fqn fqn);
+ NodeSPI<K, V> getChildDirect(Fqn fqn);
Set<Object> getChildrenNamesDirect();
- Set<Object> getKeysDirect();
+ Set<K> getKeysDirect();
boolean removeChildDirect(Object childName);
@@ -60,7 +60,7 @@
void setChildrenMapDirect(Map<Object, Node<K, V>> children);
- void putAllDirect(Map data);
+ void putAllDirect(Map<K, V> data);
void removeChildrenDirect();
@@ -72,13 +72,13 @@
void setFqn(Fqn fqn);
- NodeSPI getChildDirect(Object childName);
+ NodeSPI<K, V> getChildDirect(Object childName);
- Set<NodeSPI> getChildrenDirect();
+ Set<NodeSPI<K, V>> getChildrenDirect();
boolean hasChildrenDirect();
- Set<NodeSPI> getChildrenDirect(boolean includeMarkedForRemoval);
+ Set<NodeSPI<K, V>> getChildrenDirect(boolean includeMarkedForRemoval);
boolean isDataLoaded();
@@ -114,7 +114,7 @@
*
* @return a copy.
*/
- InternalNode copy();
+ InternalNode<K, V> copy();
NodeLock getLock();
Deleted: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -1,187 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-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.ComponentFactory;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.Start;
-import org.jboss.cache.interceptors.InterceptorChain;
-import org.jboss.cache.invocation.InvocationContextContainer;
-import org.jboss.cache.invocation.NodeInvocationDelegate;
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.lock.LockStrategyFactory;
-import org.jboss.cache.mvcc.NodeReference;
-import org.jboss.cache.mvcc.NullMarkerNode;
-import org.jboss.cache.mvcc.ReadCommittedNode;
-import org.jboss.cache.mvcc.RepeatableReadNode;
-import org.jboss.cache.optimistic.TransactionWorkspace;
-import org.jboss.cache.optimistic.WorkspaceNode;
-import org.jboss.cache.optimistic.WorkspaceNodeImpl;
-
-import java.util.Map;
-
-/**
- * Generates new nodes based on the {@link CacheSPI} configuration.
- *
- * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
- */
-public class NodeFactory<K, V> extends ComponentFactory
-{
- private CacheSPI<K, V> cache;
- private boolean useVersionedNode;
- private Configuration configuration;
- private InvocationContextContainer invocationContextContainer;
- private InterceptorChain interceptorChain;
- private CommandsFactory commandsFactory;
- private LockStrategyFactory lockStrategyFactory;
- private boolean useRepeatableRead;
- private static final NullMarkerNode NULL_MARKER = new NullMarkerNode(null);
-
- @Override
- protected <T> T construct(Class<T> componentType)
- {
- throw new UnsupportedOperationException("Should never be called!");
- }
-
- /**
- * Creates an MVCC wrapped node - either a {@link org.jboss.cache.mvcc.ReadCommittedNode} or it's subclass, a
- * {@link org.jboss.cache.mvcc.RepeatableReadNode} based on cache configuration. If a null is passed in as the InternalNode,
- * this method will return a special {@link org.jboss.cache.mvcc.NullMarkerNode} instance if using repeatable read,
- * or a null if read committed.
- *
- * @param node internal node to wrap.
- * @return a ReadCommittedNode
- */
- public ReadCommittedNode createMvccNode(InternalNode node)
- {
- if (node == null) return useRepeatableRead ? NULL_MARKER : null;
- ReadCommittedNode rcn = useRepeatableRead ? new RepeatableReadNode(node) : new ReadCommittedNode(node);
- rcn.initialize(configuration, invocationContextContainer, componentRegistry, interceptorChain);
- rcn.injectDependencies(cache);
- return rcn;
- }
-
- public enum NodeType
- {
- UNVERSIONED_NODE, VERSIONED_NODE, WORKSPACE_NODE
- }
-
- /**
- * Constructs an instance of the factory
- */
- public NodeFactory(CacheSPI<K, V> cache)
- {
- this.cache = cache;
- init();
- }
-
- public NodeFactory()
- {
- }
-
- @Inject
- public void injectDependencies(CacheSPI<K, V> cache, Configuration configuration,
- InvocationContextContainer invocationContextContainer,
- InterceptorChain interceptorChain, CommandsFactory commandsFactory, LockStrategyFactory lockStrategyFactory)
- {
- this.cache = cache;
- this.configuration = configuration;
- this.invocationContextContainer = invocationContextContainer;
- this.interceptorChain = interceptorChain;
- this.commandsFactory = commandsFactory;
- this.lockStrategyFactory = lockStrategyFactory;
- }
-
- /**
- * Initialises the node factory with the configuration from the cache.
- */
- @Start
- public void init()
- {
- useVersionedNode = configuration.getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC;
- useRepeatableRead = configuration.getIsolationLevel() == IsolationLevel.REPEATABLE_READ;
- }
-
-
- /**
- * Creates a new {@link Node} instance.
- *
- * @param childName the new node's name
- * @param fqn the new node's Fqn
- * @param parent the new node's parent
- * @param data the new node's attribute map
- * @param mapSafe <code>true</code> if param <code>data</code> can safely
- * be directly assigned to the new node's data field;
- * <code>false</code> if param <code>data</code>'s contents
- * should be copied into the new node's data field.
- * @return the new node
- */
- public NodeSPI<K, V> createDataNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
- {
- // TODO: See if data versions are needed with MVCC. Should use cheaper UnversionedNode otherwise.
- UnversionedNode un = useVersionedNode ? new VersionedNode<K, V>(fqn, parent, data, cache) : new UnversionedNode<K, V>(childName, fqn, data, cache);
-
- // it is internal nodes that are wrapped in NIDs.
- InternalNode in = un;
- if (configuration.getNodeLockingScheme() == NodeLockingScheme.MVCC && !useRepeatableRead)
- {
- // this is MVCC with READ_COMMITTED. Make sure we use node references.
- in = new NodeReference(un);
- }
- // always assume that new nodes do not have data loaded
- un.setDataLoaded(false);
- NodeInvocationDelegate<K, V> nid = new NodeInvocationDelegate(in);
-
- // Too slow to have these autowired for now. Look at manually wiring them.
- nid.initialize(configuration, invocationContextContainer, componentRegistry, interceptorChain);
- nid.injectDependencies(cache);
- un.injectDependencies(cache, commandsFactory, lockStrategyFactory);
-
-// componentRegistry.wireDependencies(nid);
-// componentRegistry.wireDependencies(un);
- // back ref
- un.setDelegate(nid);
- return nid;
- }
-
- public Node<K, V> createNode(Object childName, Node<K, V> parent, Map<K, V> data)
- {
- return createNodeOfType(parent, childName, parent, data);
- }
-
- public Node<K, V> createNodeOfType(Node<K, V> template, Object childName, Node<K, V> parent, Map<K, V> data)
- {
- // not a workspace node.
- return createDataNode(childName, Fqn.fromRelativeElements(parent.getFqn(), childName), (NodeSPI<K, V>) parent, data, false);
- }
-
- public WorkspaceNode<K, V> createWorkspaceNode(NodeSPI<K, V> dataNode, TransactionWorkspace workspace)
- {
- return new WorkspaceNodeImpl<K, V>(dataNode, workspace);
- }
-
- public NodeSPI<K, V> createRootDataNode()
- {
- return createDataNode(null, Fqn.ROOT, null, null, false);
- }
-
- public NodeSPI createNodeInvocationDelegate(InternalNode internalNode, boolean wrapWithNodeReference)
- {
- if (wrapWithNodeReference && internalNode instanceof NodeReference)
- throw new IllegalArgumentException("Cannot wrap a NodeReference with a NodeReference!");
- if (wrapWithNodeReference && useRepeatableRead)
- throw new IllegalArgumentException("Cannot use NodeReferences with RepeatableRead!");
- if (wrapWithNodeReference) internalNode = new NodeReference(internalNode);
- NodeInvocationDelegate nid = new NodeInvocationDelegate(internalNode);
- nid.initialize(configuration, invocationContextContainer, componentRegistry, interceptorChain);
- nid.injectDependencies(cache);
- return nid;
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -0,0 +1,27 @@
+package org.jboss.cache;
+
+import org.jboss.cache.mvcc.ReadCommittedNode;
+import org.jboss.cache.optimistic.TransactionWorkspace;
+import org.jboss.cache.optimistic.WorkspaceNode;
+
+import java.util.Map;
+
+/**
+ * An interface for a factory that creates nodes. This used to be a concrete class prior to 3.0.0. Made into an
+ * interface to simplify logic of different locking schemes and node types.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public interface NodeFactory<K, V>
+{
+ ReadCommittedNode createWrappedNode(InternalNode<K, V> node);
+
+ WorkspaceNode<K, V> createWrappedNode(NodeSPI<K, V> dataNode, TransactionWorkspace workspace);
+
+ NodeSPI<K, V> createNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe);
+
+ NodeSPI<K, V> createRootNode();
+
+ NodeSPI<K, V> createNodeInvocationDelegate(InternalNode<K, V> internalNode, boolean wrapWithNodeReference);
+}
Added: core/trunk/src/main/java/org/jboss/cache/PessimisticNodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/PessimisticNodeFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/PessimisticNodeFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -0,0 +1,20 @@
+package org.jboss.cache;
+
+import java.util.Map;
+
+/**
+ * Node factory specific to pessimistic locking.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public class PessimisticNodeFactory<K, V> extends AbstractNodeFactory<K, V>
+{
+ @Override
+ protected UnversionedNode<K, V> createInternalNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
+ {
+ UnversionedNode<K, V> internal = new UnversionedNode<K, V>(childName, fqn, data, cache);
+ internal.injectDependencies(cache, commandsFactory, lockStrategyFactory, this);
+ return internal;
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -756,10 +756,13 @@
public String dumpRegions()
{
StringBuilder sb = new StringBuilder();
- for (Region r : regionsRegistry.values())
+ if (regionsRegistry != null)
{
- sb.append("\tRegion ").append(r);
- sb.append("\n");
+ for (Region r : regionsRegistry.values())
+ {
+ sb.append("\tRegion ").append(r);
+ sb.append("\n");
+ }
}
return sb.toString();
}
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -60,6 +60,7 @@
protected NodeSPI delegate;
CommandsFactory commandsFactory;
protected LockStrategyFactory lockStrategyFactory;
+ private NodeFactory nodeFactory;
/**
* Constructs a new node with an FQN of Root.
@@ -82,7 +83,7 @@
/**
* Constructs a new node with a name, etc.
*/
- protected UnversionedNode(Object childName, Fqn fqn, Map data, CacheSPI cache)
+ public UnversionedNode(Object childName, Fqn fqn, Map data, CacheSPI cache)
{
if (cache == null)
{
@@ -121,11 +122,12 @@
this.delegate = delegate;
}
- public void injectDependencies(CacheSPI spi, CommandsFactory commandsFactory, LockStrategyFactory lockStrategyFactory)
+ public void injectDependencies(CacheSPI spi, CommandsFactory commandsFactory, LockStrategyFactory lockStrategyFactory, NodeFactory nodeFactory)
{
this.cache = spi;
this.commandsFactory = commandsFactory;
this.lockStrategyFactory = lockStrategyFactory;
+ this.nodeFactory = nodeFactory;
init();
}
@@ -247,22 +249,22 @@
return getOrCreateChild(child_name, gtx, true, notify);
}
- private NodeSPI getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean createIfNotExists, boolean notify)
+ private NodeSPI getOrCreateChild(Object childName, GlobalTransaction gtx, boolean createIfNotExists, boolean notify)
{
NodeSPI child;
- if (child_name == null)
+ if (childName == null)
{
throw new IllegalArgumentException("null child name");
}
- child = (NodeSPI) children().get(child_name);
+ child = (NodeSPI) children().get(childName);
InvocationContext ctx = cache.getInvocationContext();
if (createIfNotExists && child == null)
{
// construct the new child outside the synchronized block to avoid
// spending any more time than necessary in the synchronized section
- Fqn child_fqn = Fqn.fromRelativeElements(this.fqn, child_name);
- NodeSPI newChild = (NodeSPI) cache.getConfiguration().getRuntimeConfig().getNodeFactory().createNode(child_name, delegate, null);
+ Fqn child_fqn = Fqn.fromRelativeElements(this.fqn, childName);
+ NodeSPI newChild = nodeFactory.createNode(childName, Fqn.fromRelativeElements(fqn, childName), delegate, null, true);
if (newChild == null)
{
throw new IllegalStateException();
@@ -271,12 +273,12 @@
{
// check again to see if the child exists
// after acquiring exclusive lock
- child = (NodeSPI) children().get(child_name);
+ child = (NodeSPI) children().get(childName);
if (child == null)
{
if (notify) cache.getNotifier().notifyNodeCreated(child_fqn, true, ctx);
child = newChild;
- children.put(child_name, child);
+ children.put(childName, child);
if (gtx != null)
{
@@ -496,13 +498,13 @@
return children == null ? Collections.emptySet() : new HashSet<Object>(children.keySet());
}
- public Set<Object> getKeysDirect()
+ public Set<K> getKeysDirect()
{
if (data == null)
{
return Collections.emptySet();
}
- return Collections.unmodifiableSet(new HashSet<Object>(data.keySet()));
+ return Collections.unmodifiableSet(new HashSet<K>(data.keySet()));
}
public boolean removeChildDirect(Object childName)
@@ -641,18 +643,19 @@
return (NodeSPI) (children == null ? null : children.get(childName));
}
- public Set<NodeSPI> getChildrenDirect()
+ public Set<NodeSPI<K, V>> getChildrenDirect()
{
// strip out deleted child nodes...
if (children == null || children.size() == 0) return Collections.emptySet();
- Set<NodeSPI> exclDeleted = new HashSet<NodeSPI>();
+ Set<NodeSPI<K, V>> exclDeleted = new HashSet<NodeSPI<K, V>>();
for (Node n : children.values())
{
NodeSPI spi = (NodeSPI) n;
if (!spi.isDeleted()) exclDeleted.add(spi);
}
- return Collections.unmodifiableSet(exclDeleted);
+ exclDeleted = Collections.unmodifiableSet(exclDeleted);
+ return exclDeleted;
}
public boolean hasChildrenDirect()
@@ -660,7 +663,7 @@
return children != null && children.size() != 0;
}
- public Set<NodeSPI> getChildrenDirect(boolean includeMarkedForRemoval)
+ public Set<NodeSPI<K, V>> getChildrenDirect(boolean includeMarkedForRemoval)
{
if (includeMarkedForRemoval)
{
Modified: core/trunk/src/main/java/org/jboss/cache/VersionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/VersionedNode.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/VersionedNode.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -41,7 +41,7 @@
*/
private NodeSPI<K, V> parent;
- protected VersionedNode(Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, CacheSPI<K, V> cache)
+ public VersionedNode(Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, CacheSPI<K, V> cache)
{
super(fqn.getLastElement(), fqn, data, cache);
if (parent == null && !fqn.isRoot()) throw new NullPointerException("parent");
Modified: core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.config;
-import org.jboss.cache.NodeFactory;
import org.jboss.cache.RPCManager;
import org.jboss.cache.buddyreplication.BuddyGroup;
import org.jboss.cache.util.Util;
@@ -25,7 +24,6 @@
private transient TransactionManager transactionManager;
private transient Channel channel;
private transient ChannelFactory muxChannelFactory;
- private transient NodeFactory nodeFactory;
private transient BuddyGroup buddyGroup;
private RPCManager rpcManager;
@@ -34,8 +32,6 @@
*/
public void reset()
{
- // only reset the node factory and channel for now.
- nodeFactory = null;
channel = null;
rpcManager = null;
}
@@ -130,16 +126,6 @@
this.transactionManager = transactionManager;
}
- public NodeFactory getNodeFactory()
- {
- return nodeFactory;
- }
-
- public void setNodeFactory(NodeFactory nodeFactory)
- {
- this.nodeFactory = nodeFactory;
- }
-
@Override
public boolean equals(Object obj)
{
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-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -175,9 +175,11 @@
s.add(ReplicationQueueFactory.class);
s.add(LockManagerFactory.class);
s.add(ContextMetaFactory.class);
- s.add(CommandsMetaFactory.class);
+ s.add(NodeMetaFactory.class);
s.add(StateTransferManagerFactory.class);
s.add(RegionManagerFactory.class);
+ s.add(NodeMetaFactory.class);
+ s.add(CommandsMetaFactory.class);
return s;
}
Added: core/trunk/src/main/java/org/jboss/cache/factories/NodeMetaFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/NodeMetaFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/factories/NodeMetaFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -0,0 +1,34 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.NodeFactory;
+import org.jboss.cache.PessimisticNodeFactory;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+import org.jboss.cache.mvcc.MVCCNodeFactory;
+import org.jboss.cache.optimistic.OptimisticNodeFactory;
+
+/**
+ * Creates node factories.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+ at DefaultFactoryFor(classes = NodeFactory.class)
+public class NodeMetaFactory extends ComponentFactory
+{
+ @SuppressWarnings("unchecked")
+ protected <T> T construct(Class<T> componentType)
+ {
+ switch (configuration.getNodeLockingScheme())
+ {
+ case MVCC:
+ return (T) new MVCCNodeFactory();
+ case OPTIMISTIC:
+ return (T) new OptimisticNodeFactory();
+ case PESSIMISTIC:
+ return (T) new PessimisticNodeFactory();
+ default:
+ throw new ConfigurationException("Unknown locking scheme " + configuration.getNodeLockingScheme());
+ }
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/RuntimeConfigAwareFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/RuntimeConfigAwareFactory.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/factories/RuntimeConfigAwareFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -1,6 +1,5 @@
package org.jboss.cache.factories;
-import org.jboss.cache.NodeFactory;
import org.jboss.cache.RPCManager;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.RuntimeConfig;
@@ -15,7 +14,7 @@
* @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
* @since 2.1.0
*/
- at DefaultFactoryFor(classes = {RPCManager.class, NodeFactory.class})
+ at DefaultFactoryFor(classes = RPCManager.class)
public class RuntimeConfigAwareFactory extends EmptyConstructorFactory
{
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -125,7 +125,7 @@
if (!locked)
throw new TimeoutException("Unable to lock node " + node.getFqn() + " after timeout " + timeout + " for copying into workspace");
- WorkspaceNode wn = nodeFactory.createWorkspaceNode(node, workspace);
+ WorkspaceNode wn = nodeFactory.createWrappedNode(node, workspace);
lockManager.unlock(node, gtx);
return wn;
Added: core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -0,0 +1,77 @@
+package org.jboss.cache.mvcc;
+
+import org.jboss.cache.AbstractNodeFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InternalNode;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.UnversionedNode;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.lock.IsolationLevel;
+
+import java.util.Map;
+
+/**
+ * Creates nodes specific to MVCC logic.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public class MVCCNodeFactory<K, V> extends AbstractNodeFactory<K, V>
+{
+ private boolean useRepeatableRead;
+ private static final NullMarkerNode NULL_MARKER = new NullMarkerNode(null);
+
+ /**
+ * Initialises the node factory with the configuration from the cache.
+ */
+ @Start
+ public void init()
+ {
+ useRepeatableRead = configuration.getIsolationLevel() == IsolationLevel.REPEATABLE_READ;
+ }
+
+ /**
+ * Creates an MVCC wrapped node - either a {@link org.jboss.cache.mvcc.ReadCommittedNode} or it's subclass, a
+ * {@link org.jboss.cache.mvcc.RepeatableReadNode} based on cache configuration. If a null is passed in as the InternalNode,
+ * this method will return a special {@link org.jboss.cache.mvcc.NullMarkerNode} instance if using repeatable read,
+ * or a null if read committed.
+ *
+ * @param node internal node to wrap.
+ * @return a ReadCommittedNode
+ */
+ @Override
+ public ReadCommittedNode createWrappedNode(InternalNode<K, V> node)
+ {
+ if (node == null) return useRepeatableRead ? NULL_MARKER : null;
+ ReadCommittedNode rcn = useRepeatableRead ? new RepeatableReadNode(node) : new ReadCommittedNode(node);
+ rcn.initialize(configuration, invocationContextContainer, componentRegistry, interceptorChain);
+ rcn.injectDependencies(cache);
+ return rcn;
+ }
+
+ @Override
+ public NodeSPI<K, V> createNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
+ {
+ UnversionedNode<K, V> internal = new UnversionedNode<K, V>(childName, fqn, data, cache);
+ internal.injectDependencies(cache, commandsFactory, lockStrategyFactory, this);
+
+ // always assume that new nodes do not have data loaded
+ internal.setDataLoaded(false);
+ NodeSPI<K, V> nid = createNodeInvocationDelegate(internal, !useRepeatableRead);
+
+ // back reference
+ internal.setDelegate(nid);
+ return nid;
+ }
+
+ @Override
+ public NodeSPI<K, V> createNodeInvocationDelegate(InternalNode<K, V> internalNode, boolean wrapWithNodeReference)
+ {
+ if (wrapWithNodeReference && internalNode instanceof NodeReference)
+ throw new IllegalArgumentException("Cannot wrap a NodeReference with a NodeReference!");
+ if (wrapWithNodeReference && useRepeatableRead)
+ throw new IllegalArgumentException("Cannot use NodeReferences with RepeatableRead!");
+ if (wrapWithNodeReference) internalNode = new NodeReference<K, V>(internalNode);
+ return super.createNodeInvocationDelegate(internalNode, false);
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -66,8 +66,8 @@
* 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)}
+ * {@link InternalNode}s are wrapped using {@link org.jboss.cache.NodeFactory#createWrappedNode(org.jboss.cache.InternalNode)}
+ * and as such, null internal nodes are treated according to isolation level used. See {@link org.jboss.cache.NodeFactory#createWrappedNode(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
@@ -113,7 +113,7 @@
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);
+ ReadCommittedNode wrapped = nodeFactory.createWrappedNode(node);
if (wrapped != null) ctx.putLookedUpNode(f, wrapped);
return wrapped;
}
@@ -196,7 +196,7 @@
{
needToCopy = true;
}
- n = nodeFactory.createMvccNode(in);
+ n = nodeFactory.createWrappedNode(in);
context.putLookedUpNode(fqn, n);
if (needToCopy) n.markForUpdate(context, dataContainer, nodeFactory, allowWriteSkew);
}
@@ -221,7 +221,7 @@
parent.removeChildDirect(fqn.getLastElement());
in = ((NodeInvocationDelegate) temp).getDelegationTarget();
- n = nodeFactory.createMvccNode(in);
+ n = nodeFactory.createWrappedNode(in);
n.setCreated(true);
context.putLookedUpNode(fqn, n);
n.markForUpdate(context, dataContainer, nodeFactory, allowWriteSkew);
@@ -326,7 +326,7 @@
if (node == null)
{
InternalNode in = dataContainer.peekInternalNode(fqn, false);
- node = nodeFactory.createMvccNode(in);
+ node = nodeFactory.createWrappedNode(in);
ctx.putLookedUpNode(fqn, node);
}
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-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -28,11 +28,11 @@
* @since 3.0
*/
@ThreadSafe
-public class NodeReference implements InternalNode
+public class NodeReference<K, V> implements InternalNode<K, V>
{
- transient volatile InternalNode delegate;
+ transient volatile InternalNode<K, V> delegate;
- public NodeReference(InternalNode delegate)
+ public NodeReference(InternalNode<K, V> delegate)
{
this.delegate = delegate;
}
@@ -40,7 +40,7 @@
/**
* @return the InternalNode being delegated to.
*/
- public InternalNode getDelegate()
+ public InternalNode<K, V> getDelegate()
{
return delegate;
}
@@ -50,17 +50,17 @@
*
* @param delegate node to delegate to.
*/
- public void setDelegate(InternalNode delegate)
+ public void setDelegate(InternalNode<K, V> delegate)
{
this.delegate = delegate;
}
- public NodeSPI getParent()
+ public NodeSPI<K, V> getParent()
{
return delegate.getParent();
}
- public CacheSPI getCache()
+ public CacheSPI<K, V> getCache()
{
return delegate.getCache();
}
@@ -75,27 +75,27 @@
delegate.setChildrenLoaded(flag);
}
- public Object getDirect(Object key)
+ public V getDirect(K key)
{
return delegate.getDirect(key);
}
- public Map getDataDirect()
+ public Map<K, V> getDataDirect()
{
return delegate.getDataDirect();
}
- public Object putDirect(Object key, Object value)
+ public V putDirect(K key, V value)
{
return delegate.putDirect(key, value);
}
- public NodeSPI getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean notify)
+ public NodeSPI<K, V> getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean notify)
{
return delegate.getOrCreateChild(child_name, gtx, notify);
}
- public Object removeDirect(Object key)
+ public V removeDirect(K key)
{
return delegate.removeDirect(key);
}
@@ -105,17 +105,17 @@
delegate.addChildDirect(child);
}
- public NodeSPI addChildDirect(Fqn f)
+ public NodeSPI<K, V> addChildDirect(Fqn f)
{
return delegate.addChildDirect(f);
}
- public NodeSPI addChildDirect(Fqn f, boolean notify)
+ public NodeSPI<K, V> addChildDirect(Fqn f, boolean notify)
{
return delegate.addChildDirect(f, notify);
}
- public NodeSPI addChildDirect(Object o, boolean notify)
+ public NodeSPI<K, V> addChildDirect(Object o, boolean notify)
{
return delegate.addChildDirect(o, notify);
}
@@ -125,17 +125,17 @@
delegate.clearDataDirect();
}
- public NodeSPI getChildDirect(Fqn fqn)
+ public NodeSPI<K, V> getChildDirect(Fqn fqn)
{
return delegate.getChildDirect(fqn);
}
- public Set getChildrenNamesDirect()
+ public Set<Object> getChildrenNamesDirect()
{
return delegate.getChildrenNamesDirect();
}
- public Set getKeysDirect()
+ public Set<K> getKeysDirect()
{
return delegate.getKeysDirect();
}
@@ -150,22 +150,22 @@
return delegate.removeChildDirect(f);
}
- public Map getChildrenMapDirect()
+ public Map<Object, Node<K, V>> getChildrenMapDirect()
{
return delegate.getChildrenMapDirect();
}
- public Map getChildrenMapDirect(boolean b)
+ public Map<Object, Node<K, V>> getChildrenMapDirect(boolean b)
{
return delegate.getChildrenMapDirect(b);
}
- public void setChildrenMapDirect(Map children)
+ public void setChildrenMapDirect(Map<Object, Node<K, V>> children)
{
delegate.setChildrenMapDirect(children);
}
- public void putAllDirect(Map data)
+ public void putAllDirect(Map<K, V> data)
{
delegate.putAllDirect(data);
}
@@ -195,12 +195,12 @@
delegate.setFqn(fqn);
}
- public NodeSPI getChildDirect(Object childName)
+ public NodeSPI<K, V> getChildDirect(Object childName)
{
return delegate.getChildDirect(childName);
}
- public Set getChildrenDirect()
+ public Set<NodeSPI<K, V>> getChildrenDirect()
{
return delegate.getChildrenDirect();
}
@@ -210,7 +210,7 @@
return delegate.hasChildrenDirect();
}
- public Set getChildrenDirect(boolean includeMarkedForRemoval)
+ public Set<NodeSPI<K, V>> getChildrenDirect(boolean includeMarkedForRemoval)
{
return delegate.getChildrenDirect(includeMarkedForRemoval);
}
@@ -285,10 +285,10 @@
return delegate.isResident();
}
- public InternalNode copy()
+ public InternalNode<K, V> copy()
{
- InternalNode cloneDelegate = delegate.copy();
- return new NodeReference(cloneDelegate);
+ InternalNode<K, V> cloneDelegate = delegate.copy();
+ return new NodeReference<K, V>(cloneDelegate);
}
public NodeLock getLock()
@@ -296,7 +296,7 @@
return delegate.getLock();
}
- public void addChild(Object nodeName, Node nodeToAdd)
+ public void addChild(Object nodeName, Node<K, V> nodeToAdd)
{
delegate.addChild(nodeName, nodeToAdd);
}
Added: core/trunk/src/main/java/org/jboss/cache/optimistic/OptimisticNodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/OptimisticNodeFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/OptimisticNodeFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -0,0 +1,32 @@
+package org.jboss.cache.optimistic;
+
+import org.jboss.cache.AbstractNodeFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.UnversionedNode;
+import org.jboss.cache.VersionedNode;
+
+import java.util.Map;
+
+/**
+ * Node factory specific to optimistic locking.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public class OptimisticNodeFactory<K, V> extends AbstractNodeFactory<K, V>
+{
+ @Override
+ protected UnversionedNode<K, V> createInternalNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
+ {
+ VersionedNode<K, V> internal = new VersionedNode<K, V>(fqn, parent, data, cache);
+ internal.injectDependencies(cache, commandsFactory, lockStrategyFactory, this);
+ return internal;
+ }
+
+ @Override
+ public WorkspaceNode<K, V> createWrappedNode(NodeSPI<K, V> dataNode, TransactionWorkspace workspace)
+ {
+ return new WorkspaceNodeImpl<K, V>(dataNode, workspace, this);
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -46,11 +46,12 @@
private Set<Fqn> childrenAdded;
private Set<Fqn> childrenRemoved;
private Map<K, V> optimisticDataMap;
+ private NodeFactory<K, V> nodeFactory;
/**
* Constructs with a node and workspace.
*/
- public WorkspaceNodeImpl(NodeSPI<K, V> node, TransactionWorkspace workspace)
+ public WorkspaceNodeImpl(NodeSPI<K, V> node, TransactionWorkspace workspace, NodeFactory<K, V> nodeFactory)
{
NodeInvocationDelegate delegate = (NodeInvocationDelegate) node;
if (!(delegate.getDelegationTarget() instanceof VersionedNode))
@@ -68,6 +69,7 @@
}
initFlags();
+ this.nodeFactory = nodeFactory;
}
protected void initFlags()
@@ -229,15 +231,14 @@
}
@SuppressWarnings("unchecked")
- public NodeSPI<K, V> createChild(Object child_name, NodeSPI<K, V> parent, CacheSPI<K, V> cache, DataVersion version)
+ public NodeSPI<K, V> createChild(Object childName, NodeSPI<K, V> parent, CacheSPI<K, V> cache, DataVersion version)
{
- if (child_name == null)
+ if (childName == null)
{
return null;
}
- NodeFactory<K, V> factory = cache.getConfiguration().getRuntimeConfig().getNodeFactory();
- NodeSPI<K, V> child = (NodeSPI<K, V>) factory.createNodeOfType(parent, child_name, parent, null);
+ NodeSPI<K, V> child = nodeFactory.createNode(childName, Fqn.fromRelativeElements(parent.getFqn(), childName), parent, null, true);
getChildrenAddedSet().add(child.getFqn());
if (childrenRemoved != null) childrenRemoved.remove(child.getFqn());
setFlag(CHILDREN_MODIFIED_IN_WORKSPACE, true);
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -46,18 +46,13 @@
private NodeFactory factory;
- private NodeFactory.NodeType nodeType;
-
private Set<Fqn> internalFqns;
- public DefaultStateTransferIntegrator(Fqn targetFqn, CacheSPI<?, ?> cache)
+ public DefaultStateTransferIntegrator(Fqn targetFqn, CacheSPI<?, ?> cache, NodeFactory nodefactory)
{
this.targetFqn = targetFqn;
this.cache = cache;
- this.factory = cache.getConfiguration().getRuntimeConfig().getNodeFactory();
- this.nodeType = cache.getConfiguration().getNodeLockingScheme().isVersionedScheme()
- ? NodeFactory.NodeType.VERSIONED_NODE
- : NodeFactory.NodeType.UNVERSIONED_NODE;
+ this.factory = nodefactory;
this.internalFqns = cache.getInternalFqns();
}
@@ -71,7 +66,6 @@
protected void integrateTransientState(ObjectInputStream in, NodeSPI target) throws Exception
{
boolean transientSet = false;
-// ClassLoader oldCL = setClassLoader(cl);
try
{
if (log.isTraceEnabled())
@@ -180,11 +174,6 @@
return factory;
}
- protected NodeFactory.NodeType getNodeType()
- {
- return nodeType;
- }
-
protected Fqn getTargetFqn()
{
return targetFqn;
@@ -321,7 +310,7 @@
// We handle this NodeData. Create a TreeNode and
// integrate its data
- NodeSPI target = factory.createDataNode(name, fqn, parent, attrs, false);
+ NodeSPI target = factory.createNode(name, fqn, parent, attrs, false);
parent.addChild(name, target);
// JBCACHE-913
@@ -417,7 +406,7 @@
// Missing level -- have to create empty node
// This shouldn't really happen -- internal fqns should
// be immediately under the root
- child = factory.createDataNode(name, Fqn.fromRelativeElements(ancFqn, name), ancestor, null, true);
+ child = factory.createNode(name, Fqn.fromRelativeElements(ancFqn, name), ancestor, null, true);
ancestor.addChild(name, child);
}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -11,6 +11,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.RegionEmptyException;
import org.jboss.cache.RegionManager;
@@ -45,16 +46,18 @@
private boolean fetchTransientState;
private boolean fetchPersistentState;
private long stateRetrievalTimeout;
+ private NodeFactory nodeFactory;
@Inject
- public void injectDependencies(CacheSPI cache, Marshaller marshaller, RegionManager regionManager, Configuration configuration, CacheLoaderManager cacheLoaderManager)
+ public void injectDependencies(CacheSPI cache, Marshaller marshaller, RegionManager regionManager, Configuration configuration, CacheLoaderManager cacheLoaderManager, NodeFactory nodeFactory)
{
this.cache = cache;
this.regionManager = regionManager;
this.marshaller = marshaller;
this.configuration = configuration;
this.cacheLoaderManager = cacheLoaderManager;
+ this.nodeFactory = nodeFactory;
}
@Start(priority = 19)
@@ -226,6 +229,6 @@
protected StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream istream, Fqn fqn) throws Exception
{
- return StateTransferFactory.getStateTransferIntegrator(istream, fqn, cache);
+ return StateTransferFactory.getStateTransferIntegrator(istream, fqn, cache, nodeFactory);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferFactory.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferFactory.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -8,6 +8,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeFactory;
import org.jboss.cache.Version;
import java.io.IOException;
@@ -43,7 +44,7 @@
return new DefaultStateTransferGenerator(cache); // current default
}
- public static StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream in, Fqn fqn, CacheSPI cache)
+ public static StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream in, Fqn fqn, CacheSPI cache, NodeFactory nodeFactory)
throws Exception
{
short version;
@@ -69,6 +70,6 @@
if (version < RV_200 && version > 0) // <= 0 is actually a version > 15.31.63
throw new IllegalStateException("State transfer with cache replication version < 2.0.0 not supported");
else
- return new DefaultStateTransferIntegrator(fqn, cache); // current default
+ return new DefaultStateTransferIntegrator(fqn, cache, nodeFactory); // current default
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/lock/AbstractLockManagerRecordingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/AbstractLockManagerRecordingTest.java 2008-07-14 12:55:41 UTC (rev 6255)
+++ core/trunk/src/test/java/org/jboss/cache/lock/AbstractLockManagerRecordingTest.java 2008-07-14 14:39:46 UTC (rev 6256)
@@ -67,7 +67,7 @@
protected NodeSPI createNode(Fqn fqn)
{
UnversionedNode un = new UnversionedNode(fqn);
- un.injectDependencies(null, null, new LockStrategyFactory());
+ un.injectDependencies(null, null, new LockStrategyFactory(), null);
return new NodeInvocationDelegate(un);
}
}
More information about the jbosscache-commits
mailing list