incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1058673 - in /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl: DefaultTransformer.java tasks/BundleStartTask.java tasks/BundleUpdateTask.java tasks/SynchronousRefreshPackagesTask.java
Date Thu, 13 Jan 2011 17:18:58 GMT
Author: cziegeler
Date: Thu Jan 13 17:18:57 2011
New Revision: 1058673

URL: http://svn.apache.org/viewvc?rev=1058673&view=rev
Log:
SLING-1810 : Support for lazy activated bundles

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java?rev=1058673&r1=1058672&r2=1058673&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
Thu Jan 13 17:18:57 2011
@@ -90,6 +90,12 @@ public class DefaultTransformer
                         attr.put(Constants.BUNDLE_SYMBOLICNAME, sn);
                         attr.put(Constants.BUNDLE_VERSION, v.toString());
 
+                        // check for activation policy
+                        final String actPolicy = m.getMainAttributes().getValue(Constants.BUNDLE_ACTIVATIONPOLICY);
+                        if ( Constants.ACTIVATION_LAZY.equals(actPolicy) ) {
+                            attr.put(Constants.BUNDLE_ACTIVATIONPOLICY, actPolicy);
+                        }
+
                         final TransformationResult tr = new TransformationResult();
                         tr.setId(sn);
                         tr.setResourceType(InstallableResource.TYPE_BUNDLE);

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java?rev=1058673&r1=1058672&r2=1058673&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
Thu Jan 13 17:18:57 2011
@@ -28,6 +28,7 @@ import org.apache.sling.installer.api.ta
 import org.apache.sling.installer.core.impl.OsgiInstallerImpl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
 
 /** Start a bundle given its bundle ID
  *  Restarts if the bundle does not start on the first try,
@@ -71,6 +72,27 @@ public class BundleStartTask extends Ins
 	}
 
 	/**
+	 * Check if the bundle is active.
+	 * This is true if the bundle has the active state or of the bundle
+	 * is in the starting state and has the lazy activation policy.
+	 */
+	public static boolean isBundleActive(final Bundle b) {
+	    if ( b.getState() == Bundle.ACTIVE ) {
+	        return true;
+	    }
+	    if ( b.getState() == Bundle.STARTING && isLazyActivatian(b) ) {
+	        return true;
+	    }
+        return false;
+	}
+	/**
+	 * Check if the bundle has the lazy activation policy
+	 */
+	private static boolean isLazyActivatian(final Bundle b) {
+        return Constants.ACTIVATION_LAZY.equals(b.getHeaders().get(Constants.BUNDLE_ACTIVATIONPOLICY));
+	}
+
+	/**
 	 * @see org.apache.sling.installer.api.tasks.InstallTask#execute(org.apache.sling.installer.api.tasks.InstallationContext)
 	 */
 	public void execute(final InstallationContext ctx) {
@@ -100,7 +122,7 @@ public class BundleStartTask extends Ins
 			return;
 		}
 
-        if (b.getState() == Bundle.ACTIVE) {
+        if (isBundleActive(b) ) {
             this.getLogger().debug("Bundle already started, no action taken: {}/{}", bundleId,
b.getSymbolicName());
             if ( this.getResource() != null ) {
                 this.setFinishedState(ResourceState.INSTALLED);
@@ -115,7 +137,7 @@ public class BundleStartTask extends Ins
             }
             this.getLogger().info("Bundle started (retry count={}, bundle ID={}) : {}",
                     new Object[] {retryCount, bundleId, b.getSymbolicName()});
-        } catch(BundleException e) {
+        } catch (final BundleException e) {
             this.getLogger().info("Could not start bundle (retry count={}, bundle ID={})
: {}. Reason: {}. Will retry.",
                     new Object[] {retryCount, bundleId, b.getSymbolicName(), e});
 

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java?rev=1058673&r1=1058672&r2=1058673&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
Thu Jan 13 17:18:57 2011
@@ -72,7 +72,7 @@ public class BundleUpdateTask extends In
     	try {
             // If the bundle is active before the update - restart it once updated, but
             // in sequence, not right now
-            final boolean reactivate = (b.getState() == Bundle.ACTIVE);
+            final boolean reactivate = BundleStartTask.isBundleActive(b);
             b.stop();
 
             b.update(getResource().getInputStream());

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java?rev=1058673&r1=1058672&r2=1058673&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/SynchronousRefreshPackagesTask.java
Thu Jan 13 17:18:57 2011
@@ -82,9 +82,9 @@ public class SynchronousRefreshPackagesT
         // Refreshing packages might cause some bundles to be stopped,
         // make sure all currently active ones are restarted after
         // this task executes
-    	for(Bundle b : this.bundleTaskCreator.getBundleContext().getBundles()) {
-    		if(b.getState() == Bundle.ACTIVE) {
-    			final InstallTask t = new BundleStartTask(null, b.getBundleId(), this.bundleTaskCreator);
+    	for(final Bundle b : this.bundleTaskCreator.getBundleContext().getBundles()) {
+    	    if ( BundleStartTask.isBundleActive(b) ) {
+    	        final InstallTask t = new BundleStartTask(null, b.getBundleId(), this.bundleTaskCreator);
     			ctx.addTaskToCurrentCycle(t);
     			this.getLogger().debug("Added {} to restart bundle if needed after refreshing packages",
t);
     		}



Mime
View raw message