Author: bdelacretaz
Date: Tue Dec  9 05:45:39 2008
New Revision: 724696

URL: http://svn.apache.org/viewvc?rev=724696&view=rev
Log:
SLING-763 - Install bundles at the default framework start level

Modified:
    
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
    
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
    
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java

Modified: 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=724696&r1=724695&r2=724696&view=diff
==============================================================================
--- 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
 (original)
+++ 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
 Tue Dec  9 05:45:39 2008
@@ -86,11 +86,6 @@
     /** @scr.reference */
     protected StartLevel startLevel;
     
-    /** @scr.property type="Integer" valueRef="DEFAULT_BUNDLES_START_LEVEL" */
-    private static final String BUNDLES_START_LEVEL__PROPERTY = 
"bundles.startlevel";
-    private static final int DEFAULT_BUNDLES_START_LEVEL = 30;
-    private int installedBundlesStartLevel = DEFAULT_BUNDLES_START_LEVEL;
-
     private Session session;
     private File serviceDataFile;
     private int startLevelToSetAtStartup;
@@ -127,28 +122,17 @@
             context.getBundleContext().addFrameworkListener(this);
         }
         
-        // Read config
-        if(context != null) {
-            final Object prop = 
context.getProperties().get(BUNDLES_START_LEVEL__PROPERTY);
-            if(prop != null && prop instanceof Number) {
-                installedBundlesStartLevel = ((Number)prop).intValue();
-                log.info("Start level for installed bundles set to {} by {} 
property", installedBundlesStartLevel, BUNDLES_START_LEVEL__PROPERTY);
-            } else {
-                installedBundlesStartLevel = DEFAULT_BUNDLES_START_LEVEL;
-                log.info("Start level for installed bundles set to default 
value {}", installedBundlesStartLevel);
-            }
-        }
-
         // Check start levels
         if(context != null) {
             final int myLevel = 
startLevel.getBundleStartLevel(context.getBundleContext().getBundle());
-            if(installedBundlesStartLevel < myLevel) {
+            final int initialBundleStartLevel = 
startLevel.getInitialBundleStartLevel();
+            if(initialBundleStartLevel < myLevel) {
                 // Running at a lower start level than the bundles that we 
install
                 // allows us to stop them if the repository goes away 
(SLING-747)
                 log.warn(
-                        "The configured start level for bundles installed by 
jcrinstall ({})"
+                        "The configured start level for installed bundles  
({})"
                         + " should be higher than the jcrinstall start level 
({})",
-                        installedBundlesStartLevel, myLevel
+                        initialBundleStartLevel, myLevel
                 );
             }
         }
@@ -182,7 +166,7 @@
          *     Using services and a whiteboard pattern for these would be nice,
          *     but that could be problematic at startup due to async loading
          */
-       converters.add(new FileNodeConverter(installedBundlesStartLevel));
+       converters.add(new FileNodeConverter(0));
        converters.add(new ConfigNodeConverter());
        
        String folderNameRegexp = getPropertyValue(componentContext, 
FOLDER_NAME_REGEXP_PROPERTY);
@@ -405,28 +389,17 @@
     public void run() {
         log.info("{} thread {} starts", getClass().getSimpleName(), 
Thread.currentThread().getName());
         
-        // We could use the scheduler service but that makes things harder to 
test
-        boolean scanning = false;
-        boolean oldScanning = !scanning;
-        
+        boolean lastScanningState = false;
         while (observationCycleActive) {
             try {
-                final int currentLevel = startLevel.getStartLevel(); 
-                scanning = currentLevel >= installedBundlesStartLevel;
-                if(scanning != oldScanning) {
-                    if(scanning) {
-                        log.info("Scanning enabled, current start level ({}) 
equals or above {} (start level of installed bundles)", 
-                                currentLevel, installedBundlesStartLevel);
-                    } else {
-                        log.info("Scanning disabled, current start level ({}) 
is below {} (start level of installed bundles)", 
-                                currentLevel, installedBundlesStartLevel);
-                    }
-                    oldScanning = scanning;
-                }
-                
+                boolean scanning = (repository != null); 
                 if(scanning) {
                     runOneCycle();
                 }
+                if(scanning != lastScanningState) {
+                    log.info("Repository scanning {}", scanning ? "active" : 
"inactive");
+                    lastScanningState = scanning;
+                }
             } catch (IllegalArgumentException ie) {
                 log.warn("IllegalArgumentException  in " + 
getClass().getSimpleName(), ie);
             } catch (RepositoryException re) {
@@ -435,6 +408,7 @@
                 log.error("Unhandled Exception in runOneCycle()", e);
             } finally {
                 try {
+                    // We could use the scheduler service but that makes 
things harder to test
                     Thread.sleep(1000L);
                 } catch (InterruptedException ignore) {
                     // ignore

Modified: 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java?rev=724696&r1=724695&r2=724696&view=diff
==============================================================================
--- 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
 (original)
+++ 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
 Tue Dec  9 05:45:39 2008
@@ -184,10 +184,15 @@
                            needsRefresh = true;
                        } else {
                            uri = OsgiControllerImpl.getResourceLocation(uri);
-                           final int level = 
installableData.getBundleStartLevel();
-                           log.debug("No matching Bundle for uri {}, 
installing with start level {}", uri, level);
+                           int level = installableData.getBundleStartLevel();
                            b = ctx.installBundle(uri, data);
-                           startLevel.setBundleStartLevel(b, level);
+                           if(level > 0) {
+                               startLevel.setBundleStartLevel(b, level);
+                       log.debug("No matching Bundle for uri {}, installed 
with start level {}", uri, level);
+                           } else {
+                               level = startLevel.getBundleStartLevel(b);
+                       log.debug("No matching Bundle for uri {}, installing 
with current default start level {}", uri, level);
+                           }
                        }
                } finally {
                    // data is never null here

Modified: 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java?rev=724696&r1=724695&r2=724696&view=diff
==============================================================================
--- 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
 (original)
+++ 
incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
 Tue Dec  9 05:45:39 2008
@@ -228,6 +228,11 @@
 
     /** [EMAIL PROTECTED] */
     public void executeScheduledOperations() throws Exception {
+        if(processors == null) {
+            log.info("Not activated yet, cannot executeScheduledOperations");
+            return;
+        }
+    
         for(OsgiResourceProcessor p : processors) {
             p.processResourceQueue();
         }


Reply via email to