jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1346965 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/mk/wrapper/ test/java/org/apache/jackrabbit/mk/wrapper/
Date Wed, 06 Jun 2012 16:06:56 GMT
Author: stefan
Date: Wed Jun  6 16:06:55 2012
New Revision: 1346965

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

fixed regression:
 
 Running org.apache.jackrabbit.mk.wrapper.VirtualRepositoryWrapperTest
 java.lang.IllegalArgumentException: instance was not created by this factory
 	at org.apache.jackrabbit.mk.MicroKernelFactory.disposeInstance(MicroKernelFactory.java:211)
 	at org.apache.jackrabbit.mk.wrapper.VirtualRepositoryWrapper.dispose(VirtualRepositoryWrapper.java:231)
 	at org.apache.jackrabbit.mk.MicroKernelFactory$3.dispose(MicroKernelFactory.java:146)
 	at org.apache.jackrabbit.mk.MicroKernelFactory.disposeInstance(MicroKernelFactory.java:207)
 	at org.apache.jackrabbit.mk.wrapper.VirtualRepositoryWrapperTest.tearDown(VirtualRepositoryWrapperTest.java:71)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.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/VirtualRepositoryWrapperTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java?rev=1346965&r1=1346964&r2=1346965&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
Wed Jun  6 16:06:55 2012
@@ -67,125 +67,151 @@ public abstract class MicroKernelWrapper
      * @return the wrapped instance
      */
     public static MicroKernelWrapper wrap(final MicroKernel mk) {
-        if (mk instanceof MicroKernelWrapper) {
+        if (mk instanceof MicroKernelWrapperImpl) {
             return (MicroKernelWrapper) mk;
         }
-        return new MicroKernelWrapper() {
+        return new MicroKernelWrapperImpl(mk);
+    }
 
-            MicroKernel wrapped = mk;
+    /**
+     * Unwrap a wrapped MicroKernel implementation previously created by
+     * {@link #wrap};
+     *
+     * @param wrapper the MicroKernel wrapper to unwrap
+     * @return the unwrapped instance
+     * @throws IllegalArgumentException if the specified instance was not
+     * originally returned by {@link #wrap}.
+     */
+    public static MicroKernel unwrap(final MicroKernelWrapper wrapper) {
+        if (wrapper instanceof MicroKernelWrapperImpl) {
+            return ((MicroKernelWrapperImpl) wrapper).getWrapped();
+        }
+        throw new IllegalArgumentException("wrapper instance was not created by this factory");
+    }
 
-            @Override
-            public String commitStream(String path, JsopReader jsonDiff, String revisionId,
String message) {
-                return wrapped.commit(path, jsonDiff.toString(), revisionId, message);
-            }
+    private static class MicroKernelWrapperImpl implements MicroKernelWrapper {
 
-            @Override
-            public JsopReader getJournalStream(String fromRevisionId, String toRevisionId,
String path) {
-                return new JsopTokenizer(wrapped.getJournal(fromRevisionId, toRevisionId,
path));
-            }
+        final MicroKernel wrapped;
 
-            @Override
-            public JsopReader getNodesStream(String path, String revisionId) {
-                String json = wrapped.getNodes(path, revisionId, 1, 0, -1, null);
-                if (json != null) {
-                    return new JsopTokenizer(json);
-                } else {
-                    return null;
-                }
-            }
+        private MicroKernelWrapperImpl(MicroKernel mk) {
+            wrapped = mk;
+        }
 
-            @Override
-            public JsopReader getNodesStream(String path, String revisionId, int depth, long
offset, int count, String filter) {
-                String json = wrapped.getNodes(
-                        path, revisionId, depth, offset, count, filter);
-                if (json != null) {
-                    return new JsopTokenizer(json);
-                } else {
-                    return null;
-                }
-            }
+        private MicroKernel getWrapped() {
+            return wrapped;
+        }
 
-            @Override
-            public JsopReader getRevisionsStream(long since, int maxEntries, String path)
{
-                return new JsopTokenizer(wrapped.getRevisionHistory(since, maxEntries, path));
-            }
+        @Override
+        public String commitStream(String path, JsopReader jsonDiff, String revisionId, String
message) {
+            return wrapped.commit(path, jsonDiff.toString(), revisionId, message);
+        }
 
-            @Override
-            public JsopReader diffStream(String fromRevisionId, String toRevisionId, String
path) {
-                return new JsopTokenizer(wrapped.diff(fromRevisionId, toRevisionId, path));
-            }
+        @Override
+        public JsopReader getJournalStream(String fromRevisionId, String toRevisionId, String
path) {
+            return new JsopTokenizer(wrapped.getJournal(fromRevisionId, toRevisionId, path));
+        }
 
-            @Override
-            public String commit(String path, String jsonDiff, String revisionId, String
message) {
-                return wrapped.commit(path, jsonDiff, revisionId, message);
+        @Override
+        public JsopReader getNodesStream(String path, String revisionId) {
+            String json = wrapped.getNodes(path, revisionId, 1, 0, -1, null);
+            if (json != null) {
+                return new JsopTokenizer(json);
+            } else {
+                return null;
             }
+        }
 
-            @Override
-            public String branch(String trunkRevisionId) {
-                return wrapped.branch(trunkRevisionId);
+        @Override
+        public JsopReader getNodesStream(String path, String revisionId, int depth, long
offset, int count, String filter) {
+            String json = wrapped.getNodes(
+                    path, revisionId, depth, offset, count, filter);
+            if (json != null) {
+                return new JsopTokenizer(json);
+            } else {
+                return null;
             }
+        }
 
-            @Override
-            public String merge(String branchRevisionId, String message) {
-                return wrapped.merge(branchRevisionId, message);
-            }
+        @Override
+        public JsopReader getRevisionsStream(long since, int maxEntries, String path) {
+            return new JsopTokenizer(wrapped.getRevisionHistory(since, maxEntries, path));
+        }
 
-            @Override
-            public String diff(String fromRevisionId, String toRevisionId, String path) {
-                return wrapped.diff(fromRevisionId, toRevisionId, path);
-            }
+        @Override
+        public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path)
{
+            return new JsopTokenizer(wrapped.diff(fromRevisionId, toRevisionId, path));
+        }
 
-            @Override
-            public String getHeadRevision() throws MicroKernelException {
-                return wrapped.getHeadRevision();
-            }
+        @Override
+        public String commit(String path, String jsonDiff, String revisionId, String message)
{
+            return wrapped.commit(path, jsonDiff, revisionId, message);
+        }
 
-            @Override
-            public String getJournal(String fromRevisionId, String toRevisionId, String path)
{
-                return wrapped.getJournal(fromRevisionId, toRevisionId, path);
-            }
+        @Override
+        public String branch(String trunkRevisionId) {
+            return wrapped.branch(trunkRevisionId);
+        }
 
-            @Override
-            public long getLength(String blobId) {
-                return wrapped.getLength(blobId);
-            }
+        @Override
+        public String merge(String branchRevisionId, String message) {
+            return wrapped.merge(branchRevisionId, message);
+        }
 
-            @Override
-            public String getNodes(String path, String revisionId, int depth, long offset,
int maxChildNodes, String filter) {
-                return wrapped.getNodes(path, revisionId, depth, offset, maxChildNodes, filter);
-            }
+        @Override
+        public String diff(String fromRevisionId, String toRevisionId, String path) {
+            return wrapped.diff(fromRevisionId, toRevisionId, path);
+        }
 
-            @Override
-            public String getRevisionHistory(long since, int maxEntries, String path) {
-                return wrapped.getRevisionHistory(since, maxEntries, path);
-            }
+        @Override
+        public String getHeadRevision() throws MicroKernelException {
+            return wrapped.getHeadRevision();
+        }
 
-            @Override
-            public boolean nodeExists(String path, String revisionId) {
-                return wrapped.nodeExists(path, revisionId);
-            }
+        @Override
+        public String getJournal(String fromRevisionId, String toRevisionId, String path)
{
+            return wrapped.getJournal(fromRevisionId, toRevisionId, path);
+        }
 
-            @Override
-            public long getChildNodeCount(String path, String revisionId) {
-                return wrapped.getChildNodeCount(path, revisionId);
-            }
+        @Override
+        public long getLength(String blobId) {
+            return wrapped.getLength(blobId);
+        }
 
-            @Override
-            public int read(String blobId, long pos, byte[] buff, int off, int length) {
-                return wrapped.read(blobId, pos, buff, off, length);
-            }
+        @Override
+        public String getNodes(String path, String revisionId, int depth, long offset, int
maxChildNodes, String filter) {
+            return wrapped.getNodes(path, revisionId, depth, offset, maxChildNodes, filter);
+        }
 
-            @Override
-            public String waitForCommit(String oldHeadRevisionId, long maxWaitMillis) throws
InterruptedException {
-                return wrapped.waitForCommit(oldHeadRevisionId, maxWaitMillis);
-            }
+        @Override
+        public String getRevisionHistory(long since, int maxEntries, String path) {
+            return wrapped.getRevisionHistory(since, maxEntries, path);
+        }
 
-            @Override
-            public String write(InputStream in) {
-                return wrapped.write(in);
-            }
+        @Override
+        public boolean nodeExists(String path, String revisionId) {
+            return wrapped.nodeExists(path, revisionId);
+        }
+
+        @Override
+        public long getChildNodeCount(String path, String revisionId) {
+            return wrapped.getChildNodeCount(path, revisionId);
+        }
+
+        @Override
+        public int read(String blobId, long pos, byte[] buff, int off, int length) {
+            return wrapped.read(blobId, pos, buff, off, length);
+        }
+
+        @Override
+        public String waitForCommit(String oldHeadRevisionId, long maxWaitMillis) throws
InterruptedException {
+            return wrapped.waitForCommit(oldHeadRevisionId, maxWaitMillis);
+        }
+
+        @Override
+        public String write(InputStream in) {
+            return wrapped.write(in);
+        }
 
-        };
     }
 
 }

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=1346965&r1=1346964&r2=1346965&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
Wed Jun  6 16:06:55 2012
@@ -227,8 +227,8 @@ public class VirtualRepositoryWrapper ex
     }
 
     public void dispose() {
-        for (MicroKernel m : mounts.values()) {
-            MicroKernelFactory.disposeInstance(m);
+        for (MicroKernelWrapper wrapper : mounts.values()) {
+            MicroKernelFactory.disposeInstance(MicroKernelWrapperBase.unwrap(wrapper));
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java?rev=1346965&r1=1346964&r2=1346965&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java
Wed Jun  6 16:06:55 2012
@@ -70,12 +70,8 @@ public class VirtualRepositoryWrapperTes
             if (mkVirtual != null) {
                 MicroKernelFactory.disposeInstance(mkVirtual);
             }
-            if (mkRep1 != null) {
-                MicroKernelFactory.disposeInstance(mkRep1);
-            }
-            if (mkRep2 != null) {
-                MicroKernelFactory.disposeInstance(mkRep2);
-            }
+            MicroKernelFactory.disposeInstance(mkRep1);
+            MicroKernelFactory.disposeInstance(mkRep2);
             super.tearDown();
         } catch (Throwable e) {
             e.printStackTrace();



Mime
View raw message