jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1293282 - in /jackrabbit/sandbox/microkernel: ./ src/main/java/org/apache/jackrabbit/mk/ src/main/java/org/apache/jackrabbit/mk/store/
Date Fri, 24 Feb 2012 15:03:23 GMT
Author: dpfister
Date: Fri Feb 24 15:03:23 2012
New Revision: 1293282

URL: http://svn.apache.org/viewvc?rev=1293282&view=rev
Log:
Separate RevisionStore from AbstractPersistenceManager
- provide separate PersistenceManager interface
- provide caching in DefaultRevisionStore
- use BlobStore interface instead of blob methods in PersistenceManager

Added:
    jackrabbit/sandbox/microkernel/:hash.zip   (with props)
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java   (with props)
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java   (with props)
    jackrabbit/sandbox/microkernel/wstest.html   (with props)
Removed:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java

Added: jackrabbit/sandbox/microkernel/:hash.zip
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/%3Ahash.zip?rev=1293282&view=auto
==============================================================================
Binary file - no diff available.

Propchange: jackrabbit/sandbox/microkernel/:hash.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1293282&r1=1293281&r2=1293282&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java Fri Feb 24 15:03:23 2012
@@ -24,12 +24,7 @@ import org.apache.jackrabbit.mk.model.Co
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
 import org.apache.jackrabbit.mk.model.StoredNode;
-import org.apache.jackrabbit.mk.store.AbstractPersistenceManager;
-import org.apache.jackrabbit.mk.store.BDbPersistenceManager;
-import org.apache.jackrabbit.mk.store.FSPersistenceManager;
-import org.apache.jackrabbit.mk.store.H2PersistenceManager;
-import org.apache.jackrabbit.mk.store.InMemPersistenceManager;
-import org.apache.jackrabbit.mk.store.MongoPersistenceManager;
+import org.apache.jackrabbit.mk.store.DefaultRevisionStore;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 import org.apache.jackrabbit.mk.store.RevisionStore;
 import org.apache.jackrabbit.mk.util.PathUtils;
@@ -42,7 +37,7 @@ public class Repository {
     final String homeDir;
     boolean initialized;
 
-    final AbstractPersistenceManager pm;
+    private final DefaultRevisionStore rs;
 
     public Repository(String homeDir) throws Exception {
         File home = new File(homeDir == null ? "." : homeDir, ".mk");
@@ -51,11 +46,7 @@ public class Repository {
         }
         this.homeDir = home.getCanonicalPath();
 
-        pm = new H2PersistenceManager();
-        //pm = new InMemPersistenceManager();
-        //pm = new MongoPersistenceManager();
-        //pm = new BDbPersistenceManager();
-        //pm = new FSPersistenceManager();
+        rs = new DefaultRevisionStore();
 
         initialized = false;
     }
@@ -66,7 +57,7 @@ public class Repository {
         }
 
         File home = new File(homeDir);
-        pm.initialize(home);
+        rs.initialize(home);
 
         initialized = true;
     }
@@ -76,7 +67,7 @@ public class Repository {
             return;
         }
 
-        pm.close();
+        rs.close();
 
         initialized = false;
     }
@@ -86,28 +77,28 @@ public class Repository {
             throw new IllegalStateException("not initialized");
         }
 
-        return pm;
+        return rs;
     }
 
     public String getHeadRevision() throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        return pm.getHeadCommitId();
+        return rs.getHeadCommitId();
     }
 
     public StoredCommit getHeadCommit() throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        return pm.getHeadCommit();
+        return rs.getHeadCommit();
     }
 
     public StoredCommit getCommit(String id) throws NotFoundException, Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        return pm.getCommit(id);
