jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r904425 - in /jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi: Activator.java RepositoryConfigurer.java
Date Fri, 29 Jan 2010 09:01:56 GMT
Author: fmeschbe
Date: Fri Jan 29 09:01:55 2010
New Revision: 904425

URL: http://svn.apache.org/viewvc?rev=904425&view=rev
Log:
Cleanup (and actually enable) repository configuration and startup through OSGi factory configuration
(allows multiple repositories to be started).

Modified:
    jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/Activator.java
    jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/RepositoryConfigurer.java

Modified: jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/Activator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/Activator.java?rev=904425&r1=904424&r2=904425&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/Activator.java
(original)
+++ jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/Activator.java
Fri Jan 29 09:01:55 2010
@@ -42,19 +42,7 @@
     /** default log */
     private static final Logger log = LoggerFactory.getLogger(Activator.class);
 
-    public static final String SERVER_REPOSITORY_FACTORY_PID = "org.apache.sling.jcr.jackrabbit.server.SlingServerRepository";
-
-    /**
-     * The name of the configuration property naming the Sling Context for which
-     * a factory configuration has been created.
-     */
-    public static final String SLING_CONTEXT = "sling.context";
-
-    /**
-     * The name of the framework property containing the default sling context
-     * name.
-     */
-    public static final String SLING_CONTEXT_DEFAULT = "sling.context.default";
+    public static final String SERVER_REPOSITORY_FACTORY_PID = "org.apache.jackrabbit.core.RepositoryFactory";
 
     // The name of the Configuration Admin Service
     private static final String CONFIG_ADMIN_NAME = ConfigurationAdmin.class.getName();
@@ -78,6 +66,9 @@
     // the name of the default sling context
     private String slingContext;
 
