servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r602167 - in /servicemix/branches/servicemix-4.0/runtime: main/src/main/java/org/apache/servicemix/main/Main.java minimum/src/main/release/etc/config.properties minimum/src/main/release/etc/startup.properties
Date Fri, 07 Dec 2007 17:55:44 GMT
Author: chirino
Date: Fri Dec  7 09:55:41 2007
New Revision: 602167

URL: http://svn.apache.org/viewvc?rev=602167&view=rev
Log:
Added support for a startup.properties file which can provide more explict control over the
run-level and what is started from the system directroy

Added:
    servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/startup.properties
  (with props)
Modified:
    servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java
    servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/config.properties

Modified: servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java?rev=602167&r1=602166&r2=602167&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java
(original)
+++ servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java
Fri Dec  7 09:55:41 2007
@@ -45,7 +45,7 @@
 **/
 public class Main implements MainService
 {
-    /**
+    /**listed in startup.properties configuration not found
      * The system property name used to specify an URL to the system
      * property file.
     **/
@@ -63,6 +63,10 @@
      * The default name used for the configuration properties file.
     **/
     public static final String CONFIG_PROPERTIES_FILE_VALUE = "config.properties";
+    /**
+     * The default name used for the startup properties file.
+    **/
+    public static final String STARTUP_PROPERTIES_FILE_VALUE = "startup.properties";
     /*
      * The property for auto-discovering the bundles 
      */
@@ -385,13 +389,14 @@
         File bundleDir = null;
 
         // See if the property URL was specified as a property.
-        URL propURL = null;
+        URL configPropURL = null;
+        URL startupPropURL = null;
         String custom = System.getProperty(CONFIG_PROPERTIES_PROP);
         if (custom != null)
         {
             try
             {
-                propURL = new URL(custom);
+                configPropURL = new URL(custom);
             }
             catch (MalformedURLException ex)
             {
@@ -429,7 +434,9 @@
 
             try
             {
-                propURL = new File(confDir, CONFIG_PROPERTIES_FILE_VALUE).toURL();
+                configPropURL = new File(confDir, CONFIG_PROPERTIES_FILE_VALUE).toURL();
+                startupPropURL = new File(confDir, STARTUP_PROPERTIES_FILE_VALUE).toURL();
+                
             }
             catch (MalformedURLException ex)
             {
@@ -438,13 +445,31 @@
             }
         }
 
-        // Read the properties file.
-        Properties props = new Properties();
+        Properties configProps = loadPropertiesFile(configPropURL);
+        Properties startupProps = loadPropertiesFile(startupPropURL);
+        
+        // Perform variable substitution for system properties.
+        for (Enumeration e = configProps.propertyNames(); e.hasMoreElements(); )
+        {
+            String name = (String) e.nextElement();
+            configProps.setProperty(name,
+                substVars(configProps.getProperty(name), name, null, configProps));
+        }
+
+        // Mutate properties
+        Main.processConfigurationProperties(configProps, startupProps, bundleDir);
+
+        return configProps;
+    }
+
+	private static Properties loadPropertiesFile(URL configPropURL) {
+		// Read the properties file.
+        Properties configProps = new Properties();
         InputStream is = null;
         try
         {
-            is = propURL.openConnection().getInputStream();
-            props.load(is);
+            is = configPropURL.openConnection().getInputStream();
+            configProps.load(is);
             is.close();
         }
         catch (FileNotFoundException ex)
@@ -454,7 +479,7 @@
         catch (Exception ex)
         {
             System.err.println(
-                "Error loading config properties from " + propURL);
+                "Error loading config properties from " + configPropURL);
             System.err.println("Main: " + ex);
             try
             {
@@ -466,20 +491,8 @@
             }
             return null;
         }
-
-        // Perform variable substitution for system properties.
-        for (Enumeration e = props.propertyNames(); e.hasMoreElements(); )
-        {
-            String name = (String) e.nextElement();
-            props.setProperty(name,
-                substVars(props.getProperty(name), name, null, props));
-        }
-
-        // Mutate properties
-        Main.processConfigurationProperties(props, bundleDir);
-
-        return props;
-    }
+		return configProps;
+	}
 
     public static void copySystemProperties(Properties configProps)
     {
@@ -498,9 +511,16 @@
 
     /**
      * Process properties to customize default felix behavior
+     * @param startupProps 
      */
-    protected static void processConfigurationProperties(Properties props, File bundleDir)
{
-        if (Boolean.parseBoolean(props.getProperty(PROPERTY_AUTO_START)) && bundleDir
!= null) {
+    protected static void processConfigurationProperties(Properties props, Properties startupProps,
File bundleDir) {
+        if ( bundleDir == null) {
+        	return;
+        }
+        
+        if( "all".equals( props.getProperty(PROPERTY_AUTO_START,"").trim()) ) {
+            props.remove(PROPERTY_AUTO_START);
+            // We should start all the bundles in the system dir.
             File[] bundles = bundleDir.listFiles(new FileFilter() {
                 public boolean accept(File pathname) {
                     return pathname.toString().endsWith(".jar");
@@ -514,9 +534,42 @@
                     System.err.print( "Ignoring " + bundles[i].toString() + " (" + e + ")"
);
                 }
             }
-            props.setProperty("felix.auto.start.1", sb.toString());
+            props.setProperty(PROPERTY_AUTO_START, sb.toString());
+        }
+        else if( STARTUP_PROPERTIES_FILE_VALUE.equals( props.getProperty(PROPERTY_AUTO_START,"").trim())
) {
             props.remove(PROPERTY_AUTO_START);
+            // We should start the bundles in the startup.properties file.
+        	HashMap<Integer, StringBuffer> levels = new HashMap<Integer, StringBuffer>();
+        	for (Iterator iterator = startupProps.keySet().iterator(); iterator.hasNext();)
{
+				String name = (String) iterator.next();
+				File file = new File(bundleDir, name);
+				if( file.exists() && !file.isDirectory() ) {
+					Integer level;
+					try {
+						level = new Integer(startupProps.getProperty(name).trim());
+					} catch (NumberFormatException e1) {
+	                    System.err.print( "Ignoring " + file.toString() + " (run level must
be an integer)" );
+	                    continue;
+					}
+					StringBuffer sb = levels.get(level);
+					if (sb==null) {
+						sb = new StringBuffer(256);
+						levels.put(level, sb);
+					}
+	                try {
+	                    sb.append("\"").append(file.toURL().toString()).append("\" ");
+	                } catch (MalformedURLException e) {
+	                    System.err.print( "Ignoring " + file.toString() + " (" + e + ")" );
+	                }
+				} else {
+					System.err.println("Bundle listed in "+STARTUP_PROPERTIES_FILE_VALUE+" configuration
not found: "+file);
+				}
+			}
+        	for (Map.Entry<Integer, StringBuffer> entry : levels.entrySet()) {
+                props.setProperty(PROPERTY_AUTO_START+"."+entry.getKey(), entry.getValue().toString());
+			}
         }
+
     }
 
     private static final String DELIM_START = "${";

Modified: servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/config.properties
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/config.properties?rev=602167&r1=602166&r2=602167&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/config.properties
(original)
+++ servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/config.properties
Fri Dec  7 09:55:41 2007
@@ -27,14 +27,13 @@
  org.apache.servicemix.main.spi; version=1.0.0, \
  ${jre-${java.specification.version}}
 #org.osgi.framework.bootdelegation=sun.*,com.sun.*
-felix.auto.start=true
-#felix.auto.start.1= \
-#   "file:${servicemix.home}/bundle/org.apache.felix.shell-1.0.0.jar" \
-#   "file:${servicemix.home}/bundle/org.apache.felix.shell.tui-1.0.0.jar" \
-#   "file:${servicemix.home}/bundle/org.apache.felix.bundlerepository-1.0.0.jar" \
-#   "file:${servicemix.home}/bundle/telnetd.jar"
-felix.startlevel.framework=1
-felix.startlevel.bundle=1
+
+# To enable the use of the startup.properties file to control the start level:
+#felix.auto.start=startup.properties
+felix.auto.start=all
+
+felix.startlevel.framework=100
+felix.startlevel.bundle=50
 felix.cache.profiledir=${servicemix.home}/data/cache
 #framework.service.urlhandlers=false
 

Added: servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/startup.properties
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/startup.properties?rev=602167&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/startup.properties
(added)
+++ servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/startup.properties
Fri Dec  7 09:55:41 2007
@@ -0,0 +1,39 @@
+# This file allows you to control the start level of each bundle.
+# TODO: generate this file so that the bundle version are replaced at 
+# build time.
+#
+
+#
+# Libs that don't start services should probably get loaded first.
+#
+org.apache.servicemix.bundles.ant-1.7.0-4.0-SNAPSHOT.jar=10
+org.apache.servicemix.bundles.aopalliance-1.0-4.0-SNAPSHOT.jar=10
+org.apache.servicemix.bundles.cglib-2.1_3-4.0-SNAPSHOT.jar=10
+org.apache.servicemix.bundles.mina-1.1.6-r602102-4.0-SNAPSHOT.jar=10
+org.apache.servicemix.bundles.xstream-1.2.2-4.0-SNAPSHOT.jar=10
+geronimo-servlet_2.5_spec-1.1.1-SNAPSHOT.jar=10
+geronimo-stax-api_1.0_spec-1.0.1-SNAPSHOT.jar=10
+org.osgi.compendium-0.9.0-20070713.230317-1.jar=10
+spring-aop-2.5.jar=10
+spring-beans-2.5.jar=10
+spring-context-2.5.jar=10
+spring-core-2.5.jar=10
+spring-osgi-core-1.0-m3.jar=10
+spring-osgi-extender-1.0-m3.jar=10
+spring-osgi-io-1.0-m3.jar=10
+
+#
+# Startup core services like logging
+#
+pax-logging-api-0.9.8-20071205.114123-4.jar=20
+pax-logging-service-0.9.8-20071205.114123-4.jar=20
+org.apache.servicemix.runtime.filemonitor-4.0-SNAPSHOT.jar=20
+
+#
+# The rest of the services..
+#
+org.apache.felix.bundlerepository-1.1.0-20071205.111236-2.jar=50
+org.apache.felix.configadmin-0.9.0-20070906.081947-8.jar=50
+org.apache.servicemix.gshell.core-4.0-SNAPSHOT.jar=50
+org.apache.servicemix.gshell.obr-4.0-SNAPSHOT.jar=50
+org.apache.servicemix.gshell.osgi-4.0-SNAPSHOT.jar=50

Propchange: servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/startup.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/startup.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: servicemix/branches/servicemix-4.0/runtime/minimum/src/main/release/etc/startup.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message