jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r543813 - in /jackrabbit/trunk/jackrabbit-jcr-rmi: ./ src/main/java/org/apache/jackrabbit/rmi/client/ src/main/java/org/apache/jackrabbit/rmi/servlet/
Date Sun, 03 Jun 2007 00:38:44 GMT
Author: jukka
Date: Sat Jun  2 17:38:43 2007
New Revision: 543813

URL: http://svn.apache.org/viewvc?view=rev&rev=543813
Log:
JCR-956: Repository access and binding servlets for RMI

Added:
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepository.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepositoryFactory.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIBindingServlet.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIRepositoryServlet.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml?view=diff&rev=543813&r1=543812&r2=543813
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml Sat Jun  2 17:38:43 2007
@@ -88,6 +88,10 @@
       <artifactId>jcr</artifactId>
     </dependency>
     <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-api</artifactId>
       <optional>true</optional>

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepository.java?view=auto&rev=543813
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepository.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepository.java
Sat Jun  2 17:38:43 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.rmi.client;
+
+import org.apache.jackrabbit.commons.repository.ProxyRepository;
+
+/**
+ * Proxy for a remote repository bound in RMI. The configured repository is
+ * looked up from RMI lazily during each method call. Thus the RMI entry
+ * does not need to exist when this class is instantiated. The RMI entry
+ * can also be replaced with another repository during the lifetime of an
+ * instance of this class.
+ *
+ * @since 1.4
+ */
+public class RMIRepository extends ProxyRepository {
+
+    /**
+     * Creates a proxy for the remote repository in the given RMI URL.
+     *
+     * @param url RMI URL of the remote repository
+     */
+    public RMIRepository(String url) {
+        super(new RMIRepositoryFactory(url));
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepositoryFactory.java?view=auto&rev=543813
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepositoryFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepositoryFactory.java
Sat Jun  2 17:38:43 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.rmi.client;
+
+import java.net.MalformedURLException;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.commons.repository.RepositoryFactory;
+
+/**
+ * Factory that looks up a repository from JNDI.
+ *
+ * @since 1.4
+ */
+public class RMIRepositoryFactory implements RepositoryFactory {
+
+    /**
+     * RMI URL of the repository.
+     */
+    private final String url;
+
+    /**
+     * Creates a factory for looking up a repository from the given RMI URL.
+     *
+     * @param url RMI URL of the repository
+     */
+    public RMIRepositoryFactory(String url) {
+        this.url = url;
+    }
+
+    /**
+     * Looks up and returns a repository from the configured RMI URL.
+     *
+     * @return local adapter for the remote repository
+     * @throws RepositoryException if the repository could not be accessed
+     */
+    public Repository getRepository() throws RepositoryException {
+        try {
+            return new ClientRepositoryFactory().getRepository(url);
+        } catch (MalformedURLException e) {
+            throw new RepositoryException("Invalid repository URL: " + url, e);
+        } catch (NotBoundException e) {
+            throw new RepositoryException("Repository not found: " + url, e);
+        } catch (ClassCastException e) {
+            throw new RepositoryException("Invalid repository: " + url, e);
+        } catch (RemoteException e) {
+            throw new RepositoryException("Repository access error: " + url, e);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/RMIRepositoryFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIBindingServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIBindingServlet.java?view=auto&rev=543813
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIBindingServlet.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIBindingServlet.java
Sat Jun  2 17:38:43 2007
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.rmi.servlet;
+
+import java.net.MalformedURLException;
+import java.rmi.AlreadyBoundException;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+
+import org.apache.jackrabbit.commons.servlet.ServletRepository;
+import org.apache.jackrabbit.rmi.server.RemoteAdapterFactory;
+import org.apache.jackrabbit.rmi.server.ServerAdapterFactory;
+
+/**
+ * Servlet that binds a repository from a servlet context attribute in RMI.
+ * <p>
+ * The initialization parameters of this servlet are:
+ * <dl>
+ *   <dt>javax.jcr.Repository</dt>
+ *   <dd>
+ *     Name of the servlet context attribute that contains the repository.
+ *     The default value is "<code>javax.jcr.Repository</code>".
+ *   </dd>
+ *   <dt>org.apache.jackrabbit.rmi.server.RemoteAdapterFactory</dt>
+ *   <dd>
+ *     Name of the remote adapter factory class used to create the remote
+ *     repository reference. The configured class should have public
+ *     constructor that takes no arguments. The default value is
+ *     "<code>org.apache.jackrabbit.rmi.server.ServerAdapterFactory</code>".
+ *   </dd>
+ *   <dt>url</dt>
+ *   <dd>
+ *     RMI URL where to bind the repository in. The default value is
+ *     "<code>//localhost/javax/jcr/Repository</code>".
+ *   </dd>
+ * </dl>
+ *
+ * @since 1.4
+ */
+public class RMIBindingServlet extends HttpServlet {
+
+    /**
+     * Serial version UID.
+     */
+    private static final long serialVersionUID = -207084931471893942L;
+
+    /**
+     * Location of the repository within the JNDI context.
+     */
+    private String url;
+
+    /**
+     * The remote repository reference. Kept to avoid it from being
+     * collected as garbage when no clients are connected.
+     */
+    private Remote remote;
+
+    /**
+     * Binds a repository from the servlet context in the configured RMI URL.
+     *
+     * @throws ServletException if the repository could not be bound in RMI
+     */
+    public void init() throws ServletException {
+        url = getInitParameter("url");
+        if (url == null) {
+            url = "//localhost/javax/jcr/Repository";
+        }
+
+        try {
+            RemoteAdapterFactory factory = getRemoteAdapterFactory();
+            remote = factory.getRemoteRepository(new ServletRepository(this));
+        } catch (RemoteException e) {
+            throw new ServletException(
+                    "Failed to create the remote repository reference", e);
+        }
+
+        try {
+            Naming.bind(url, remote);
+        } catch (MalformedURLException e) {
+            throw new ServletException("Invalid RMI URL: " + url, e);
+        } catch (AlreadyBoundException e) {
+            throw new ServletException(
+                    "RMI URL is already bound: " + url, e);
+        } catch (RemoteException e) {
+            throw new ServletException(
+                    "Failed to bind repository to RMI: " + url, e);
+        }
+    }
+
+    /**
+     * Instantiates and returns the configured remote adapter factory.
+     *
+     * @return remote adapter factory
+     * @throws ServletException if the factory could not be instantiated
+     */
+    private RemoteAdapterFactory getRemoteAdapterFactory()
+            throws ServletException {
+        String name = getInitParameter(RemoteAdapterFactory.class.getName());
+        if (name == null) {
+            name = ServerAdapterFactory.class.getName();
+        }
+        try {
+            Class factoryClass = Class.forName(name);
+            return (RemoteAdapterFactory) factoryClass.newInstance();
+        } catch (ClassNotFoundException e) {
+            throw new ServletException(
+                    "Remote adapter factory class not found: " + name, e);
+        } catch (InstantiationException e) {
+            throw new ServletException(
+                    "Failed to instantiate the adapter factory: " + name, e);
+        } catch (IllegalAccessException e) {
+            throw new ServletException(
+                    "Adapter factory constructor is not public: " + name, e);
+        } catch (ClassCastException e) {
+            throw new ServletException(
+                    "Invalid remote adapter factory class: " + name, e);
+        }
+    }
+
+    /**
+     * Unbinds the repository from RMI.
+     */
+    public void destroy() {
+        try {
+            remote = null;
+            Naming.unbind(url);
+        } catch (MalformedURLException e) {
+            log("Invalid RMI URL: " + url, e);
+        } catch (NotBoundException e) {
+            log("Repository not bound in RMI: " + url, e);
+        } catch (RemoteException e) {
+            log("Failed to unbind repository from RMI: " + url, e);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIBindingServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIRepositoryServlet.java?view=auto&rev=543813
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIRepositoryServlet.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIRepositoryServlet.java
Sat Jun  2 17:38:43 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.rmi.servlet;
+
+import javax.jcr.Repository;
+import javax.servlet.ServletException;
+
+import org.apache.jackrabbit.commons.servlet.AbstractRepositoryServlet;
+import org.apache.jackrabbit.rmi.client.RMIRepository;
+
+/**
+ * Servlet that makes a repository from RMI available as an attribute
+ * in the servlet context.
+ * <p>
+ * The supported initialization parameters of this servlet are:
+ * <dl>
+ *   <dt>javax.jcr.Repository</dt>
+ *   <dd>
+ *     Name of the servlet context attribute to put the repository in.
+ *     The default value is "<code>javax.jcr.Repository</code>".
+ *   </dd>
+ *   <dt>url</dt>
+ *   <dd>
+ *     RMI URL of the remote repository. The default value is
+ *     "<code>//localhost/javax/jcr/Repository</code>".
+ *   </dd>
+ * </dl>
+ * <p>
+ * This servlet can also be mapped to the URL space. See
+ * {@link AbstractRepositoryServlet} for the details.
+ *
+ * @since 1.4
+ */
+public class RMIRepositoryServlet extends AbstractRepositoryServlet {
+
+    /**
+     * Serial version UID.
+     */
+    private static final long serialVersionUID = 3361176460018801671L;
+
+    /**
+     * Creates and returns an RMI repository proxy for the configured RMI URL.
+     *
+     * @return RMI repository proxy
+     */
+    protected Repository getRepository() throws ServletException {
+        return new RMIRepository(
+                getInitParameter("url", "//localhost/javax/jcr/Repository"));
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/servlet/RMIRepositoryServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message