jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1309709 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk: MicroKernelFactory.java simple/SimpleKernelImpl.java
Date Thu, 05 Apr 2012 09:09:48 GMT
Author: jukka
Date: Thu Apr  5 09:09:47 2012
New Revision: 1309709

URL: http://svn.apache.org/viewvc?rev=1309709&view=rev
Log:
OAK-32: Drop MicroKernel.dispose()

Refactor SimpleKernelImpl.get() into MicroKernelFactory to reduce the footprint of factory
code

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java?rev=1309709&r1=1309708&r2=1309709&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
Thu Apr  5 09:09:47 2012
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.mk;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.client.Client;
@@ -34,6 +36,9 @@ import org.apache.jackrabbit.mk.wrapper.
  */
 public class MicroKernelFactory {
 
+    private static final Map<String, SimpleKernelImpl> INSTANCES =
+            new HashMap<String, SimpleKernelImpl>();
+
     /**
      * Get an instance. Supported URLs:
      * <ul>
@@ -47,11 +52,39 @@ public class MicroKernelFactory {
      * @param url the repository URL
      * @return a new instance
      */
-    public static MicroKernel getInstance(String url) {
-        if (url.startsWith("mem:")) {
-            return SimpleKernelImpl.get(url);
-        } else if (url.startsWith("simple:")) {
-                return SimpleKernelImpl.get(url);
+    public static synchronized MicroKernel getInstance(String url) {
+        if (url.startsWith("mem:") || url.startsWith("simple:")) {
+            boolean clean = false;
+            if (url.endsWith(";clean")) {
+                url = url.substring(0, url.length() - ";clean".length());
+                clean = true;
+            }
+
+            url = url.replaceAll("\\{homeDir\\}", System.getProperty("homeDir", "."));
+
+            String name;
+            if (url.startsWith("simple:")) {
+                name = url.substring("simple:".length());
+            } else {
+                name = url.substring("mem:".length());
+            }
+
+            if (clean) {
+                String dir = url.substring(url.lastIndexOf(':') + 1);
+                try {
+                    FileUtils.deleteRecursive(dir, false);
+                } catch (Exception e) {
+                    throw ExceptionFactory.convert(e);
+                }
+                INSTANCES.remove(name);
+            }
+
+            SimpleKernelImpl instance = INSTANCES.get(name);
+            if (instance == null) {
+                instance = new SimpleKernelImpl(name);
+                INSTANCES.put(name, instance);
+            }
+            return instance;
         } else if (url.startsWith("log:")) {
             return LogWrapper.get(url);
         } else if (url.startsWith("sec:")) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java?rev=1309709&r1=1309708&r2=1309709&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
Thu Apr  5 09:09:47 2012
@@ -20,7 +20,6 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.blobs.AbstractBlobStore;
 import org.apache.jackrabbit.mk.blobs.FileBlobStore;
 import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
-import org.apache.jackrabbit.mk.fs.FileUtils;
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopStream;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
@@ -37,7 +36,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 
 /*
 
@@ -62,8 +60,6 @@ Node structure:
  */
 public class SimpleKernelImpl extends MicroKernelWrapperBase implements MicroKernel {
 
-    private static final HashMap<String, SimpleKernelImpl> INSTANCES = new HashMap<String,
SimpleKernelImpl>();
-
     private static final int REV_SKIP_OFFSET = 20;
 
     private final String name;
@@ -122,47 +118,6 @@ public class SimpleKernelImpl extends Mi
         }
     }
 
-    /**
-     * Get or open the object. The following prefixes are supported:
-     * <ul><li>fs: store the binaries in the file system
-     * </li><li>server: also start the server
-     * </li></ul>
-     *
-     * @param url the url
-     * @return the object
-     */
-    public static synchronized SimpleKernelImpl get(String url) {
-        boolean clean = false;
-        if (url.endsWith(";clean")) {
-            url = url.substring(0, url.length() - ";clean".length());
-            clean = true;
-        }
-        url = url.replaceAll("\\{homeDir\\}", System.getProperty("homeDir", "."));
-        if (clean) {
-            String dir = url.substring(url.lastIndexOf(':') + 1);
-            try {
-                FileUtils.deleteRecursive(dir, false);
-            } catch (Exception e) {
-                throw ExceptionFactory.convert(e);
-            }
-        }
-        String name;
-        if (url.startsWith("simple:")) {
-            name = url.substring("simple:".length());
-        } else {
-            name = url.substring("mem:".length());
-        }
-        if (clean) {
-            INSTANCES.remove(name);
-        }
-        SimpleKernelImpl instance = INSTANCES.get(name);
-        if (instance == null) {
-            instance = new SimpleKernelImpl(name);
-            INSTANCES.put(name, instance);
-        }
-        return instance;
-    }
-
     private void applyConfig(NodeImpl head) {
         // /head/config doesn't always exist
         if (head.exists("config")) {
@@ -593,7 +548,6 @@ public class SimpleKernelImpl extends Mi
             gate.commit("end");
             nodeMap.close();
             ds.close();
-            INSTANCES.remove(name);
             if (server != null) {
                 server.stop();
                 server = null;



Mime
View raw message