jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1309712 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk: MicroKernelFactory.java client/Client.java index/IndexWrapper.java wrapper/LogWrapper.java
Date Thu, 05 Apr 2012 09:18:46 GMT
Author: jukka
Date: Thu Apr  5 09:18:45 2012
New Revision: 1309712

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

Inline more factory methods in to MicroKernelFactory

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/client/Client.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.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=1309712&r1=1309711&r2=1309712&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:18:45 2012
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.mk.client.C
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.mk.fs.FileUtils;
 import org.apache.jackrabbit.mk.index.IndexWrapper;
+import org.apache.jackrabbit.mk.server.Server;
 import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
 import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.wrapper.LogWrapper;
@@ -86,13 +87,13 @@ public class MicroKernelFactory {
             }
             return instance;
         } else if (url.startsWith("log:")) {
-            return LogWrapper.get(url);
+            return new LogWrapper(getInstance(url.substring("log:".length())));
         } else if (url.startsWith("sec:")) {
             return SecurityWrapper.get(url);
         } else if (url.startsWith("virtual:")) {
             return VirtualRepositoryWrapper.get(url);
         } else if (url.startsWith("index:")) {
-            return IndexWrapper.get(url);
+            return new IndexWrapper(getInstance(url.substring("index:".length())));
         } else if (url.startsWith("fs:")) {
             boolean clean = false;
             if (url.endsWith(";clean")) {
@@ -110,10 +111,24 @@ public class MicroKernelFactory {
             }
             return new MicroKernelImpl(dir);
         } else if (url.startsWith("http:")) {
-            return Client.createHttpClient(url);
+            return new Client(url);
         } else if (url.startsWith("http-bridge:")) {
-            MicroKernel mk = MicroKernelFactory.getInstance(url.substring("http-bridge:".length()));
-            return Client.createHttpBridge(mk);
+            MicroKernel mk = getInstance(url.substring("http-bridge:".length()));
+
+            final Server server = new Server(mk);
+            try {
+                server.start();
+            } catch (IOException e) {
+                throw new IllegalArgumentException(e.getMessage());
+            }
+
+            return new Client(server.getAddress()) {
+                @Override
+                public synchronized void dispose() {
+                    super.dispose();
+                    server.stop();
+                }
+            };
         } else {
             throw new IllegalArgumentException(url);
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java?rev=1309712&r1=1309711&r2=1309712&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java
Thu Apr  5 09:18:45 2012
@@ -28,7 +28,6 @@ import javax.net.SocketFactory;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
-import org.apache.jackrabbit.mk.server.Server;
 import org.apache.jackrabbit.mk.util.IOUtils;
 
 /**
@@ -49,47 +48,32 @@ public class Client implements MicroKern
     private final AtomicBoolean disposed = new AtomicBoolean();
     
     private HttpExecutor executor;
-    
+
     /**
-     * Create a new instance of this class, given a URL to connect to.
+     * Returns the socket address of the given URL.
      * 
-     * @param url url
-     * @return micro kernel
+     * @param url URL
+     * @return socket address
      */
-    public static MicroKernel createHttpClient(String url) {
+    private static InetSocketAddress getAddress(String url) {
         try {
             URI uri = new URI(url);
-            return new Client(new InetSocketAddress(uri.getHost(), uri.getPort()));
+            return new InetSocketAddress(uri.getHost(), uri.getPort());
         } catch (URISyntaxException e) {
-            throw new IllegalArgumentException(e.getMessage());
+            throw new IllegalArgumentException(e);
         }
     }
     
+
     /**
-     * Create a new instance of this class, where every request goes through an HTTP bridge
-     * before being delivered to a given micro kernel implementation.
+     * Create a new instance of this class.
      * 
-     * @param mk micro kernel 
-     * @return bridged micro kernel
+     * @param addr socket address
      */
-    public static MicroKernel createHttpBridge(MicroKernel mk) {
-        final Server server = new Server(mk);
-        
-        try {
-            server.start();
-        } catch (IOException e) {
-            throw new IllegalArgumentException(e.getMessage());
-        }
-
-        return new Client(server.getAddress()) {
-            @Override
-            public synchronized void dispose() {
-                super.dispose();
-                server.stop();
-            }
-        };
+    public Client(String url) {
+        this(getAddress(url));
     }
-    
+
     /**
      * Create a new instance of this class.
      * 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java?rev=1309712&r1=1309711&r2=1309712&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
Thu Apr  5 09:18:45 2012
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.mk.index;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Iterator;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.json.JsopReader;
@@ -53,12 +52,6 @@ public class IndexWrapper extends MicroK
         this.indexer = new Indexer(mk);
     }
 
-    public static synchronized IndexWrapper get(String url) {
-        String u = url.substring("index:".length());
-        IndexWrapper w = new IndexWrapper(MicroKernelFactory.getInstance(u));
-        return w;
-    }
-
     public String getHeadRevision() {
         return mk.getHeadRevision();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java?rev=1309712&r1=1309711&r2=1309712&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
Thu Apr  5 09:18:45 2012
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.mk.wrapper
 
 import java.io.InputStream;
 import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.util.ExceptionFactory;
@@ -38,14 +37,6 @@ public class LogWrapper implements Micro
         this.mk = mk;
     }
 
-    public static synchronized LogWrapper get(String url) {
-        String u = url.substring("log:".length());
-        LogWrapper w = new LogWrapper(MicroKernelFactory.getInstance(u));
-        w.log("MicroKernel mk" + w.id + " = MicroKernelFactory.getInstance("
-                + JsopBuilder.encode(u) + ");");
-        return w;
-    }
-
     public String commit(String path, String jsonDiff, String revisionId, String message)
{
         try {
             logMethod("commit", path, jsonDiff, revisionId, message);



Mime
View raw message