jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1328631 - in /jackrabbit/oak/trunk/oak-run: pom.xml src/main/java/org/apache/jackrabbit/oak/run/Main.java src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java src/main/resources/ src/main/resources/logback.xml
Date Sat, 21 Apr 2012 10:31:10 GMT
Author: jukka
Date: Sat Apr 21 10:31:10 2012
New Revision: 1328631

URL: http://svn.apache.org/viewvc?rev=1328631&view=rev
Log:
OAK-4: Runnable jar packaging

Support both in-memory and on-disk repositories, add placeholder for clustered ones

Added:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java
      - copied, changed from r1328630, jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
    jackrabbit/oak/trunk/oak-run/src/main/resources/
    jackrabbit/oak/trunk/oak-run/src/main/resources/logback.xml
Modified:
    jackrabbit/oak/trunk/oak-run/pom.xml
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java

Modified: jackrabbit/oak/trunk/oak-run/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/pom.xml?rev=1328631&r1=1328630&r2=1328631&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-run/pom.xml Sat Apr 21 10:31:10 2012
@@ -83,6 +83,11 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>com.h2database</groupId>
+      <artifactId>h2</artifactId>
+      <version>1.3.158</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-jcr-server</artifactId>
       <version>${jackrabbit.version}</version>

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java?rev=1328631&r1=1328630&r2=1328631&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java Sat
Apr 21 10:31:10 2012
@@ -16,13 +16,11 @@
  */
 package org.apache.jackrabbit.oak.run;
 
-import javax.jcr.Repository;
+import java.io.InputStream;
+import java.util.Properties;
+
 import javax.servlet.Servlet;
 
-import org.apache.jackrabbit.mk.core.MicroKernelImpl;
-import org.apache.jackrabbit.oak.jcr.GlobalContext;
-import org.apache.jackrabbit.oak.jcr.RepositoryImpl;
-import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
@@ -30,24 +28,66 @@ import org.eclipse.jetty.servlet.Servlet
 public class Main {
 
     public static void main(String[] args) throws Exception {
-        final Repository repository =
-                new RepositoryImpl(new GlobalContext(new MicroKernelImpl()));
-        Servlet servlet = new JCRWebdavServerServlet() {
-            @Override
-            protected Repository getRepository() {
-                return repository;
-            }
-        };
+        printProductInfo();
 
         ServletContextHandler context =
                 new ServletContextHandler(ServletContextHandler.SECURITY);
         context.setContextPath("/");
-        context.addServlet(new ServletHolder(servlet),"/*");
- 
+
+        if (args.length == 0) {
+            System.out.println("Starting an in-memory repository");
+            System.out.println("http://localhost:8080/ -> [memory]");
+            Servlet servlet = new RepositoryServlet(null);
+            context.addServlet(new ServletHolder(servlet),"/*");
+        } else if (args.length == 1) {
+            System.out.println("Starting a standalone repository");
+            System.out.println("http://localhost:8080/ -> " + args[0]);
+            Servlet servlet = new RepositoryServlet(args[0]);
+            context.addServlet(new ServletHolder(servlet), "/*");
+        } else {
+            System.out.println("Starting a clustered repository");
+            for (int i = 0; i < args.length; i++) {
+                // FIXME: Use a clustered MicroKernel implementation
+                System.out.println(
+                        "http://localhost:8080/node" + i + "/ -> " + args[i]);
+                Servlet servlet = new RepositoryServlet(args[i]);
+                context.addServlet(
+                        new ServletHolder(servlet), "/node" + i + "/*");
+            }
+        }
+
         Server server = new Server(8080);
         server.setHandler(context);
         server.start();
         server.join();
     }
 
+    private static void printProductInfo() {
+        String version = null;
+
+        try {
+            InputStream stream = Main.class.getResourceAsStream(
+                    "/META-INF/maven/org.apache.jackrabbit/oak-run/pom.properties");
+            if (stream != null) {
+                try {
+                    Properties properties = new Properties();
+                    properties.load(stream);
+                    version = properties.getProperty("version");
+                } finally {
+                    stream.close();
+                }
+            }
+        } catch (Exception ignore) {
+        }
+
+        String product;
+        if (version != null) {
+            product = "Apache Jackrabbit Oak " + version;
+        } else {
+            product = "Apache Jackrabbit Oak";
+        }
+
+        System.out.println(product);
+    }
+
 }

Copied: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java
(from r1328630, jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java?p2=jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java&p1=jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java&r1=1328630&r2=1328631&rev=1328631&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java
Sat Apr 21 10:31:10 2012
@@ -17,37 +17,56 @@
 package org.apache.jackrabbit.oak.run;
 
 import javax.jcr.Repository;
-import javax.servlet.Servlet;
+import javax.jcr.RepositoryException;
+import javax.servlet.ServletException;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.oak.jcr.GlobalContext;
 import org.apache.jackrabbit.oak.jcr.RepositoryImpl;
 import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-
-public class Main {
-
-    public static void main(String[] args) throws Exception {
-        final Repository repository =
-                new RepositoryImpl(new GlobalContext(new MicroKernelImpl()));
-        Servlet servlet = new JCRWebdavServerServlet() {
-            @Override
-            protected Repository getRepository() {
-                return repository;
-            }
-        };
-
-        ServletContextHandler context =
-                new ServletContextHandler(ServletContextHandler.SECURITY);
-        context.setContextPath("/");
-        context.addServlet(new ServletHolder(servlet),"/*");
- 
-        Server server = new Server(8080);
-        server.setHandler(context);
-        server.start();
-        server.join();
+
+class RepositoryServlet extends JCRWebdavServerServlet {
+
+    private final String path;
+
+    private MicroKernel kernel;
+
+    private Repository repository;
+
+    public RepositoryServlet(String path) {
+        this.path = path;
+    }
+
+    @Override
+    public void init() throws ServletException {
+        if (path != null) {
+            kernel = new MicroKernelImpl(path);
+        } else {
+            kernel = new MicroKernelImpl();
+        }
+
+        try {
+            repository = new RepositoryImpl(new GlobalContext(kernel));
+        } catch (RepositoryException e) {
+            kernel.dispose();
+            throw new ServletException(
+                    "Failed to start the repository at " + path, e);
+        }
+
+        super.init();
+    }
+
+    @Override
+    protected Repository getRepository() {
+        return repository;
+    }
+
+    @Override
+    public void destroy() {
+        super.destroy();
+
+        kernel.dispose();
     }
 
-}
+}
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-run/src/main/resources/logback.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/resources/logback.xml?rev=1328631&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/resources/logback.xml (added)
+++ jackrabbit/oak/trunk/oak-run/src/main/resources/logback.xml Sat Apr 21 10:31:10 2012
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+  -->
+<configuration>
+
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+    </encoder>
+  </appender>
+
+  <root level="warn">
+    <appender-ref ref="STDOUT" />
+  </root>
+
+</configuration>



Mime
View raw message