jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1303850 - in /jackrabbit/oak/trunk/oak-mk/src: main/java/org/apache/jackrabbit/mk/blobs/ main/java/org/apache/jackrabbit/mk/core/ main/java/org/apache/jackrabbit/mk/persistence/ main/java/org/apache/jackrabbit/mk/store/ test/java/org/apach...
Date Thu, 22 Mar 2012 15:45:32 GMT
Author: dpfister
Date: Thu Mar 22 15:45:31 2012
New Revision: 1303850

URL: http://svn.apache.org/viewvc?rev=1303850&view=rev
Log:
Refactor blob methods out of RevisionProvider/RevisionStore
- remove initialize() from Persistence interface
- use Closeable marker interface instead of Persistence.close()

Modified:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
Thu Mar 22 15:45:31 2012
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.mk.util.Str
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
@@ -62,7 +63,7 @@ import java.util.WeakHashMap;
  * long), size of data store id (variable size long), hash code length (variable
  * size int), hash code.
  */
-public abstract class AbstractBlobStore implements BlobStore, Cache.Backend<AbstractBlobStore.BlockId,
AbstractBlobStore.Data> {
+public abstract class AbstractBlobStore implements Closeable, BlobStore, Cache.Backend<AbstractBlobStore.BlockId,
AbstractBlobStore.Data> {
 
     protected static final String HASH_ALGORITHM = "SHA-1";
 

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
Thu Mar 22 15:45:31 2012
@@ -578,7 +578,7 @@ public class MicroKernelImpl implements 
             throw new IllegalStateException("this instance has already been disposed");
         }
         try {
-            return rep.getRevisionStore().getBlobLength(blobId);
+            return rep.getBlobStore().getBlobLength(blobId);
         } catch (Exception e) {
             throw new MicroKernelException(e);
         }
@@ -589,7 +589,7 @@ public class MicroKernelImpl implements 
             throw new IllegalStateException("this instance has already been disposed");
         }
         try {
-            return rep.getRevisionStore().getBlob(blobId, pos, buff, off, length);
+            return rep.getBlobStore().readBlob(blobId, pos, buff, off, length);
         } catch (Exception e) {
             throw new MicroKernelException(e);
         }
@@ -600,7 +600,7 @@ public class MicroKernelImpl implements 
             throw new IllegalStateException("this instance has already been disposed");
         }
         try {
-            return rep.getRevisionStore().putBlob(in);
+            return rep.getBlobStore().writeBlob(in);
         } catch (Exception e) {
             throw new MicroKernelException(e);
         }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java
Thu Mar 22 15:45:31 2012
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.mk.core;
 import java.io.Closeable;
 import java.io.File;
 
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mk.blobs.FileBlobStore;
 import org.apache.jackrabbit.mk.model.CommitBuilder;
 import org.apache.jackrabbit.mk.model.Id;
 import org.apache.jackrabbit.mk.model.NodeState;
