jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1363687 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: kernel/KernelNodeStore.java plugins/memory/MemoryNodeStateBuilder.java plugins/memory/MemoryNodeStore.java
Date Fri, 20 Jul 2012 09:08:20 GMT
Author: jukka
Date: Fri Jul 20 09:08:19 2012
New Revision: 1363687

URL: http://svn.apache.org/viewvc?rev=1363687&view=rev
Log:
OAK-167: Caching NodeStore implementation

Complete the MemoryNodeStore class

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1363687&r1=1363686&r2=1363687&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Fri Jul 20 09:08:19 2012
@@ -20,18 +20,20 @@ import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
-import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStateBuilder;
 import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
 import org.apache.jackrabbit.oak.spi.commit.EmptyEditor;
 import org.apache.jackrabbit.oak.spi.commit.EmptyObserver;
 import org.apache.jackrabbit.oak.spi.commit.Observer;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
 /**
  * {@code NodeStore} implementations against {@link MicroKernel}.
  */
-public class KernelNodeStore extends MemoryNodeStore {
+public class KernelNodeStore implements NodeStore {
 
     /**
      * The {@link MicroKernel} instance used to store the content tree.
@@ -98,6 +100,11 @@ public class KernelNodeStore extends Mem
     }
 
     @Override
+    public NodeStateBuilder getBuilder(NodeState base) {
+        return new MemoryNodeStateBuilder(base);
+    }
+
+    @Override
     public CoreValueFactory getValueFactory() {
         return new CoreValueFactoryImpl(kernel);
     }
@@ -113,4 +120,5 @@ public class KernelNodeStore extends Mem
     CommitEditor getCommitEditor() {
         return editor;
     }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java?rev=1363687&r1=1363686&r2=1363687&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
Fri Jul 20 09:08:19 2012
@@ -29,7 +29,7 @@ import java.util.Map;
 /**
  * Basic in-memory node state builder.
  */
-class MemoryNodeStateBuilder implements NodeStateBuilder {
+public class MemoryNodeStateBuilder implements NodeStateBuilder {
 
     private final NodeState base;
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java?rev=1363687&r1=1363686&r2=1363687&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
Fri Jul 20 09:08:19 2012
@@ -16,15 +16,28 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
 /**
- * Abstract node store base class with in-memory node state builder
- * functionality.
+ * Basic in-memory node store implementation. Useful as a base class for
+ * more complex functionality.
  */
-public abstract class MemoryNodeStore implements NodeStore {
+public class MemoryNodeStore implements NodeStore {
+
+    private final AtomicReference<NodeState> root =
+            new AtomicReference<NodeState>(MemoryNodeState.EMPTY_NODE);
+
+    @Override
+    public NodeState getRoot() {
+        return root.get();
+    }
 
     @Override
     public NodeStateBuilder getBuilder(NodeState base) {
@@ -34,4 +47,61 @@ public abstract class MemoryNodeStore im
         return new MemoryNodeStateBuilder(base);
     }
 
+    @Override
+    public NodeStoreBranch branch() {
+        return new MemoryNodeStoreBranch(root.get());
+    }
+
+    @Override
+    public CoreValueFactory getValueFactory() {
+        return MemoryValueFactory.INSTANCE;
+    }
+
+    private class MemoryNodeStoreBranch implements NodeStoreBranch {
+
+        private final NodeState base;
+
+        private volatile NodeState root;
+
+        public MemoryNodeStoreBranch(NodeState base) {
+            this.base = base;
+            this.root = base;
+        }
+
+        @Override
+        public NodeState getBase() {
+            return base;
+        }
+
+        @Override
+        public NodeState getRoot() {
+            return root;
+        }
+
+        @Override
+        public void setRoot(NodeState newRoot) {
+            this.root = newRoot;
+        }
+
+        @Override
+        public NodeState merge() throws CommitFailedException {
+            while (!MemoryNodeStore.this.root.compareAndSet(base, root)) {
+                // TODO: rebase();
+                throw new UnsupportedOperationException();
+            }
+            return root;
+        }
+
+        @Override
+        public boolean copy(String source, String target) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public boolean move(String source, String target) {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+
 }



Mime
View raw message