+    // the repository configurer ManagedServiceFactory
+    private RepositoryConfigurer repositoryConfigurer;
+
 //    TODO: private static AccessManagerFactoryTracker accessManagerFactoryTracker;
 
     public void start(BundleContext context) {
@@ -88,11 +79,8 @@
         // (theoretically) be non-null after the last bundle stop
         moduleCache = null;
 
-        // check the name of the default context, nothing to do if none
-        slingContext = context.getProperty(SLING_CONTEXT_DEFAULT);
-        if (slingContext == null) {
-            slingContext = "default";
-        }
+        // launch the configurer
+        repositoryConfigurer = new RepositoryConfigurer(bundleContext);
 
         ServiceReference sr = context.getServiceReference(CONFIG_ADMIN_NAME);
         if (sr != null) {
@@ -123,6 +111,12 @@
 
     public void stop(BundleContext arg0) {
 
+        // stop the repository configurer
+        if (repositoryConfigurer != null) {
+            repositoryConfigurer.shutdown();
+            repositoryConfigurer = null;
+        }
+
         // drop module cache
         moduleCache = null;
 
@@ -259,7 +253,6 @@
         if (homeDir == null) return;
 
         // default config values
-        props.put(SLING_CONTEXT, slingContext);
         props.put(RepositoryConfigurer.REPOSITORY_CONFIG_URL,
             getConfig(bundleContext, homeDir));
         props.put(RepositoryConfigurer.REPOSITORY_HOME_DIR, homeDir.getPath());

Modified: jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/RepositoryConfigurer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/RepositoryConfigurer.java?rev=904425&r1=904424&r2=904425&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/RepositoryConfigurer.java
(original)
+++ jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/RepositoryConfigurer.java
Fri Jan 29 09:01:55 2010
@@ -1,13 +1,20 @@
 /*
- * Copyright 1997-2010 Day Management AG
- * Barfuesserplatz 6, 4001 Basel, Switzerland
- * All Rights Reserved.
+ * 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
  *
- * This software is the confidential and proprietary information of
- * Day Management AG, ("Confidential Information"). You shall not
- * disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Day.
+ *   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.core.osgi;
 
@@ -40,6 +47,10 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The <code>RepositoryConfigurer</code> is a ManagedServiceFactory receiving
+ * configurations to managed (start/stop) embedded repository instances.
+ */
 public class RepositoryConfigurer implements ManagedServiceFactory {
 
     /**
@@ -50,8 +61,6 @@
      * "file:" scheme must still be specified.
      * <p>
      * This parameter is mandatory for this activator to start the repository.
-     *
-     * @scr.property value=""
      */
     public static final String REPOSITORY_CONFIG_URL = "config";
 
@@ -60,23 +69,33 @@
      * where the repository files are located (value is "home").
      * <p>
      * This parameter is mandatory for this activator to start the repository.
-     *
-     * @scr.property value=""
      */
     public static final String REPOSITORY_HOME_DIR = "home";
 
     /**
-     * @scr.property value=""
+     * The name of the configuration property defining the name of the
+     * repository.
      */
     public static final String REPOSITORY_REGISTRATION_NAME = "name";
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
+    /**
+     * Map of repositories started by this class. This map is used to update
+     * configured repositories and to shut the repositories down if
+     * configuration is deleted or this services is shut down.
+     */
     private final Map<String, RepositoryHolder> repositories = new ConcurrentHashMap<String,
RepositoryHolder>();
 
+    /**
+     * The BundleContext to register repository services.
+     */
     private final BundleContext bundleContext;
 
+    /**
+     * The OSGi service registration of this configurer
+     */
     private final ServiceRegistration configurerService;
 
     public RepositoryConfigurer(final BundleContext bundleContext) {
@@ -86,6 +105,8 @@
         cfgServiceProps.put(Constants.SERVICE_DESCRIPTION,
             getConfigurerServiceDescription());
         cfgServiceProps.put(Constants.SERVICE_VENDOR, getVendor());
+        cfgServiceProps.put(Constants.SERVICE_PID,
+            Activator.SERVER_REPOSITORY_FACTORY_PID);
 
         configurerService = bundleContext.registerService(
             "org.osgi.service.cm.ManagedServiceFactory", this, cfgServiceProps);
@@ -130,6 +151,43 @@
         return "repository";
     }
 
+    protected InputStream openConfig(final String config)
+            throws FileNotFoundException, IOException {
+
+        // 1. check for an existing file
+        final File configFile = new File(config);
+        if (configFile.isFile() && configFile.canRead()) {
+            log.info("startRepository: Using configuration file {}",
+                configFile.getAbsolutePath());
+            return new FileInputStream(configFile);
+        }
+
+        // 2. check for an URL
+        try {
+
+            final URL configURL = new URL(config);
+            log.info("startRepository: Using configuration URL ", configURL);
+            return configURL.openStream();
+
+        } catch (MalformedURLException mue) {
+            // ignore, just check whether we can copy a default file
+        }
+
+        // 3. config is a file, which we have to prepare yet
+        copyFile(configFile);
+        log.info("startRepository: Using new default configuration file {}",
+            configFile.getAbsolutePath());
+        return new FileInputStream(configFile);
+    }
+
+    protected JackrabbitRepository createRepository(final InputStream config,
+            final String home)
+            throws org.apache.jackrabbit.core.config.ConfigurationException,
+            RepositoryException {
+        final RepositoryConfig crc = RepositoryConfig.create(config, home);
+        return RepositoryImpl.create(crc);
+    }
+
     // ---------- ManagedServiceFactory interface
 
     public final String getName() {
@@ -149,14 +207,7 @@
         }
 
         // start new repository with updated/new configuration
-        try {
-            startRepository(pid, properties);
-        } catch (RepositoryException re) {
-            throw new ConfigurationException(
-                null,
-                "Failed starting repository " + pid + " from new configuration",
-                re);
-        }
+        startRepository(pid, properties);
     }
 
     public final void deleted(final String pid) {
@@ -166,7 +217,8 @@
     // ---------- Repository startup and shutdown
 
     private void startRepository(final String pid,
-            final Dictionary<String, ?> properties) throws ConfigurationException,
RepositoryException {
+            final Dictionary<String, ?> properties)
+            throws ConfigurationException {
 
         final String config = getProperty(properties, REPOSITORY_CONFIG_URL,
             getDefaultRepositoryUrl());
@@ -175,38 +227,8 @@
 
         InputStream ins = null;
         try {
-
-            // check whether the URL is a file path
-            final File configFile = new File(config);
-            if (configFile.canRead()) {
-
-                ins = new FileInputStream(configFile);
-                log.info("startRepository: Using configuration file {}",
-                    configFile.getAbsolutePath());
-
-            } else {
-
-                try {
-
-                    URL configURL = new URL(config);
-                    ins = configURL.openStream();
-                    log.info("startRepository: Using configuration URL ",
-                        configURL);
-
-                } catch (MalformedURLException mue) {
-
-                    // last ressort: URL is a file, which we have to prepare yet
-                    copyFile(configFile);
-                    ins = new FileInputStream(configFile);
-                    log.info(
-                        "startRepository: Using new default configuration file {}",
-                        configFile.getAbsolutePath());
-
-                }
-            }
-
-            final RepositoryConfig crc = RepositoryConfig.create(ins, home);
-            final JackrabbitRepository repository = RepositoryImpl.create(crc);
+            ins = openConfig(config);
+            final JackrabbitRepository repository = createRepository(ins, home);
 
             final Dictionary<String, Object> props = copyProperties(properties);
             props.put(Constants.SERVICE_DESCRIPTION,
@@ -224,11 +246,18 @@
             log.error("startRepository: IO problem starting repository from "
                 + config + " in " + home, ioe);
 
+        } catch (org.apache.jackrabbit.core.config.ConfigurationException ce) {
+
+            log.error(
+                "startRepository: Failed configuring the repository from "
+                    + config + " in " + home, ce);
+
         } catch (RepositoryException re) {
 
             log.error(
                 "startRepository: Repository problem starting repository from "
                     + config + " in " + home, re);
+
         } finally {
             if (ins != null) {
                 try {
@@ -258,7 +287,7 @@
     private String getProperty(final Dictionary<String, ?> properties,
             final String propName, final String defaultValue)
             throws ConfigurationException {
-        final Object propertyObj = properties.get(REPOSITORY_CONFIG_URL);
+        final Object propertyObj = properties.get(propName);
         if (propertyObj == null) {
             return defaultValue;
         }
@@ -273,8 +302,8 @@
         }
 
         // property is not a string
-        throw new ConfigurationException(REPOSITORY_CONFIG_URL,
-            "Repository Configuration URL must be a single string");
+        throw new ConfigurationException(propName,
+            "Property must be a single string value");
     }
 
     private Dictionary<String, Object> copyProperties(
@@ -332,8 +361,7 @@
         private final ServiceRegistration registration;
 
         public RepositoryHolder(final JackrabbitRepository repository,
-
-        final ServiceRegistration registration) {
+                final ServiceRegistration registration) {
             this.repository = repository;
             this.registration = registration;
         }



Mime
View raw message