+        return rs.getCommit(id);
     }
 
     /**
@@ -123,14 +114,14 @@ public class Repository {
             throw new IllegalStateException("not initialized");
         }
 
-        StoredNode root = pm.getRootNode(revId);
+        StoredNode root = rs.getRootNode(revId);
         if (PathUtils.denotesRoot(path)) {
             return root;
         }
 
         //return root.getNode(path.substring(1), pm);
         String[] ids = resolvePath(revId, path);
-        return pm.getNode(ids[ids.length - 1]);
+        return rs.getNode(ids[ids.length - 1]);
     }
 
     public boolean nodeExists(String revId, String path) {
@@ -144,13 +135,13 @@ public class Repository {
 
         try {
             String[] names = PathUtils.split(path);
-            Node parent = pm.getRootNode(revId);
+            Node parent = rs.getRootNode(revId);
             for (int i = 0; i < names.length; i++) {
                 ChildNodeEntry cne = parent.getChildNodeEntry(names[i]);
                 if (cne == null) {
                     return false;
                 }
-                parent = pm.getNode(cne.getId());
+                parent = rs.getNode(cne.getId());
             }
             return true;
         } catch (Exception e) {
@@ -159,7 +150,7 @@ public class Repository {
     }
 
     public CommitBuilder getCommitBuilder(String revId, String msg) throws Exception {
-        return new CommitBuilder(revId, msg, pm);
+        return new CommitBuilder(revId, msg, rs);
 
     }
 
@@ -177,7 +168,7 @@ public class Repository {
             throw new IllegalArgumentException("illegal path");
         }
 
-        Commit commit = pm.getCommit(revId);
+        Commit commit = rs.getCommit(revId);
 
         if (PathUtils.denotesRoot(nodePath)) {
             return new String[]{commit.getRootNodeId()};
@@ -187,7 +178,7 @@ public class Repository {
 
         // get root node
         ids[0] = commit.getRootNodeId();
-        Node parent = pm.getNode(ids[0]);
+        Node parent = rs.getNode(ids[0]);
         // traverse path and remember id of each element
         for (int i = 0; i < names.length; i++) {
             ChildNodeEntry cne = parent.getChildNodeEntry(names[i]);
@@ -195,7 +186,7 @@ public class Repository {
                 throw new NotFoundException(nodePath);
             }
             ids[i + 1] = cne.getId();
-            parent = pm.getNode(cne.getId());
+            parent = rs.getNode(cne.getId());
         }
         return ids;
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java?rev=1293282&r1=1293281&r2=1293282&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java Fri Feb 24 15:03:23 2012
@@ -19,15 +19,11 @@ package org.apache.jackrabbit.mk.store;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.InputStream;
 
-import org.apache.jackrabbit.mk.blobs.BlobStore;
-import org.apache.jackrabbit.mk.blobs.FileBlobStore;
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
-import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.util.StringUtils;
 
 import com.sleepycat.je.Database;
@@ -43,23 +39,22 @@ import com.sleepycat.je.OperationStatus;
 /**
  *
  */
