jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1299695 - in /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit: state/TransientNodeState.java utils/BatchIterator.java utils/PagedIterator.java
Date Mon, 12 Mar 2012 14:52:36 GMT
Author: mduerig
Date: Mon Mar 12 14:52:35 2012
New Revision: 1299695

URL: http://svn.apache.org/viewvc?rev=1299695&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- renaming, comment 

Added:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/PagedIterator.java
      - copied, changed from r1299680, jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/BatchIterator.java
Removed:
    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

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=1299695&r1=1299694&r2=1299695&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
Mon Mar 12 14:52:35 2012
@@ -27,7 +27,7 @@ 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.PagedIterator;
 import org.apache.jackrabbit.utils.Function1;
 import org.apache.jackrabbit.utils.Predicate;
 
@@ -103,9 +103,9 @@ public class TransientNodeState {
 
     public Iterator<TransientNodeState> getNodes() {
         Iterator<? extends ChildNodeEntry> persistedEntries = flatten(
-            new BatchIterator<ChildNodeEntry>(BATCH_SIZE) {
+            new PagedIterator<ChildNodeEntry>(BATCH_SIZE) {
                 @Override
-                protected Iterator<? extends ChildNodeEntry> getBatch(long pos, long
size) {
+                protected Iterator<? extends ChildNodeEntry> getPage(long pos, long
size) {
                     return getPersistentNodeState().getChildNodeEntries(pos, size).iterator();
                 }
         });

Copied: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/PagedIterator.java
(from r1299680, 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/PagedIterator.java?p2=jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/PagedIterator.java&p1=jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/BatchIterator.java&r1=1299680&r2=1299695&rev=1299695&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/BatchIterator.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/PagedIterator.java
Mon Mar 12 14:52:35 2012
@@ -3,22 +3,37 @@ 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;
+/**
+ * A {@code PagedIterator} is an iterator of several pages. A page itself is
+ * an iterator. The abstract {@code getPage} method is called whenever this
+ * iterator needs to fetch another page.<p/>
+ *
+ * Lazy flattening (e.g. with {@link org.apache.jackrabbit.utils.Iterators#flatten(java.util.Iterator)}
+ * results in an iterator which does batch reading from its back end.
+ *
+ * @param <T>
+ */
+public abstract class PagedIterator<T> implements Iterator<Iterator<? extends
T>> {
+    private final long pageSize;
     private long pos;
     private Iterator<? extends T> current;
 
-    protected BatchIterator(long batchSize) {
-        this.batchSize = batchSize;
+    protected PagedIterator(long pageSize) {
+        this.pageSize = pageSize;
     }
 
-    protected abstract Iterator<? extends T> getBatch(long pos, long size);
+    /**
+     * @param pos  start index
+     * @param size  maximal number of elements
+     * @return  iterator starting at index {@code pos} containing at most {@code size} elements.
+     */
+    protected abstract Iterator<? extends T> getPage(long pos, long size);
 
     @Override
     public boolean hasNext() {
         if (current == null) {
-            current = getBatch(pos, batchSize);
-            pos += batchSize;
+            current = getPage(pos, pageSize);
+            pos += pageSize;
         }
 
         return current.hasNext();



Mime
View raw message