@@ -35,13 +37,15 @@ import org.apache.jackrabbit.mk.util.Pat
  */
 public class Repository {
 
-    private final String homeDir;
+    private final File homeDir;
     private boolean initialized;
     private RevisionStore rs;
+    private BlobStore bs;
+    private boolean blobStoreNeedsClose;
 
     public Repository(String homeDir) throws Exception {
         File home = new File(homeDir == null ? "." : homeDir, ".mk");
-        this.homeDir = home.getCanonicalPath();
+        this.homeDir = home.getCanonicalFile();
     }
     
     /**
@@ -49,9 +53,10 @@ public class Repository {
      * 
      * @param rs revision store, already initialized
      */
-    public Repository(RevisionStore rs) {
+    public Repository(RevisionStore rs, BlobStore bs) {
         this.homeDir = null;
         this.rs = rs;
+        this.bs = bs;
 
         initialized = true;
     }
@@ -61,11 +66,21 @@ public class Repository {
             return;
         }
 
-        DefaultRevisionStore rs = new DefaultRevisionStore();
-        rs.initialize(new File(homeDir), new H2Persistence());
-
+        H2Persistence pm = new H2Persistence(homeDir);
+        pm.initialize();
+        
+        DefaultRevisionStore rs = new DefaultRevisionStore(pm);
+        rs.initialize();
+        
         this.rs = rs;
-
+        
+        if (pm instanceof BlobStore) {
+            bs = (BlobStore) pm;
+        } else {
+            bs = new FileBlobStore(new File(homeDir, "blobs").getCanonicalPath());
+            blobStoreNeedsClose = true;
+        }
+        
         initialized = true;
     }
 
@@ -73,6 +88,9 @@ public class Repository {
         if (!initialized) {
             return;
         }
+        if (blobStoreNeedsClose && bs instanceof Closeable) {
+            IOUtils.closeQuietly((Closeable) bs);
+        }
         if (rs instanceof Closeable) {
             IOUtils.closeQuietly((Closeable) rs);
         }
@@ -86,6 +104,14 @@ public class Repository {
 
         return rs;
     }
+    
+    public BlobStore getBlobStore() {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        return bs;
+    }
 
     public Id getHeadRevision() throws Exception {
         if (!initialized) {

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java
Thu Mar 22 15:45:31 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.mk.persist
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
 import java.io.File;
 
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
@@ -43,9 +44,10 @@ import com.sleepycat.je.OperationStatus;
 /**
  *
  */
-public class BDbPersistence implements Persistence {
+public class BDbPersistence implements Persistence, Closeable {
 
     private final static byte[] HEAD_ID = new byte[]{0};
+    private final File homeDir;
     private Environment dbEnv;
     private Database db;
     private Database head;
@@ -53,7 +55,11 @@ public class BDbPersistence implements P
     // TODO: make this configurable
     private IdFactory idFactory = IdFactory.getDigestFactory();
     
-    public void initialize(File homeDir) throws Exception {
+    public BDbPersistence(File homeDir) {
+        this.homeDir = homeDir;
+    }
+    
+    public void initialize() throws Exception {
         File dbDir = new File(homeDir, "db");
         if (!dbDir.exists()) {
             dbDir.mkdirs();

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java
Thu Mar 22 15:45:31 2012
@@ -38,13 +38,19 @@ import org.apache.jackrabbit.mk.util.IOU
  */
 public class FSPersistence implements Persistence {
 
+    private final File homeDir;
     private File dataDir;
     private File head;
 
     // TODO: make this configurable
     private IdFactory idFactory = IdFactory.getDigestFactory();
     
-    public void initialize(File homeDir) throws Exception {
+    
+    public FSPersistence(File homeDir) {
+        this.homeDir = homeDir;
+    }
+    
+    public void initialize() throws Exception {
         dataDir = new File(homeDir, "data");
         if (!dataDir.exists()) {
             dataDir.mkdirs();
@@ -55,9 +61,6 @@ public class FSPersistence implements Pe
         }
     }
 
-    public void close() {
-    }
-
     public Id readHead() throws Exception {
         FileInputStream in = new FileInputStream(head);
         try {

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
Thu Mar 22 15:45:31 2012
@@ -29,6 +29,7 @@ import org.h2.jdbcx.JdbcConnectionPool;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
 import java.io.File;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
@@ -38,18 +39,23 @@ import java.sql.Statement;
 /**
  *
  */
-public class H2Persistence implements Persistence {
+public class H2Persistence implements Persistence, Closeable {
 
     private static final boolean FAST = Boolean.getBoolean("mk.fastDb");
 
+    private final File homeDir;
     private JdbcConnectionPool cp;
     
     // TODO: make this configurable
     private IdFactory idFactory = IdFactory.getDigestFactory();
 
+    public H2Persistence(File homeDir) throws Exception {
+        this.homeDir = homeDir;
+    }
+    
     //---------------------------------------------------< Persistence >
 
-    public void initialize(File homeDir) throws Exception {
+    public void initialize() throws Exception {
         File dbDir = new File(homeDir, "db");
         if (!dbDir.exists()) {
             dbDir.mkdirs();

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java
Thu Mar 22 15:45:31 2012
@@ -18,14 +18,10 @@ package org.apache.jackrabbit.mk.persist
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.InputStream;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.jackrabbit.mk.blobs.BlobStore;
-import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Id;
@@ -39,34 +35,26 @@ import org.apache.jackrabbit.mk.store.No
 /**
  *
  */
-public class InMemPersistence implements Persistence, BlobStore {
+public class InMemPersistence implements Persistence {
 
     private final Map<Id, byte[]> nodes = Collections.synchronizedMap(new HashMap<Id,
byte[]>());
     private final Map<Id, StoredCommit> commits = Collections.synchronizedMap(new HashMap<Id,
StoredCommit>());
     private final Map<Id, ChildNodeEntriesMap> cneMaps = Collections.synchronizedMap(new
HashMap<Id, ChildNodeEntriesMap>());
-    private final BlobStore blobs = new MemoryBlobStore();
 
     private Id head;
 
     // TODO: make this configurable
     private IdFactory idFactory = IdFactory.getDigestFactory();
     
-    public void initialize(File homeDir) throws Exception {
-        head = null;
-    }
-
-    public void close() {
-    }
-
-    public Id readHead() throws Exception {
+    public Id readHead() {
         return head;
     }
 
-    public void writeHead(Id id) throws Exception {
+    public void writeHead(Id id) {
         head = id;
     }
 
-    public Binding readNodeBinding(Id id) throws NotFoundException, Exception {
+    public Binding readNodeBinding(Id id) throws NotFoundException {
         byte[] bytes = nodes.get(id);
         if (bytes != null) {
             return new BinaryBinding(new ByteArrayInputStream(bytes));
@@ -88,7 +76,7 @@ public class InMemPersistence implements
         return id;
     }
 
-    public StoredCommit readCommit(Id id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(Id id) throws NotFoundException {
         StoredCommit commit = commits.get(id);
         if (commit != null) {
             return commit;
@@ -107,7 +95,7 @@ public class InMemPersistence implements
         }
     }
 
-    public ChildNodeEntriesMap readCNEMap(Id id) throws NotFoundException, Exception {
+    public ChildNodeEntriesMap readCNEMap(Id id) throws NotFoundException {
         ChildNodeEntriesMap map = cneMaps.get(id);
         if (map != null) {
             return map;
@@ -128,22 +116,4 @@ public class InMemPersistence implements
 
         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/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
Thu Mar 22 15:45:31 2012
@@ -18,7 +18,7 @@ package org.apache.jackrabbit.mk.persist
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
+import java.io.Closeable;
 import java.io.InputStream;
 import java.util.Iterator;
 
@@ -50,9 +50,9 @@ import com.mongodb.gridfs.GridFSDBFile;
 import com.mongodb.gridfs.GridFSInputFile;
 
 /**
- *
+ * 
  */
-public class MongoPersistence implements Persistence, BlobStore {
+public class MongoPersistence implements Persistence, Closeable, BlobStore {
 
     private static final boolean BINARY_FORMAT = false;
 
@@ -73,7 +73,7 @@ public class MongoPersistence implements
     // TODO: make this configurable
     private IdFactory idFactory = IdFactory.getDigestFactory();
     
-    public void initialize(File homeDir) throws Exception {
+    public void initialize() throws Exception {
         con = new Mongo();
         //con = new Mongo("localhost", 27017);
 

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java
Thu Mar 22 15:45:31 2012
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.mk.persistence;
 
-import java.io.File;
-
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Id;
@@ -35,10 +33,6 @@ import org.apache.jackrabbit.mk.store.No
  */
 public interface Persistence {
 
-    void initialize(File homeDir) throws Exception;
-
-    void close();
-
     Id readHead() throws Exception;
 
     void writeHead(Id id) throws Exception;

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
Thu Mar 22 15:45:31 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.mk.store;
 
-import java.io.InputStream;
 import java.util.Iterator;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -222,23 +221,4 @@ public class CopyingGC implements Revisi
             rsFrom.unlockHead();
         }
     }
-    
-    public int getBlob(String blobId, long pos, byte[] buff, int off, int length)
-            throws NotFoundException, Exception {
-        
-        // Assuming that from and to store use the same BlobStore instance
-        return rsTo.getBlob(blobId, pos, buff, off, length);
-    }
-
-    public long getBlobLength(String blobId) throws NotFoundException,
-            Exception {
-        
-        // Assuming that from and to store use the same BlobStore instance
-        return rsTo.getBlobLength(blobId);
-    }
-
-    public String putBlob(InputStream in) throws Exception {
-        // Assuming that from and to store use the same BlobStore instance
-        return rsTo.putBlob(in);
-    }
 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
Thu Mar 22 15:45:31 2012
@@ -16,8 +16,11 @@
  */
 package org.apache.jackrabbit.mk.store;
 
-import org.apache.jackrabbit.mk.blobs.BlobStore;
-import org.apache.jackrabbit.mk.blobs.FileBlobStore;
+import java.io.Closeable;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Id;
 import org.apache.jackrabbit.mk.model.MutableCommit;
@@ -26,15 +29,9 @@ import org.apache.jackrabbit.mk.model.No
 import org.apache.jackrabbit.mk.model.StoredCommit;
 import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.persistence.Persistence;
+import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.SimpleLRUCache;
 
-import java.io.Closeable;
-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>Persistence</code>
  * and a <code>BlobStore</code>, respectively and providing caching. 
@@ -45,34 +42,24 @@ public class DefaultRevisionStore implem
     public static final int DEFAULT_CACHE_SIZE = 10000;
 
     private boolean initialized;
-    private File homeDir;
     private Id head;
     private long headCounter;
     private final ReentrantReadWriteLock headLock = new ReentrantReadWriteLock();
-    private Persistence pm;
-    private BlobStore blobStore;
-    private boolean blobStoreNeedsClose;
+    private final Persistence pm;
 
     private Map<Id, Object> cache;
 
-    public void initialize(File homeDir, Persistence persistence) throws Exception {
+    public DefaultRevisionStore(Persistence pm) {
+        this.pm = pm;
+    }
+    
+    public void initialize() throws Exception {
         if (initialized) {
             throw new IllegalStateException("already initialized");
         }
-        this.homeDir = homeDir;
 
         cache = Collections.synchronizedMap(SimpleLRUCache.<Id, Object>newInstance(determineInitialCacheSize()));
 
-        pm = persistence;
-        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
         head = pm.readHead();
         if (head == null || head.getBytes().length == 0) {
@@ -97,12 +84,9 @@ public class DefaultRevisionStore implem
         verifyInitialized();
 
         cache.clear();
-
-        if (blobStoreNeedsClose) {
-            blobStore.close();
+        if (pm instanceof Closeable) {
+            IOUtils.closeQuietly((Closeable) pm);
         }
-        pm.close();
-        
         initialized = false;
     }
 
@@ -220,12 +204,6 @@ public class DefaultRevisionStore implem
         headLock.writeLock().unlock();
     }
 
-    public String putBlob(InputStream in) throws Exception {
-        verifyInitialized();
-
-        return blobStore.writeBlob(in);
-    }
-
     //-----------------------------------------------------< RevisionProvider >
 
     public NodeState getNodeState(StoredNode node) {
@@ -299,21 +277,4 @@ public class DefaultRevisionStore implem
             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);
-    }
-    
-    @Override
-    public String toString() {
-        return homeDir.toString();
-    }
 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
Thu Mar 22 15:45:31 2012
@@ -23,7 +23,7 @@ import org.apache.jackrabbit.mk.model.St
 import org.apache.jackrabbit.mk.model.StoredNode;
 
 /**
- *
+ * Read operations.
  */
 public interface RevisionProvider {
 
@@ -50,6 +50,4 @@ public interface RevisionProvider {
     StoredNode getRootNode(Id commitId) throws NotFoundException, Exception;
     StoredCommit getHeadCommit() throws Exception;
     Id getHeadCommitId() throws Exception;
-    int getBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException,
Exception;
-    long getBlobLength(String blobId) throws NotFoundException, Exception;
 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
Thu Mar 22 15:45:31 2012
@@ -21,10 +21,8 @@ import org.apache.jackrabbit.mk.model.Id
 import org.apache.jackrabbit.mk.model.MutableCommit;
 import org.apache.jackrabbit.mk.model.MutableNode;
 
-import java.io.InputStream;
-
 /**
- *
+ * Write operations.
  */
 public interface RevisionStore extends RevisionProvider {
 
@@ -53,6 +51,4 @@ public interface RevisionStore extends R
      * Unlock the head.
      */
     void unlockHead();
-    
-    String /*id*/ putBlob(InputStream in) throws Exception;
 }

Modified: jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java?rev=1303850&r1=1303849&r2=1303850&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java
Thu Mar 22 15:45:31 2012
@@ -19,10 +19,9 @@ package org.apache.jackrabbit.mk.store;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
-import java.io.File;
-
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.mk.core.Repository;
 import org.apache.jackrabbit.mk.fs.FileUtils;
@@ -61,11 +60,11 @@ public class CopyingGCTest {
     @Ignore
     @Test
     public void concurrentGC() throws Exception {
-        rsFrom = new DefaultRevisionStore();
-        rsFrom.initialize(new File("target/mk1"), new InMemPersistence());
+        rsFrom = new DefaultRevisionStore(new InMemPersistence());
+        rsFrom.initialize();
 
-        rsTo = new DefaultRevisionStore(); 
-        rsTo.initialize(new File("target/mk2"), new InMemPersistence());
+        rsTo = new DefaultRevisionStore(new InMemPersistence()); 
+        rsTo.initialize();
 
         final CopyingGC gc = new CopyingGC(rsFrom, rsTo);
         
@@ -80,7 +79,7 @@ public class CopyingGCTest {
         });
         t.setDaemon(true);
 
-        MicroKernel mk = new MicroKernelImpl(new Repository(gc));
+        MicroKernel mk = new MicroKernelImpl(new Repository(gc, new MemoryBlobStore()));
         mk.commit("/", "+\"a\" : { \"b\" : { \"c\" : { \"d\" : {} } } }", mk.getHeadRevision(),
null);
         
         t.start();
@@ -100,15 +99,15 @@ public class CopyingGCTest {
     public void copyHeadRevisionToNewStore() throws Exception {
         String[] revs = new String[5];
         
-        rsFrom = new DefaultRevisionStore();
-        rsFrom.initialize(new File("target/mk1"), new InMemPersistence());
+        rsFrom = new DefaultRevisionStore(new InMemPersistence());
+        rsFrom.initialize();
 
-        rsTo = new DefaultRevisionStore(); 
-        rsTo.initialize(new File("target/mk2"), new InMemPersistence());
+        rsTo = new DefaultRevisionStore(new InMemPersistence()); 
+        rsTo.initialize();
 
         CopyingGC gc = new CopyingGC(rsFrom, rsTo);
         
-        MicroKernel mk = new MicroKernelImpl(new Repository(gc));
+        MicroKernel mk = new MicroKernelImpl(new Repository(gc, new MemoryBlobStore()));
         revs[0] = mk.commit("/", "+\"a\" : { \"c\":{}, \"d\":{} }", mk.getHeadRevision(),
null);
         revs[1] = mk.commit("/", "+\"b\" : {}", mk.getHeadRevision(), null);
         revs[2] = mk.commit("/b", "+\"e\" : {}", mk.getHeadRevision(), null);



Mime
View raw message