jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1309746 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/wrapper/ test/java/org/apache/jackrabbit/mk/wrapper/
Date Thu, 05 Apr 2012 10:50:31 GMT
Author: jukka
Date: Thu Apr  5 10:50:31 2012
New Revision: 1309746

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

Better handling of SimpleKernel and VirtualRepositoryWrapper in MKF

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/wrapper/VirtualRepositoryWrapper.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.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=1309746&r1=1309745&r2=1309746&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 10:50:31 2012
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.client.Client;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.mk.fs.FileUtils;
@@ -53,7 +54,7 @@ public class MicroKernelFactory {
      * @param url the repository URL
      * @return a new instance
      */
-    public static synchronized MicroKernel getInstance(String url) {
+    public static MicroKernel getInstance(String url) {
         int colon = url.indexOf(':');
         if (colon == -1) {
             throw new IllegalArgumentException("Unknown repository URL: " + url);
@@ -89,19 +90,36 @@ public class MicroKernelFactory {
             if (head.equals("fs")) {
                 return new MicroKernelImpl(tail);
             } else {
-                SimpleKernelImpl instance = INSTANCES.get(tail);
-                if (instance == null) {
-                    instance = new SimpleKernelImpl(tail);
-                    INSTANCES.put(tail, instance);
+                final String name = tail;
+                synchronized (INSTANCES) {
+                    SimpleKernelImpl instance = INSTANCES.get(name);
+                    if (instance == null) {
+                        instance = new SimpleKernelImpl(name) {
+                            @Override
+                            public synchronized void dispose() {
+                                super.dispose();
+                                synchronized (INSTANCES) {
+                                    INSTANCES.remove(name);
+                                }
+                            }
+                        };
+                        INSTANCES.put(name, instance);
+                    }
+                    return instance;
                 }
-                return instance;
             }
         } else if (head.equals("log")) {
             return new LogWrapper(getInstance(tail));
         } else if (head.equals("sec")) {
             return SecurityWrapper.get(url);
         } else if (head.equals("virtual")) {
-            return VirtualRepositoryWrapper.get(url);
+            MicroKernel mk = getInstance(tail);
+            try {
+                return new VirtualRepositoryWrapper(mk);
+            } catch (MicroKernelException e) {
+                mk.dispose();
+                throw e;
+            }
         } else if (head.equals("index")) {
             return new IndexWrapper(getInstance(tail));
         } else if (head.equals("http")) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java?rev=1309746&r1=1309745&r2=1309746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
Thu Apr  5 10:50:31 2012
@@ -40,7 +40,6 @@ import org.apache.jackrabbit.mk.util.Pat
  */
 public class VirtualRepositoryWrapper extends MicroKernelWrapperBase implements MicroKernel
{
 
-    private static final String PREFIX = "virtual:";
     private static final String MOUNT = "/:mount";
 
     /**
@@ -74,38 +73,27 @@ public class VirtualRepositoryWrapper ex
 
     private final NodeMap map = new NodeMap();
 
-    private VirtualRepositoryWrapper(MicroKernel mk) {
+    public VirtualRepositoryWrapper(MicroKernel mk) {
         this.mk = MicroKernelWrapperBase.wrap(mk);
-    }
 
-    public static synchronized VirtualRepositoryWrapper get(String url) {
-        String urlMeta = url.substring(PREFIX.length());
-        MicroKernel mk = MicroKernelFactory.getInstance(urlMeta);
-        try {
-            String head = mk.getHeadRevision();
-            VirtualRepositoryWrapper vm = new VirtualRepositoryWrapper(mk);
-            if (mk.nodeExists(MOUNT, head)) {
-                String mounts = mk.getNodes(MOUNT, head);
-                NodeMap map = new NodeMap();
-                JsopReader t = new JsopTokenizer(mounts);
-                t.read('{');
-                NodeImpl n = NodeImpl.parse(map, t, 0);
-                for (long pos = 0;; pos++) {
-                    String childName = n.getChildNodeName(pos);
-                    if (childName == null) {
-                        break;
-                    }
-                    NodeImpl mount = n.getNode(childName);
-                    String mountUrl = JsopTokenizer.decodeQuoted(mount.getProperty("url"));
-                    String[] paths = JsopTokenizer.decodeQuoted(mount.getProperty("paths")).split(",");
-                    vm.addMount(childName, mountUrl, paths);
-                    vm.getHeadRevision();
+        String head = mk.getHeadRevision();
+        if (mk.nodeExists(MOUNT, head)) {
+            String mounts = mk.getNodes(MOUNT, head);
+            NodeMap map = new NodeMap();
+            JsopReader t = new JsopTokenizer(mounts);
+            t.read('{');
+            NodeImpl n = NodeImpl.parse(map, t, 0);
+            for (long pos = 0;; pos++) {
+                String childName = n.getChildNodeName(pos);
+                if (childName == null) {
+                    break;
                 }
+                NodeImpl mount = n.getNode(childName);
+                String mountUrl = JsopTokenizer.decodeQuoted(mount.getProperty("url"));
+                String[] paths = JsopTokenizer.decodeQuoted(mount.getProperty("paths")).split(",");
+                addMount(childName, mountUrl, paths);
+                getHeadRevision();
             }
-            return vm;
-        } catch (MicroKernelException e) {
-            mk.dispose();
-            throw e;
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java?rev=1309746&r1=1309745&r2=1309746&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
Thu Apr  5 10:50:31 2012
@@ -17,8 +17,8 @@
 package org.apache.jackrabbit.mk.wrapper;
 
 import static org.junit.Assert.assertEquals;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
 import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.apache.jackrabbit.mk.index.IndexWrapper;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -39,9 +39,7 @@ public class IndexWrapperTest extends Mu
     @Before
     public void setUp() throws Exception {
         super.setUp();
-        mk.dispose();
-        url = "index:" + url;
-        mk = MicroKernelFactory.getInstance(url);
+        mk = new IndexWrapper(mk);
     }
 
     @Test



Mime
View raw message