-public class BDbPersistenceManager extends AbstractPersistenceManager {
+public class BDbPersistenceManager implements PersistenceManager {
 
     private final static byte[] HEAD_ID = new byte[]{0};
     private Environment dbEnv;
     private Database db;
     private Database head;
-    private BlobStore blobStore;
 
-    @Override
-    protected void doInitialize(File homeDir) throws Exception {
+    // TODO: make this configurable
+    private IdFactory idFactory = IdFactory.getDigestFactory();
+    
+    public void initialize(File homeDir) throws Exception {
         File dbDir = new File(homeDir, "db");
         if (!dbDir.exists()) {
             dbDir.mkdir();
         }
 
-        blobStore = new FileBlobStore(new File(homeDir, "blobs").getCanonicalPath());
-
         EnvironmentConfig envConfig = new EnvironmentConfig();
         //envConfig.setTransactional(true);
         envConfig.setAllowCreate(true);
@@ -86,8 +81,7 @@ public class BDbPersistenceManager exten
         });
     }
 
-    @Override
-    protected void doClose() {
+    public void close() {
         try {
             if (db.getConfig().getDeferredWrite()) {
                 db.sync();
@@ -103,8 +97,7 @@ public class BDbPersistenceManager exten
         }
     }
 
-    @Override
-    protected String readHead() throws Exception {
+    public String readHead() throws Exception {
         DatabaseEntry key = new DatabaseEntry(HEAD_ID);
         DatabaseEntry data = new DatabaseEntry();
 
@@ -115,29 +108,26 @@ public class BDbPersistenceManager exten
         }
     }
 
-    @Override
-    protected void writeHead(String id) throws Exception {
+    public void writeHead(String id) throws Exception {
         DatabaseEntry key = new DatabaseEntry(HEAD_ID);
         DatabaseEntry data = new DatabaseEntry(StringUtils.convertHexToBytes(id));
 
         head.put(null, key, data);
     }
 
-    @Override
-    protected StoredNode readNode(String id) throws NotFoundException, Exception {
+    public Binding readNodeBinding(String id) throws NotFoundException, Exception {
         DatabaseEntry key = new DatabaseEntry(StringUtils.convertHexToBytes(id));
         DatabaseEntry data = new DatabaseEntry();
 
         if (db.get(null, key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
             ByteArrayInputStream in = new ByteArrayInputStream(data.getData());
-            return StoredNode.deserialize(id, this, new BinaryBinding(in));
+            return new BinaryBinding(in);
         } else {
             throw new NotFoundException(id);
         }
     }
 
-    @Override
-    protected String writeNode(Node node) throws Exception {
+    public String writeNode(Node node) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         node.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -145,8 +135,7 @@ public class BDbPersistenceManager exten
         return persist(bytes, rawId);
     }
 
-    @Override
-    protected StoredCommit readCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
         DatabaseEntry key = new DatabaseEntry(StringUtils.convertHexToBytes(id));
         DatabaseEntry data = new DatabaseEntry();
 
@@ -158,8 +147,7 @@ public class BDbPersistenceManager exten
         }
     }
 
-    @Override
-    protected String writeCommit(Commit commit) throws Exception {
+    public String writeCommit(Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -167,23 +155,7 @@ public class BDbPersistenceManager exten
         return persist(bytes, rawId);
     }
 
-    @Override
-    protected String writeBlob(InputStream in) throws Exception {
-        return blobStore.writeBlob(in);
-    }
-
-    @Override
-    protected int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException, Exception {
-        return blobStore.readBlob(blobId, pos, buff, off, length);
-    }
-
-    @Override
-    protected long blobLength(String blobId) throws NotFoundException, Exception {
-        return blobStore.getBlobLength(blobId);
-    }
-
-    @Override
-    protected ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
+    public ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
         DatabaseEntry key = new DatabaseEntry(StringUtils.convertHexToBytes(id));
         DatabaseEntry data = new DatabaseEntry();
 
@@ -195,8 +167,7 @@ public class BDbPersistenceManager exten
         }
     }
 
-    @Override
-    protected String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
+    public String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         map.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java?rev=1293282&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java (added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java Fri Feb 24 15:03:23 2012
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.store;
+
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mk.blobs.FileBlobStore;
+import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
+import org.apache.jackrabbit.mk.model.Commit;
+import org.apache.jackrabbit.mk.model.MutableCommit;
+import org.apache.jackrabbit.mk.model.Node;
+import org.apache.jackrabbit.mk.model.MutableNode;
+import org.apache.jackrabbit.mk.model.StoredCommit;
+import org.apache.jackrabbit.mk.model.StoredNode;
+import org.apache.jackrabbit.mk.util.SimpleLRUCache;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Default revision store implementation, passing calls to a <code>PersistenceManager</code>
+ * and a <code>BlobStore</code>, respectively and providing caching. 
+ */
+public class DefaultRevisionStore implements RevisionStore {
+
+    public static final String CACHE_SIZE = "mk.cacheSize";
+    public static final int DEFAULT_CACHE_SIZE = 10000;
+
+    private boolean initialized;
+
+    private String headId;
+    private final ReentrantReadWriteLock headLock = new ReentrantReadWriteLock();
+    private PersistenceManager pm;
+    private BlobStore blobStore;
+    private boolean blobStoreNeedsClose;
+
+    private Map<String, Object> cache;
+
+    public void initialize(File homeDir) throws Exception {
+        if (initialized) {
+            throw new IllegalStateException("already initialized");
+        }
+
+        cache = Collections.synchronizedMap(SimpleLRUCache.<String, Object>newInstance(determineInitialCacheSize()));
+
+        pm = new H2PersistenceManager();
+        //pm = new InMemPersistenceManager();
+        //pm = new MongoPersistenceManager();
+        //pm = new BDbPersistenceManager();
+        //pm = new FSPersistenceManager();
+        pm.initialize(homeDir);
+        
+        if (pm instanceof BlobStore) {
+            blobStore = (BlobStore) pm;
+        } else {
+            blobStore = new FileBlobStore(new File(homeDir, "blobs").getCanonicalPath());
+            blobStoreNeedsClose = true;
+        }
+
+        // make sure we've got a HEAD commit
+        headId = pm.readHead();
+        if (headId == null || headId.length() == 0) {
+            // assume virgin repository
+            String rootNodeId = pm.writeNode(new MutableNode(this));
+            MutableCommit initialCommit = new MutableCommit();
+            initialCommit.setCommitTS(System.currentTimeMillis());
+            initialCommit.setRootNodeId(rootNodeId);
+            headId = pm.writeCommit(initialCommit);
+            pm.writeHead(headId);
+        }
+
+        initialized = true;
+    }
+
+    public void close() {
+        verifyInitialized();
+
+        cache.clear();
+
+        if (blobStoreNeedsClose) {
+            blobStore.close();
+        }
+        pm.close();
+        
+        initialized = false;
+    }
+
+    protected void verifyInitialized() {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+    }
+
+    protected int determineInitialCacheSize() {
+        String val = System.getProperty(CACHE_SIZE);
+        return (val != null) ? Integer.parseInt(val) : DEFAULT_CACHE_SIZE;
+    }
+    
+    //--------------------------------------------------------< RevisionStore >
+
+    public String putNode(Node node) throws Exception {
+        verifyInitialized();
+
+        PersistHook callback = null;
+        if (node instanceof PersistHook) {
+            callback = (PersistHook) node;
+            callback.prePersist(this);
+        }
+
+        String id = pm.writeNode(node);
+        
+        if (callback != null)  {
+            callback.postPersist(this);
+        }
+        
+        cache.put(id, new StoredNode(id, node, this));
+
+        return id;
+    }
+
+    public String putCNEMap(ChildNodeEntriesMap map) throws Exception {
+        verifyInitialized();
+
+        PersistHook callback = null;
+        if (map instanceof PersistHook) {
+            callback = (PersistHook) map;
+            callback.prePersist(this);
+        }
+
+       String id = pm.writeCNEMap(map);
+
+        if (callback != null)  {
+            callback.postPersist(this);
+        }
+
+        cache.put(id, map);
+
+        return id;
+    }
+
+    public String putCommit(Commit commit) throws Exception {
+        verifyInitialized();
+
+        PersistHook callback = null;
+        if (commit instanceof PersistHook) {
+            callback = (PersistHook) commit;
+            callback.prePersist(this);
+        }
+
+        String id = pm.writeCommit(commit);
+
+        if (callback != null)  {
+            callback.postPersist(this);
+        }
+
+        cache.put(id, new StoredCommit(id, commit));
+
+        return id;
+    }
+
+    public void setHeadCommitId(String commitId) throws Exception {
+        verifyInitialized();
+
+        headLock.writeLock().lock();
+        try {
+            pm.writeHead(commitId);
+            headId = commitId;
+        } finally {
+            headLock.writeLock().unlock();
+        }
+    }
+
+    public void lockHead() {
+        headLock.writeLock().lock();
+    }
+
+    public void unlockHead() {
+        headLock.writeLock().unlock();
+    }
+
+    public String putBlob(InputStream in) throws Exception {
+        verifyInitialized();
+
+        return blobStore.writeBlob(in);
+    }
+
+    //-----------------------------------------------------< RevisionProvider >
+
+    public StoredNode getNode(String id) throws NotFoundException, Exception {
+        verifyInitialized();
+
+        StoredNode node = (StoredNode) cache.get(id);
+        if (node != null) {
+            return node;
+        }
+
+        Binding nodeBinding = pm.readNodeBinding(id);
+        node = StoredNode.deserialize(id, this, nodeBinding);
+
+        cache.put(id, node);
+
+        return node;
+    }
+
+    public ChildNodeEntriesMap getCNEMap(String id) throws NotFoundException, Exception {
+        verifyInitialized();
+
+        ChildNodeEntriesMap map = (ChildNodeEntriesMap) cache.get(id);
+        if (map != null) {
+            return map;
+        }
+
+        map = pm.readCNEMap(id);
+
+        cache.put(id, map);
+
+        return map;
+    }
+
+    public StoredCommit getCommit(String id) throws NotFoundException, Exception {
+        verifyInitialized();
+
+        StoredCommit commit = (StoredCommit) cache.get(id);
+        if (commit != null) {
+            return commit;
+        }
+
+        commit = pm.readCommit(id);
+        cache.put(id, commit);
+
+        return commit;
+    }
+
+    public StoredNode getRootNode(String commitId) throws NotFoundException, Exception {
+        return getNode(getCommit(commitId).getRootNodeId());
+    }
+
+    public StoredCommit getHeadCommit() throws Exception {
+        return getCommit(getHeadCommitId());
+    }
+
+    public String getHeadCommitId() throws Exception {
+        verifyInitialized();
+
+        headLock.readLock().lock();
+        try {
+            return headId;
+        } finally {
+            headLock.readLock().unlock();
+        }
+    }
+
+    public int getBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException, Exception {
+        verifyInitialized();
+
+        return blobStore.readBlob(blobId, pos, buff, off, length);
+    }
+
+    public long getBlobLength(String blobId) throws NotFoundException, Exception {
+        verifyInitialized();
+
+        return blobStore.getBlobLength(blobId);
+    }
+}

Propchange: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java?rev=1293282&r1=1293281&r2=1293282&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java Fri Feb 24 15:03:23 2012
@@ -21,49 +21,40 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.InputStream;
 
-import org.apache.jackrabbit.mk.blobs.BlobStore;
-import org.apache.jackrabbit.mk.blobs.FileBlobStore;
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
-import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.StringUtils;
 
 /**
  *
  */
-public class FSPersistenceManager extends AbstractPersistenceManager {
+public class FSPersistenceManager implements PersistenceManager {
 
     private File dataDir;
     private File head;
-    private BlobStore blobStore;
-
-    @Override
-    protected void doInitialize(File homeDir) throws Exception {
-        blobStore = new FileBlobStore(new File(homeDir, "blobs").getCanonicalPath());
 
+    // TODO: make this configurable
+    private IdFactory idFactory = IdFactory.getDigestFactory();
+    
+    public void initialize(File homeDir) throws Exception {
         dataDir = new File(homeDir, "data");
         if (!dataDir.exists()) {
             dataDir.mkdir();
         }
-
         head = new File(homeDir, "HEAD");
         if (!head.exists()) {
             writeHead("");
         }
-
     }
 
-    @Override
-    protected void doClose() {
+    public void close() {
     }
 
-    @Override
-    protected String readHead() throws Exception {
+    public String readHead() throws Exception {
         FileInputStream in = new FileInputStream(head);
         try {
             return IOUtils.readString(in);
@@ -72,8 +63,7 @@ public class FSPersistenceManager extend
         }
     }
 
-    @Override
-    protected void writeHead(String id) throws Exception {
+    public void writeHead(String id) throws Exception {
         FileOutputStream out = new FileOutputStream(head);
         try {
             IOUtils.writeString(out, id);
@@ -82,13 +72,12 @@ public class FSPersistenceManager extend
         }
     }
 
-    @Override
-    protected StoredNode readNode(String id) throws NotFoundException, Exception {
+    public Binding readNodeBinding(String id) throws NotFoundException, Exception {
         File f = getFile(id);
         if (f.exists()) {
             BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
             try {
-                return StoredNode.deserialize(id, this, new BinaryBinding(in));
+                return new BinaryBinding(in);
             } finally {
                 in.close();
             }
@@ -97,8 +86,7 @@ public class FSPersistenceManager extend
         }
     }
 
-    @Override
-    protected String writeNode(Node node) throws Exception {
+    public String writeNode(Node node) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         node.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -106,8 +94,7 @@ public class FSPersistenceManager extend
         return writeFile(bytes, rawId);
     }
 
-    @Override
-    protected StoredCommit readCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
         File f = getFile(id);
         if (f.exists()) {
             BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
@@ -121,8 +108,7 @@ public class FSPersistenceManager extend
         }
     }
 
-    @Override
-    protected String writeCommit(Commit commit) throws Exception {
+    public String writeCommit(Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -130,23 +116,7 @@ public class FSPersistenceManager extend
         return writeFile(bytes, rawId);
     }
 
-    @Override
-    protected String writeBlob(InputStream in) throws Exception {
-        return blobStore.writeBlob(in);
-    }
-
-    @Override
-    protected int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException, Exception {
-        return blobStore.readBlob(blobId, pos, buff, off, length);
-    }
-
-    @Override
-    protected long blobLength(String blobId) throws NotFoundException, Exception {
-        return blobStore.getBlobLength(blobId);
-    }
-
-    @Override
-    protected ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
+    public ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
         File f = getFile(id);
         if (f.exists()) {
             BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
@@ -160,8 +130,7 @@ public class FSPersistenceManager extend
         }
     }
 
-    @Override
-    protected String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
+    public String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         map.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java?rev=1293282&r1=1293281&r2=1293282&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java Fri Feb 24 15:03:23 2012
@@ -16,20 +16,16 @@
  */
 package org.apache.jackrabbit.mk.store;
 
-import org.apache.jackrabbit.mk.blobs.BlobStore;
-import org.apache.jackrabbit.mk.blobs.FileBlobStore;
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
-import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.util.StringUtils;
 import org.h2.jdbcx.JdbcConnectionPool;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.InputStream;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -38,15 +34,18 @@ import java.sql.Statement;
 /**
  *
  */
-public class H2PersistenceManager extends AbstractPersistenceManager {
+public class H2PersistenceManager implements PersistenceManager {
 
     private static final boolean FAST = Boolean.getBoolean("mk.fastDb");
 
     private JdbcConnectionPool cp;
-    private BlobStore blobStore;
+    
+    // TODO: make this configurable
+    private IdFactory idFactory = IdFactory.getDigestFactory();
+
+    //---------------------------------------------------< PersistenceManager >
 
-    @Override
-    protected void doInitialize(File homeDir) throws Exception {
+    public void initialize(File homeDir) throws Exception {
         File dbDir = new File(homeDir, "db");
         if (!dbDir.exists()) {
             dbDir.mkdir();
@@ -70,19 +69,16 @@ public class H2PersistenceManager extend
             store.setConnectionPool(cp);
             blobStore = store;
 */
-            blobStore = new FileBlobStore(new File(homeDir, "blobs").getCanonicalPath());
         } finally {
             con.close();
         }
     }
 
-    @Override
-    protected void doClose() {
+    public void close() {
         cp.dispose();
     }
 
-    @Override
-    protected String readHead() throws Exception {
+    public String readHead() throws Exception {
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement("select * from head");
@@ -98,8 +94,7 @@ public class H2PersistenceManager extend
         }
     }
 
-    @Override
-    protected void writeHead(String id) throws Exception {
+    public void writeHead(String id) throws Exception {
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement("update head set id=?");
@@ -111,8 +106,7 @@ public class H2PersistenceManager extend
         }
     }
 
-    @Override
-    protected StoredNode readNode(String id) throws NotFoundException, Exception {
+    public Binding readNodeBinding(String id) throws NotFoundException, Exception {
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement("select DATA from REVS where ID = ?");
@@ -121,7 +115,7 @@ public class H2PersistenceManager extend
                 ResultSet rs = stmt.executeQuery();
                 if (rs.next()) {
                     ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));
-                    return StoredNode.deserialize(id, this, new BinaryBinding(in));
+                    return new BinaryBinding(in);
                 } else {
                     throw new NotFoundException(id);
                 }
@@ -133,8 +127,7 @@ public class H2PersistenceManager extend
         }
     }
 
-    @Override
-    protected String writeNode(Node node) throws Exception {
+    public String writeNode(Node node) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         node.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -160,8 +153,7 @@ public class H2PersistenceManager extend
         return id;
     }
 
-    @Override
-    protected StoredCommit readCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement("select DATA from REVS where ID = ?");
@@ -182,8 +174,7 @@ public class H2PersistenceManager extend
         }
     }
     
-    @Override
-    protected String writeCommit(Commit commit) throws Exception {
+    public String writeCommit(Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -209,23 +200,7 @@ public class H2PersistenceManager extend
         return id;
     }
 
-    @Override
-    protected String writeBlob(InputStream in) throws Exception {
-        return blobStore.writeBlob(in);
-    }
-
-    @Override
-    protected int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException, Exception {
-        return blobStore.readBlob(blobId, pos, buff, off, length);
-    }
-
-    @Override
-    protected long blobLength(String blobId) throws NotFoundException, Exception {
-        return blobStore.getBlobLength(blobId);
-    }
-
-    @Override
-    protected ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
+    public ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement("select DATA from REVS where ID = ?");
@@ -246,8 +221,7 @@ public class H2PersistenceManager extend
         }
     }
 
-    @Override
-    protected String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
+    public String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         map.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java?rev=1293282&r1=1293281&r2=1293282&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java Fri Feb 24 15:03:23 2012
@@ -30,67 +30,61 @@ import org.apache.jackrabbit.mk.model.Ch
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
-import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.util.StringUtils;
 
 /**
  *
  */
-public class InMemPersistenceManager extends AbstractPersistenceManager {
+public class InMemPersistenceManager implements PersistenceManager, BlobStore {
 
-
-    private final Map<String, StoredNode> nodes = Collections.synchronizedMap(new HashMap<String, StoredNode>());
+    private final Map<String, byte[]> nodes = Collections.synchronizedMap(new HashMap<String, byte[]>());
     private final Map<String, StoredCommit> commits = Collections.synchronizedMap(new HashMap<String, StoredCommit>());
     private final Map<String, ChildNodeEntriesMap> cneMaps = Collections.synchronizedMap(new HashMap<String, ChildNodeEntriesMap>());
     private final BlobStore blobs = new MemoryBlobStore();
 
     private String head;
 
-    @Override
-    protected void doInitialize(File homeDir) throws Exception {
+    // TODO: make this configurable
+    private IdFactory idFactory = IdFactory.getDigestFactory();
+    
+    public void initialize(File homeDir) throws Exception {
         head = null;
     }
 
-    @Override
-    protected void doClose() {
+    public void close() {
     }
 
-    @Override
-    protected String readHead() throws Exception {
+    public String readHead() throws Exception {
         return head;
     }
 
-    @Override
-    protected void writeHead(String id) throws Exception {
+    public void writeHead(String id) throws Exception {
         head = id;
     }
 
-    @Override
-    protected StoredNode readNode(String id) throws NotFoundException, Exception {
-        StoredNode node = nodes.get(id);
-        if (node != null) {
-            return node;
+    public Binding readNodeBinding(String id) throws NotFoundException, Exception {
+        byte[] bytes = nodes.get(id);
+        if (bytes != null) {
+            return new BinaryBinding(new ByteArrayInputStream(bytes));
         } else {
             throw new NotFoundException(id);
         }
     }
 
-    @Override
-    protected String writeNode(Node node) throws Exception {
+    public String writeNode(Node node) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         node.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
         String id = StringUtils.convertBytesToHex(idFactory.createContentId(bytes));
 
         if (!nodes.containsKey(id)) {
-            nodes.put(id, StoredNode.deserialize(id, this, new BinaryBinding(new ByteArrayInputStream(bytes))));
+            nodes.put(id, bytes);
         }
 
         return id;
     }
 
-    @Override
-    protected StoredCommit readCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
         StoredCommit commit = commits.get(id);
         if (commit != null) {
             return commit;
@@ -99,8 +93,7 @@ public class InMemPersistenceManager ext
         }
     }
 
-    @Override
-    protected String writeCommit(Commit commit) throws Exception {
+    public String writeCommit(Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -113,23 +106,7 @@ public class InMemPersistenceManager ext
         return id;
     }
 
-    @Override
-    protected String writeBlob(InputStream in) throws Exception {
-        return blobs.writeBlob(in);
-    }
-
-    @Override
-    protected int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException, Exception {
-        return blobs.readBlob(blobId, pos, buff, off, length);
-    }
-
-    @Override
-    protected long blobLength(String blobId) throws NotFoundException, Exception {
-        return blobs.getBlobLength(blobId);
-    }
-
-    @Override
-    protected ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
+    public ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
         ChildNodeEntriesMap map = cneMaps.get(id);
         if (map != null) {
             return map;
@@ -138,8 +115,7 @@ public class InMemPersistenceManager ext
         }
     }
 
-    @Override
-    protected String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
+    public String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         map.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -151,4 +127,22 @@ public class InMemPersistenceManager ext
 
         return id;
     }
+    
+    //------------------------------------------------------------< BlobStore >
+
+    public String addBlob(String tempFilePath) throws Exception {
+        return blobs.addBlob(tempFilePath);
+    }
+
+    public String writeBlob(InputStream in) throws Exception {
+        return blobs.writeBlob(in);
+    }
+
+    public int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException, Exception {
+        return blobs.readBlob(blobId, pos, buff, off, length);
+    }
+
+    public long getBlobLength(String blobId) throws Exception {
+        return blobs.getBlobLength(blobId);
+    }
 }

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=1293282&r1=1293281&r2=1293282&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 24 15:03:23 2012
@@ -22,11 +22,13 @@ import java.io.File;
 import java.io.InputStream;
 import java.util.Iterator;
 
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mk.fs.FilePath;
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
-import org.apache.jackrabbit.mk.model.StoredNode;
+import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.StringUtils;
 import org.bson.types.ObjectId;
@@ -45,7 +47,7 @@ import com.mongodb.gridfs.GridFSInputFil
 /**
  *
  */
-public class MongoPersistenceManager extends AbstractPersistenceManager {
+public class MongoPersistenceManager implements PersistenceManager, BlobStore {
 
     private static final boolean BINARY_FORMAT = false;
 
@@ -63,8 +65,10 @@ public class MongoPersistenceManager ext
     private DBCollection cneMaps;
     private GridFS fs;
 
-    @Override
-    protected void doInitialize(File homeDir) throws Exception {
+    // TODO: make this configurable
+    private IdFactory idFactory = IdFactory.getDigestFactory();
+    
+    public void initialize(File homeDir) throws Exception {
         con = new Mongo();
         //con = new Mongo("localhost", 27017);
 
@@ -94,15 +98,13 @@ public class MongoPersistenceManager ext
         fs = new GridFS(db);
     }
 
-    @Override
-    protected void doClose() {
+    public void close() {
         con.close();
         con = null;
         db = null;
     }
 
-    @Override
-    protected String readHead() throws Exception {
+    public String readHead() throws Exception {
         DBObject entry = db.getCollection(HEAD_COLLECTION).findOne();
         if (entry == null) {
             return null;
@@ -110,14 +112,12 @@ public class MongoPersistenceManager ext
         return (String) entry.get(ID_FIELD);
     }
 
-    @Override
-    protected void writeHead(String id) throws Exception {
+    public void writeHead(String id) throws Exception {
         // capped collection of size 1
         db.getCollection(HEAD_COLLECTION).insert(new BasicDBObject(ID_FIELD, id));
     }
 
-    @Override
-    protected StoredNode readNode(String id) throws NotFoundException, Exception {
+    public Binding readNodeBinding(String id) throws NotFoundException, Exception {
         BasicDBObject key = new BasicDBObject();
         if (BINARY_FORMAT) {
             key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
@@ -129,17 +129,16 @@ public class MongoPersistenceManager ext
             // todo support partitioned child node lists
             if (BINARY_FORMAT) {
                 byte[] bytes = (byte[]) nodeObject.get(DATA_FIELD);
-                return StoredNode.deserialize(id, this, new BinaryBinding(new ByteArrayInputStream(bytes)));
+                return new BinaryBinding(new ByteArrayInputStream(bytes));
             } else {
-                return StoredNode.deserialize(id, this, new DBObjectBinding(nodeObject));
+                return new DBObjectBinding(nodeObject);
             }
         } else {
             throw new NotFoundException(id);
         }
     }
-
-    @Override
-    protected String writeNode(Node node) throws Exception {
+    
+    public String writeNode(Node node) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         node.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -163,8 +162,7 @@ public class MongoPersistenceManager ext
         return id;
     }
 
-    @Override
-    protected StoredCommit readCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
         BasicDBObject key = new BasicDBObject();
         if (BINARY_FORMAT) {
             key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
@@ -184,8 +182,7 @@ public class MongoPersistenceManager ext
         }
     }
 
-    @Override
-    protected String writeCommit(Commit commit) throws Exception {
+    public String writeCommit(Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -208,43 +205,7 @@ public class MongoPersistenceManager ext
         return id;
     }
 
-    @Override
-    protected String writeBlob(InputStream in) throws Exception {
-        GridFSInputFile f = fs.createFile(in, true);
-        //f.save(0x20000);   // save in 128k chunks
-        f.save();
-
-        return f.getId().toString();
-    }
-
-    @Override
-    protected int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException, Exception {
-        GridFSDBFile f = fs.findOne(new ObjectId(blobId));
-        if (f == null) {
-            throw new NotFoundException(blobId);
-        }
-        // todo provide a more efficient implementation
-        InputStream in = f.getInputStream();
-        try {
-            in.skip(pos);
-            return in.read(buff, off, length);
-        } finally {
-            IOUtils.closeQuietly(in);
-        }
-    }
-
-    @Override
-    protected long blobLength(String blobId) throws NotFoundException, Exception {
-        GridFSDBFile f = fs.findOne(new ObjectId(blobId));
-        if (f == null) {
-            throw new NotFoundException(blobId);
-        }
-
-        return f.getLength();
-    }
-
-    @Override
-    protected ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
+    public ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception {
         BasicDBObject key = new BasicDBObject();
         if (BINARY_FORMAT) {
             key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
@@ -264,8 +225,7 @@ public class MongoPersistenceManager ext
         }
     }
 
-    @Override
-    protected String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
+    public String writeCNEMap(ChildNodeEntriesMap map) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         map.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -288,6 +248,56 @@ public class MongoPersistenceManager ext
         return id;
     }
 
+    //------------------------------------------------------------< BlobStore >
+
+    public String addBlob(String tempFilePath) throws Exception {
+        try {
+            FilePath file = FilePath.get(tempFilePath);
+            try {
+                InputStream in = file.newInputStream();
+                return writeBlob(in);
+            } finally {
+                file.delete();
+            }
+        } catch (Exception e) {
+            throw ExceptionFactory.convert(e);
+        }
+    }
+
+    public String writeBlob(InputStream in) throws Exception {
+        GridFSInputFile f = fs.createFile(in, true);
+        //f.save(0x20000);   // save in 128k chunks
+        f.save();
+
+        return f.getId().toString();
+    }
+
+    public int readBlob(String blobId, long pos, byte[] buff, int off,
+            int length) throws Exception {
+
+        GridFSDBFile f = fs.findOne(new ObjectId(blobId));
+        if (f == null) {
+            throw new NotFoundException(blobId);
+        }
+        // todo provide a more efficient implementation
+        InputStream in = f.getInputStream();
+        try {
+            in.skip(pos);
+            return in.read(buff, off, length);
+        } finally {
+            IOUtils.closeQuietly(in);
+        }
+    }
+
+    public long getBlobLength(String blobId) throws Exception {
+        GridFSDBFile f = fs.findOne(new ObjectId(blobId));
+        if (f == null) {
+            throw new NotFoundException(blobId);
+        }
+
+        return f.getLength();
+    }
+    
     //-------------------------------------------------------< implementation >
 
     protected final static String ENCODED_DOT = "_x46_";

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java?rev=1293282&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java (added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java Fri Feb 24 15:03:23 2012
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.store;
+
+import java.io.File;
+
+import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
+import org.apache.jackrabbit.mk.model.Commit;
+import org.apache.jackrabbit.mk.model.Node;
+import org.apache.jackrabbit.mk.model.StoredCommit;
+
+/**
+ * Defines the methods exposed by a persistence manager, that stores head
+ * revision id, nodes, child node entries and blobs.
+ * 
+ * TODO: convert model type (e.g. Commit) arguments into byte arrays or similar
+ *       primitive types (such as in #readNodeBinding).
+ */
+public interface PersistenceManager {
+
+    void initialize(File homeDir) throws Exception;
+
+    void close();
+
+    String readHead() throws Exception;
+
+    void writeHead(String id) throws Exception;
+
+    Binding readNodeBinding(String id) throws NotFoundException, Exception;
+
+    String writeNode(Node node) throws Exception;
+
+    ChildNodeEntriesMap readCNEMap(String id) throws NotFoundException, Exception;
+
+    String writeCNEMap(ChildNodeEntriesMap map) throws Exception;
+
+    StoredCommit readCommit(String id) throws NotFoundException, Exception;
+
+    String writeCommit(Commit commit) throws Exception;
+}

Propchange: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: jackrabbit/sandbox/microkernel/wstest.html
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/wstest.html?rev=1293282&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/wstest.html (added)
+++ jackrabbit/sandbox/microkernel/wstest.html Fri Feb 24 15:03:23 2012
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>WebSocket Test</title>
+<script language="javascript" type="text/javascript">
+var wsUri = "ws://echo.websocket.org/"; 
+//wsUri = "ws://localhost:28080/"; 
+var output;  
+
+function init()
+{ 
+output = document.getElementById("output");
+testWebSocket();
+}
+
+function testWebSocket()
+{
+websocket = new WebSocket(wsUri);
+websocket.onopen = function(evt) { onOpen(evt) };
+websocket.onclose = function(evt) { onClose(evt) };
+websocket.onmessage = function(evt) { onMessage(evt) };
+websocket.onerror = function(evt) { onError(evt) };
+}
+
+function onOpen(evt)
+{
+writeToScreen("CONNECTED");
+doSend("WebSocket rocks");
+}
+
+function onClose(evt)
+{
+writeToScreen("DISCONNECTED");
+}
+
+function onMessage(evt)
+{
+writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');
+websocket.close();
+}
+
+function onError(evt)
+{
+writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
+}
+
+function doSend(message)
+{
+writeToScreen("SENT: " + message);
+websocket.send(message);
+}
+
+function writeToScreen(message)
+{
+var pre = document.createElement("p");
+pre.style.wordWrap = "break-word";
+pre.innerHTML = message;
+output.appendChild(pre);
+}
+
+window.addEventListener("load", init, false);
+</script>
+
+<h2>WebSocket Test</h2>
+<div id="output"></div>
+</html>

Propchange: jackrabbit/sandbox/microkernel/wstest.html
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message