jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1299476 - in /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit: state/TransientNodeState.java utils/BatchIterator.java utils/Iterators.java
Date Sun, 11 Mar 2012 22:45:22 GMT
Author: mduerig
Date: Sun Mar 11 22:45:22 2012
New Revision: 1299476

URL: http://svn.apache.org/viewvc?rev=1299476&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- batch reading from microkernel 

Added:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/BatchIterator.java
Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Iterators.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java?rev=1299476&r1=1299475&r2=1299476&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
Sun Mar 11 22:45:22 2012
@@ -28,8 +28,8 @@ import org.apache.jackrabbit.oak.model.C
 import org.apache.jackrabbit.oak.model.NodeState;
 import org.apache.jackrabbit.oak.model.PropertyState;
 import org.apache.jackrabbit.state.ChangeTree.NodeDelta;
+import org.apache.jackrabbit.utils.BatchIterator;
 import org.apache.jackrabbit.utils.Function1;
-import org.apache.jackrabbit.utils.Iterators;
 import org.apache.jackrabbit.utils.Predicate;
 
 import javax.jcr.ItemExistsException;
@@ -37,7 +37,14 @@ import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
 import java.util.Iterator;
 
+import static org.apache.jackrabbit.utils.Iterators.filter;
+import static org.apache.jackrabbit.utils.Iterators.flatten;
+import static org.apache.jackrabbit.utils.Iterators.chain;
+import static org.apache.jackrabbit.utils.Iterators.map;
+
 public class TransientNodeState {
+    private static final long BATCH_SIZE = 256;
+
     private final Context sessionContext;
 
     private String revision;
@@ -95,12 +102,17 @@ public class TransientNodeState {
     }
 
     public Iterator<TransientNodeState> getChildNodeStates() {
-        // todo implement paging
-        Iterable<? extends ChildNodeEntry> persistedEntries = getPersistentNodeState().getChildNodeEntries(0,
Long.MAX_VALUE);
+        BatchIterator<ChildNodeEntry> persistedEntries = new BatchIterator<ChildNodeEntry>(BATCH_SIZE)
{
+            @Override
+            protected Iterator<? extends ChildNodeEntry> getBatch(long pos, long size)
{
+                return getPersistentNodeState().getChildNodeEntries(pos, size).iterator();
+            }
+        };
+
         final NodeDelta delta = getNodeDelta();
 
         // fixme: this is not safe against concurrent modifications. Either copy delta or
make NodeDelta immutable
-        Iterator<ChildNodeEntry> unmodifiedEntries = Iterators.filter(persistedEntries.iterator(),
+        Iterator<ChildNodeEntry> unmodifiedEntries = filter(flatten(persistedEntries),
                 new Predicate<ChildNodeEntry>() {
                     @Override
                     public boolean evaluate(ChildNodeEntry entry) {
@@ -108,7 +120,7 @@ public class TransientNodeState {
                     }
                 });
         
-        Iterator<TransientNodeState> unmodifiedStates = Iterators.map(unmodifiedEntries,
+        Iterator<TransientNodeState> unmodifiedStates = map(unmodifiedEntries,
                 new Function1<ChildNodeEntry, TransientNodeState>() {
                     @Override
                     public TransientNodeState apply(ChildNodeEntry entry) {
@@ -116,7 +128,7 @@ public class TransientNodeState {
                     }
                 });
 
-        Iterator<TransientNodeState> modifiedStates = Iterators.map(delta.getNodes(),
+        Iterator<TransientNodeState> modifiedStates = map(delta.getNodes(),
                 new Function1<NodeDelta, TransientNodeState>() {
                     @Override
                     public TransientNodeState apply(NodeDelta delta) {
@@ -124,11 +136,11 @@ public class TransientNodeState {
                     }
                 });
 
-        return Iterators.iteratorChain(unmodifiedStates, modifiedStates);
+        return chain(unmodifiedStates, modifiedStates);
     }
 
     public Iterator<TransientNodeState> getChildNodeStates(Predicate<TransientNodeState>
condition) {
-        return Iterators.filter(getChildNodeStates(), condition);
+        return filter(getChildNodeStates(), condition);
     }
 
     public boolean hasProperties() {
@@ -141,7 +153,7 @@ public class TransientNodeState {
 
         // fixme: this is not safe against concurrent modifications. Either copy delta or
make NodeDelta immutable
         Iterator<PropertyState> propertyEntries =
-            Iterators.filter(propertyStates.iterator(),
+            filter(propertyStates.iterator(),
                     new Predicate<PropertyState>() {
                         @Override
                         public boolean evaluate(PropertyState state) {
@@ -149,11 +161,11 @@ public class TransientNodeState {
                         }
                     });
 
-        return Iterators.iteratorChain(propertyEntries, delta.getPropertyStates());
+        return chain(propertyEntries, delta.getPropertyStates());
     }
 
     public Iterator<PropertyState> getProperties(Predicate<PropertyState> condition)
{
-        return Iterators.filter(getProperties(), condition);
+        return filter(getProperties(), condition);
     }
 
     public JsonValue getPropertyValue(String name) throws ItemNotFoundException {

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/BatchIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/BatchIterator.java?rev=1299476&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/BatchIterator.java
(added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/BatchIterator.java
Sun Mar 11 22:45:22 2012
@@ -0,0 +1,41 @@
+package org.apache.jackrabbit.utils;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+public abstract class BatchIterator<T> implements Iterator<Iterator<? extends
T>> {
+    private final long batchSize;
+    private long pos;
+    private Iterator<? extends T> current;
+
+    protected BatchIterator(long batchSize) {
+        this.batchSize = batchSize;
+    }
+
+    protected abstract Iterator<? extends T> getBatch(long pos, long size);
+
+    @Override
+    public boolean hasNext() {
+        if (current == null) {
+            current = getBatch(pos, batchSize);
+            pos += batchSize;
+        }
+
+        return current.hasNext();
+    }
+
+    @Override
+    public Iterator<? extends T> next() {
+        if (!hasNext()) {
+            throw new NoSuchElementException();
+        }
+        Iterator<? extends T> e = current;
+        current = null;
+        return e;
+    }
+
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException("remove");
+    }
+}

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Iterators.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Iterators.java?rev=1299476&r1=1299475&r2=1299476&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Iterators.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Iterators.java
Sun Mar 11 22:45:22 2012
@@ -69,7 +69,7 @@ public final class Iterators {
      * @return
      */
     @SuppressWarnings("unchecked")
-    public static <T> Iterator<T> iteratorChain(Iterator<? extends T> iterator1,
Iterator<? extends T> iterator2) {
+    public static <T> Iterator<T> chain(Iterator<? extends T> iterator1,
Iterator<? extends T> iterator2) {
         return new IteratorChain(iterator1, iterator2);
     }
 



Mime
View raw message