jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1242926 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: model/ store/
Date Fri, 10 Feb 2012 21:14:58 GMT
Author: stefan
Date: Fri Feb 10 21:14:57 2012
New Revision: 1242926

URL: http://svn.apache.org/viewvc?rev=1242926&view=rev
Log:
binary serialization of child node ids

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesMap.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java?rev=1242926&r1=1242925&r2=1242926&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
Fri Feb 10 21:14:57 2012
@@ -210,12 +210,21 @@ public abstract class AbstractNode imple
     }
 
     public void serialize(Binding binding) throws Exception {
-        binding.write(":props", properties.size(),
-                new AbstractRangeIterator<Binding.KeyValuePair>(properties.keySet().iterator(),
0, -1) {
+        final Iterator<Map.Entry<String, String>> iter = properties.entrySet().iterator();
+        binding.writeMap(":props", properties.size(),
+                new Binding.StringEntryIterator() {
                     @Override
-                    protected Binding.KeyValuePair doNext() {
-                        String key = (String) it.next();
-                        return new Binding.KeyValuePair(key, properties.get(key));
+                    public boolean hasNext() {
+                        return iter.hasNext();
+                    }
+                    @Override
+                    public Binding.StringEntry next() {
+                        Map.Entry<String, String> entry = iter.next();
+                        return new Binding.StringEntry(entry.getKey(), entry.getValue());
+                    }
+                    @Override
+                    public void remove() {
+                        throw new UnsupportedOperationException();
                     }
                 });
         binding.write(":inlined", childEntries.inlined() ? 1 : 0);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesMap.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesMap.java?rev=1242926&r1=1242925&r2=1242926&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesMap.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesMap.java
Fri Feb 10 21:14:57 2012
@@ -17,11 +17,10 @@
 package org.apache.jackrabbit.mk.model;
 
 import org.apache.jackrabbit.mk.store.Binding;
-import org.apache.jackrabbit.mk.store.RevisionProvider;
 import org.apache.jackrabbit.mk.util.AbstractFilteringIterator;
-import org.apache.jackrabbit.mk.util.AbstractRangeIterator;
 import org.apache.jackrabbit.mk.util.EmptyIterator;
 import org.apache.jackrabbit.mk.util.RangeIterator;
+import org.apache.jackrabbit.mk.util.StringUtils;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -271,12 +270,21 @@ public class ChildNodeEntriesMap impleme
     @Override
     public void serialize(Binding binding) throws Exception {
         binding.write(":ordered", insertionOrdered ? 1 : 0);
-        binding.write(":children", getCount(),
-                new AbstractRangeIterator<Binding.KeyValuePair>(getEntries(0, -1),
0, -1) {
+        final Iterator<ChildNodeEntry> iter = getEntries(0, -1);
+        binding.writeMap(":children", getCount(),
+                new Binding.BytesEntryIterator() {
                     @Override
-                    protected Binding.KeyValuePair doNext() {
-                        ChildNodeEntry cne = (ChildNodeEntry) it.next();
-                        return new Binding.KeyValuePair(cne.getName(), cne.getId());
+                    public boolean hasNext() {
+                        return iter.hasNext();
+                    }
+                    @Override
+                    public Binding.BytesEntry next() {
+                        ChildNodeEntry cne = iter.next();
+                        return new Binding.BytesEntry(cne.getName(), StringUtils.convertHexToBytes(cne.getId()));
+                    }
+                    @Override
+                    public void remove() {
+                        throw new UnsupportedOperationException();
                     }
                 });
     }
@@ -284,10 +292,10 @@ public class ChildNodeEntriesMap impleme
     public static ChildNodeEntriesMap deserialize(Binding binding) throws Exception {
         boolean insertionOrdered = binding.readIntValue(":ordered") == 0 ? false : true;
         ChildNodeEntriesMap newInstance = new ChildNodeEntriesMap(insertionOrdered);
-        Iterator<Binding.KeyValuePair> iter = binding.read(":children");
+        Binding.BytesEntryIterator iter = binding.readBytesMap(":children");
         while (iter.hasNext()) {
-            Binding.KeyValuePair kvp = iter.next();
-            newInstance.add(new ChildNodeEntry(kvp.getKey(), kvp.getValue()));
+            Binding.BytesEntry entry = iter.next();
+            newInstance.add(new ChildNodeEntry(entry.getKey(), StringUtils.convertBytesToHex(entry.getValue())));
         }
         return newInstance;
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java?rev=1242926&r1=1242925&r2=1242926&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
Fri Feb 10 21:14:57 2012
@@ -552,16 +552,16 @@ public class ChildNodeEntriesTree implem
 
     public void serialize(Binding binding) throws Exception {
         binding.write(":count", count);
-        binding.write(":index", index.length, new Iterator<Binding.KeyValuePair>()
{
+        binding.writeMap(":index", index.length, new Binding.StringEntryIterator() {
             int pos = -1;
-            
+
             @Override
             public boolean hasNext() {
                 return pos < index.length - 1;
             }
 
             @Override
-            public Binding.KeyValuePair next() {
+            public Binding.StringEntry next() {
                 pos++;
                 if (pos >= index.length) {
                     throw new NoSuchElementException();
@@ -570,15 +570,15 @@ public class ChildNodeEntriesTree implem
                 IndexEntry entry = index[pos];
                 if (entry == null) {
                     // null entry: ""
-                    return new Binding.KeyValuePair(Integer.toString(pos), "");
+                    return new Binding.StringEntry(Integer.toString(pos), "");
                 } else if (entry instanceof NodeInfo) {
                     NodeInfo ni = (NodeInfo) entry;
                     // "n<id>:<name>"
-                    return new Binding.KeyValuePair(Integer.toString(pos), "n" + ni.getId()
+ ":" + ni.getName());
+                    return new Binding.StringEntry(Integer.toString(pos), "n" + ni.getId()
+ ":" + ni.getName());
                 } else {
                     BucketInfo bi = (BucketInfo) entry;
                     // "b<id>:<count>"
-                    return new Binding.KeyValuePair(Integer.toString(pos), "b" + bi.getId()
+ ":" + bi.getSize());
+                    return new Binding.StringEntry(Integer.toString(pos), "b" + bi.getId()
+ ":" + bi.getSize());
                 }
             }
 
@@ -592,26 +592,26 @@ public class ChildNodeEntriesTree implem
     static ChildNodeEntriesTree deserialize(RevisionProvider provider, Binding binding) throws
Exception {
         ChildNodeEntriesTree newInstance = new ChildNodeEntriesTree(provider);
         newInstance.count = binding.readIntValue(":count");
-        Iterator<Binding.KeyValuePair> iter = binding.read(":index");
+        Binding.StringEntryIterator iter = binding.readStringMap(":index");
         int pos = -1;
         while (iter.hasNext()) {
-            Binding.KeyValuePair kvp = iter.next();
+            Binding.StringEntry entry = iter.next();
             ++pos;
             // deserialize index array entry
-            assert(pos == Integer.parseInt(kvp.getKey()));
-            if (kvp.getValue().length() == 0) {
+            assert(pos == Integer.parseInt(entry.getKey()));
+            if (entry.getValue().length() == 0) {
                 // ""
                 newInstance.index[pos] = null;
-            } else if (kvp.getValue().charAt(0) == 'n') {
+            } else if (entry.getValue().charAt(0) == 'n') {
                 // "n<id>:<name>"
-                String value = kvp.getValue().substring(1);
+                String value = entry.getValue().substring(1);
                 int i = value.indexOf(':');
                 String id = value.substring(0, i);
                 String name = value.substring(i + 1);
                 newInstance.index[pos] = new NodeInfo(name, id);
             } else {
                 // "b<id>:<count>"
-                String value = kvp.getValue().substring(1);
+                String value = entry.getValue().substring(1);
                 int i = value.indexOf(':');
                 String id = value.substring(0, i);
                 int count = Integer.parseInt(value.substring(i + 1));

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java?rev=1242926&r1=1242925&r2=1242926&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
Fri Feb 10 21:14:57 2012
@@ -34,10 +34,10 @@ public class StoredNode extends Abstract
 
     public static StoredNode deserialize(String id, RevisionProvider provider, Binding binding)
throws Exception {
         StoredNode newInstance = new StoredNode(id, provider);
-        Iterator<Binding.KeyValuePair> iter = binding.read(":props");
+        Binding.StringEntryIterator iter = binding.readStringMap(":props");
         while (iter.hasNext()) {
-            Binding.KeyValuePair kvp = iter.next();
-            newInstance.properties.put(kvp.getKey(), kvp.getValue());
+            Binding.StringEntry entry = iter.next();
+            newInstance.properties.put(entry.getKey(), entry.getValue());
         }
         boolean inlined = binding.readIntValue(":inlined") != 0;
         if (inlined) {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java?rev=1242926&r1=1242925&r2=1242926&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
Fri Feb 10 21:14:57 2012
@@ -76,15 +76,28 @@ public class BinaryBinding implements Bi
     }
 
     @Override
-    public void write(String key, int count, Iterator<KeyValuePair> iterator) throws
Exception {
+    public void writeMap(String key, int count, StringEntryIterator iterator) throws Exception
{
         if (out == null) {
             throw new IllegalStateException("no OutputStream provided");
         }
         IOUtils.writeVarInt(out, count);
         while (iterator.hasNext()) {
-            KeyValuePair kvp = iterator.next();
-            IOUtils.writeString(out, kvp.getKey());
-            IOUtils.writeString(out, kvp.getValue());
+            StringEntry entry = iterator.next();
+            IOUtils.writeString(out, entry.getKey());
+            IOUtils.writeString(out, entry.getValue());
+        }
+    }
+
+    @Override
+    public void writeMap(String key, int count, BytesEntryIterator iterator) throws Exception
{
+        if (out == null) {
+            throw new IllegalStateException("no OutputStream provided");
+        }
+        IOUtils.writeVarInt(out, count);
+        while (iterator.hasNext()) {
+            BytesEntry entry = iterator.next();
+            IOUtils.writeString(out, entry.getKey());
+            IOUtils.writeBytes(out, entry.getValue());
         }
     }
 
@@ -121,24 +134,24 @@ public class BinaryBinding implements Bi
     }
 
     @Override
-    public Iterator<KeyValuePair> read(String key) throws Exception {
+    public StringEntryIterator readStringMap(String key) throws Exception {
         if (in == null) {
             throw new IllegalStateException("no InputStream provided");
         }
         final int size = IOUtils.readVarInt(in);
-        return new Iterator<KeyValuePair>() {
+        return new StringEntryIterator() {
             int count = size;
 
             public boolean hasNext() {
                 return count > 0;
             }
 
-            public KeyValuePair next() {
+            public StringEntry next() {
                 if (count-- > 0) {
                     try {
                         String key = IOUtils.readString(in);
                         String value = IOUtils.readString(in);
-                        return new KeyValuePair(key, value);
+                        return new StringEntry(key, value);
                     } catch (IOException e) {
                         throw new RuntimeException("deserialization failed", e);        
              
                     }
@@ -151,4 +164,36 @@ public class BinaryBinding implements Bi
             }
         };
     }
+
+    @Override
+    public BytesEntryIterator readBytesMap(String key) throws Exception {
+        if (in == null) {
+            throw new IllegalStateException("no InputStream provided");
+        }
+        final int size = IOUtils.readVarInt(in);
+        return new BytesEntryIterator() {
+            int count = size;
+
+            public boolean hasNext() {
+                return count > 0;
+            }
+
+            public BytesEntry next() {
+                if (count-- > 0) {
+                    try {
+                        String key = IOUtils.readString(in);
+                        byte[] value = IOUtils.readBytes(in);
+                        return new BytesEntry(key, value);
+                    } catch (IOException e) {
+                        throw new RuntimeException("deserialization failed", e);
+                    }
+                }
+                throw new NoSuchElementException();
+            }
+
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+        };
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java?rev=1242926&r1=1242925&r2=1242926&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
Fri Feb 10 21:14:57 2012
@@ -27,19 +27,21 @@ public interface Binding {
     void write(String key, byte[] value) throws Exception;
     void write(String key, long value) throws Exception;
     void write(String key, int value) throws Exception;
-    void write(String key, int count, Iterator<KeyValuePair> iterator) throws Exception;
-    
+    void writeMap(String key, int count, StringEntryIterator iterator) throws Exception;
+    void writeMap(String key, int count, BytesEntryIterator iterator) throws Exception;
+
     String readStringValue(String key) throws Exception;
     byte[] readBytesValue(String key) throws Exception;
     long readLongValue(String key) throws Exception;
     int readIntValue(String key) throws Exception;
-    Iterator<KeyValuePair> read(String key) throws Exception;
-    
-    static class KeyValuePair {
+    StringEntryIterator readStringMap(String key) throws Exception;
+    BytesEntryIterator readBytesMap(String key) throws Exception;
+
+    static abstract class Entry<V> {
         String key;
-        String value;
-        
-        public KeyValuePair(String key, String value) {
+        V value;
+
+        public Entry(String key, V value) {
             this.key = key;
             this.value = value;
         }
@@ -48,8 +50,36 @@ public interface Binding {
             return key;
         }
 
+        public V getValue() {
+            return value;
+        }
+    }
+
+    static class StringEntry extends Entry<String> {
+
+        public StringEntry(String key, String value) {
+            super(key, value);
+        }
+
         public String getValue() {
             return value;
         }
     }
+
+    static class BytesEntry extends Entry<byte[]> {
+
+        public BytesEntry(String key, byte[] value) {
+            super(key, value);
+        }
+
+        public byte[] getValue() {
+            return value;
+        }
+    }
+
+    static interface StringEntryIterator extends Iterator<StringEntry> {
+    }
+
+    static interface BytesEntryIterator extends Iterator<BytesEntry> {
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java?rev=1242926&r1=1242925&r2=1242926&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
Fri Feb 10 21:14:57 2012
@@ -380,11 +380,21 @@ public class MongoPersistenceManager ext
         }
 
         @Override
-        public void write(String key, int count, Iterator<KeyValuePair> iterator) throws
Exception {
+        public void writeMap(String key, int count, StringEntryIterator iterator) throws
Exception {
             BasicDBObject childObj = new BasicDBObject();
             while (iterator.hasNext()) {
-                KeyValuePair kvp = iterator.next();
-                childObj.append(encodeName(kvp.getKey()), kvp.getValue());
+                StringEntry entry = iterator.next();
+                childObj.append(encodeName(entry.getKey()), entry.getValue());
+            }
+            obj.append(encodeName(key), childObj);
+        }
+
+        @Override
+        public void writeMap(String key, int count, BytesEntryIterator iterator) throws Exception
{
+            BasicDBObject childObj = new BasicDBObject();
+            while (iterator.hasNext()) {
+                BytesEntry entry = iterator.next();
+                childObj.append(encodeName(entry.getKey()), StringUtils.convertBytesToHex(entry.getValue()));
             }
             obj.append(encodeName(key), childObj);
         }
@@ -410,19 +420,19 @@ public class MongoPersistenceManager ext
         }
 
         @Override
-        public Iterator<KeyValuePair> read(String key) throws Exception {
+        public StringEntryIterator readStringMap(String key) throws Exception {
             final BasicDBObject childObj = (BasicDBObject) obj.get(encodeName(key));
             final Iterator<String> it = childObj.keySet().iterator();
-            return new Iterator<KeyValuePair>() {
+            return new StringEntryIterator() {
                 @Override
                 public boolean hasNext() {
                     return it.hasNext();
                 }
 
                 @Override
-                public KeyValuePair next() {
+                public StringEntry next() {
                     String key = it.next();
-                    return new KeyValuePair(decodeName(key), childObj.getString(key));
+                    return new StringEntry(decodeName(key), childObj.getString(key));
                 }
 
                 @Override
@@ -431,6 +441,30 @@ public class MongoPersistenceManager ext
                 }
             };
         }
-    }
 
+        @Override
+        public BytesEntryIterator readBytesMap(String key) throws Exception {
+            final BasicDBObject childObj = (BasicDBObject) obj.get(encodeName(key));
+            final Iterator<String> it = childObj.keySet().iterator();
+            return new BytesEntryIterator() {
+                @Override
+                public boolean hasNext() {
+                    return it.hasNext();
+                }
+
+                @Override
+                public BytesEntry next() {
+                    String key = it.next();
+                    return new BytesEntry(
+                            decodeName(key),
+                            StringUtils.convertHexToBytes(childObj.getString(key)));
+                }
+
+                @Override
+                public void remove() {
+                    throw new UnsupportedOperationException();
+                }
+            };
+        }
+    }
 }



Mime
View raw message