incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r792134 - in /sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks: BundleInstallRemoveTask.java BundleStartTask.java
Date Wed, 08 Jul 2009 13:36:43 GMT
Author: bdelacretaz
Date: Wed Jul  8 13:36:43 2009
New Revision: 792134

URL: http://svn.apache.org/viewvc?rev=792134&view=rev
Log:
SLING-905 - cleaner retries for starting bundles

Modified:
    sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java
    sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java

Modified: sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java?rev=792134&r1=792133&r2=792134&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java
Wed Jul  8 13:36:43 2009
@@ -85,12 +85,6 @@
 
 	@Override
 	protected InstallResultCode doInstallOrUpdate(OsgiControllerTaskContext tctx, Map<String,
Object> attributes) throws Exception {
-        int retryCount = 0;
-        if ( attributes.get("RETRY_COUNT") != null ) {
-            retryCount = (Integer)attributes.get("RETRY_COUNT");
-        }
-        retryCount++;
-        attributes.put("RETRY_COUNT", retryCount);
 
     	// Check that we have bundle data and manifest
     	InputStream is = data.adaptTo(InputStream.class);
@@ -125,7 +119,7 @@
 			// If the bundle (or one with the same symbolic name) is
 			// already installed, ignore the new one if it's a lower
 			// version
-			if (b != null && retryCount == 1) {
+			if (b != null) {
 				final Version installedVersion = new Version((String)(b.getHeaders().get(Constants.BUNDLE_VERSION)));
 				final Version newBundleVersion = new Version(m.getMainAttributes().getValue(Constants.BUNDLE_VERSION));
 				if(ignoreNewBundle(b.getSymbolicName(), uri, installedVersion, newBundleVersion)) {
@@ -135,21 +129,15 @@
 
 			if (b != null) {
 				// Existing bundle -> stop, update, restart
-			    if ( retryCount == 1 ) {
-			    	if(ocs.getLogService() != null) {
-			    		ocs.getLogService().log(LogService.LOG_DEBUG, "Calling Bundle.stop() and updating
" + uri);
-			    	}
-			        b.stop();
-			        b.update(is);
-	                b.start();
-			    } else {
-			    	if(ocs.getLogService() != null) {
-			    		ocs.getLogService().log(LogService.LOG_DEBUG, "Calling Bundle.start " + uri);
-			    	}
-	                b.start();
-			    }
+		    	if(ocs.getLogService() != null) {
+		    		ocs.getLogService().log(LogService.LOG_INFO, 
+		    				"Bundle " + b.getBundleId() + " already present, calling Bundle.stop() and updating
" + uri);
+		    	}
+		        b.stop();
+		        b.update(is);
 			    updated = true;
 			    tctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask());
+			    tctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
 			} else {
 				// New bundle -> install
 			    final String fullUri = OsgiControllerImpl.getResourceLocation(uri);
@@ -159,8 +147,9 @@
 			    }
 			    b = bundleContext.installBundle(fullUri, is);
 		    	if(ocs.getLogService() != null) {
-		    		ocs.getLogService().log(LogService.LOG_DEBUG, "No matching Bundle, installed " +
fullUri);
+		    		ocs.getLogService().log(LogService.LOG_INFO, "Bundle was not present, installed "
+ fullUri);
 		    	}
+			    tctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
 			}
 		} finally {
 		    // data is never null here
@@ -175,14 +164,6 @@
         // and updates where there are no attributes yet
         attributes.put(Storage.KEY_BUNDLE_ID, b.getBundleId());
 
-        // start bundle
-        tctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
-        
-        // TODO - remove retry
-        // Successful - reset retry count
-        retryCount = 0;
-        attributes.put("RETRY_COUNT", retryCount);
-
         return updated ? InstallResultCode.UPDATED : InstallResultCode.INSTALLED;
 	}
 

Modified: sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=792134&r1=792133&r2=792134&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
Wed Jul  8 13:36:43 2009
@@ -23,6 +23,7 @@
 import org.apache.sling.osgi.installer.impl.OsgiControllerTask;
 import org.apache.sling.osgi.installer.impl.OsgiControllerTaskContext;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
 import org.osgi.service.log.LogService;
 
 /** Task that starts a bundle */
@@ -46,9 +47,9 @@
 		return getClass().getSimpleName() + " (bundle " + bundleId + ")";
 	}
 
-	public void execute(OsgiControllerTaskContext ctx) throws Exception {
-		final Bundle b = ctx.getBundleContext().getBundle(bundleId);
-		final LogService log = ctx.getOsgiControllerServices().getLogService();
+	public void execute(OsgiControllerTaskContext tctx) throws Exception {
+		final Bundle b = tctx.getBundleContext().getBundle(bundleId);
+		final LogService log = tctx.getOsgiControllerServices().getLogService();
 		
 		if(b == null) {
 			if(log != null) {
@@ -62,10 +63,19 @@
 				log.log(LogService.LOG_DEBUG, "Bundle already started, no action taken:" + bundleId +
"/" + b.getSymbolicName());
 			}
 		} else {
-			if(log != null) {
-				log.log(LogService.LOG_INFO, "Starting bundle:" + bundleId + "/" + b.getSymbolicName());
+			try {
+				b.start();
+				if(log != null) {
+					log.log(LogService.LOG_INFO, "Bundle started:" + bundleId + "/" + b.getSymbolicName());
+				}
+			} catch(BundleException e) {
+				if(log != null) {
+					log.log(LogService.LOG_INFO, 
+							"Could not start bundle (" + e + "), will retry: " + bundleId + "/" + b.getSymbolicName());
+				}
+				tctx.addTaskToNextCycle(this);
 			}
-			b.start();
+			
 		}
 	}
 }



Mime
View raw message