You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2014/07/09 14:14:53 UTC

svn commit: r1609126 - in /jackrabbit/oak/trunk/oak-run/src/main: groovy/org/apache/jackrabbit/oak/console/GroovyConsole.groovy java/org/apache/jackrabbit/oak/console/Console.java

Author: chetanm
Date: Wed Jul  9 12:14:53 2014
New Revision: 1609126

URL: http://svn.apache.org/r1609126
Log:
OAK-1960 - Console in Oak Run does not close the NodeStore upon exit

Used the Fixture pattern where the Fixture would be closed via shutdown hook

Modified:
    jackrabbit/oak/trunk/oak-run/src/main/groovy/org/apache/jackrabbit/oak/console/GroovyConsole.groovy
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java

Modified: jackrabbit/oak/trunk/oak-run/src/main/groovy/org/apache/jackrabbit/oak/console/GroovyConsole.groovy
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/groovy/org/apache/jackrabbit/oak/console/GroovyConsole.groovy?rev=1609126&r1=1609125&r2=1609126&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/groovy/org/apache/jackrabbit/oak/console/GroovyConsole.groovy (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/groovy/org/apache/jackrabbit/oak/console/GroovyConsole.groovy Wed Jul  9 12:14:53 2014
@@ -52,7 +52,7 @@ class GroovyConsole {
     private final Groovysh shell
     private final IO io;
 
-    GroovyConsole(ConsoleSession session, IO io) {
+    GroovyConsole(ConsoleSession session, IO io, Closeable closeable) {
         this.session = session
         this.io = io
         this.shell = prepareShell()
@@ -60,6 +60,7 @@ class GroovyConsole {
             if (shell.history) {
                 shell.history.flush()
             }
+            closeable.close()
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java?rev=1609126&r1=1609125&r2=1609126&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java Wed Jul  9 12:14:53 2014
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.oak.console;
 
+import java.io.Closeable;
 import java.io.File;
+import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
 
@@ -26,8 +28,10 @@ import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
 import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
 import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentStore;
 import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.codehaus.groovy.tools.shell.IO;
@@ -61,7 +65,7 @@ public class Console {
             System.exit(1);
         }
 
-        NodeStore store;
+        NodeStoreFixture fixture;
         if (nonOptions.get(0).startsWith(MongoURI.MONGODB_PREFIX)) {
             MongoClientURI uri = new MongoClientURI(nonOptions.get(0));
             if (uri.getDatabase() == null) {
@@ -69,11 +73,12 @@ public class Console {
                 System.exit(1);
             }
             MongoConnection mongo = new MongoConnection(uri.getURI());
-            store = new DocumentMK.Builder().
+            DocumentNodeStore store = new DocumentMK.Builder().
                     setMongoDB(mongo.getDB()).
                     setClusterId(clusterId.value(options)).getNodeStore();
+            fixture = new MongoFixture(store);
         } else {
-            store = new SegmentNodeStore(new FileStore(
+            fixture = new SegmentFixture(new FileStore(
                     new File(nonOptions.get(0)), 256));
         }
         
@@ -88,7 +93,7 @@ public class Console {
         }
 
         GroovyConsole console =
-                new GroovyConsole(ConsoleSession.create(store), new IO());
+                new GroovyConsole(ConsoleSession.create(fixture.getStore()), new IO(), fixture);
 
         int code = 0;
         if(!scriptArgs.isEmpty()){
@@ -101,4 +106,46 @@ public class Console {
 
         System.exit(code);
     }
+
+    private static interface NodeStoreFixture extends Closeable{
+        NodeStore getStore();
+    }
+
+    private static class MongoFixture implements NodeStoreFixture {
+        private final DocumentNodeStore nodeStore;
+
+        private MongoFixture(DocumentNodeStore nodeStore) {
+            this.nodeStore = nodeStore;
+        }
+
+        @Override
+        public NodeStore getStore() {
+            return nodeStore;
+        }
+
+        @Override
+        public void close() throws IOException {
+            nodeStore.dispose();
+        }
+    }
+
+    private static class SegmentFixture implements NodeStoreFixture {
+        private final SegmentStore segmentStore;
+        private final SegmentNodeStore nodeStore;
+
+        private SegmentFixture(SegmentStore segmentStore) {
+            this.segmentStore = segmentStore;
+            this.nodeStore = new SegmentNodeStore(segmentStore);
+        }
+
+        @Override
+        public NodeStore getStore() {
+            return nodeStore;
+        }
+
+        @Override
+        public void close() throws IOException {
+            segmentStore.close();
+        }
+    }
 }