incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r984405 - in /sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer: ./ impl/ impl/tasks/
Date Wed, 11 Aug 2010 13:41:35 GMT
Author: cziegeler
Date: Wed Aug 11 13:41:34 2010
New Revision: 984405

URL: http://svn.apache.org/viewvc?rev=984405&view=rev
Log:
SLING-1560 : Do counter handling internally, tasks should not throw an exception

Modified:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstallerStatistics.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstallerStatistics.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstallerStatistics.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstallerStatistics.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstallerStatistics.java
Wed Aug 11 13:41:34 2010
@@ -30,7 +30,7 @@ public interface OsgiInstallerStatistics
 	long [] getCounters();
 
 	/** Counter index: number of OSGi tasks executed */
-	int OSGI_TASKS_COUNTER = 0;
+ 	int OSGI_TASKS_COUNTER = 0;
 
     /** Counter index: number of installer cycles */
     int INSTALLER_CYCLES_COUNTER = 1;

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
Wed Aug 11 13:41:34 2010
@@ -34,8 +34,6 @@ public interface OsgiInstallerContext {
      */
     BundleContext getBundleContext();
 
-    void incrementCounter(int index);
-    void setCounter(int index, long value);
     /**
      * Finds the bundle with given symbolic name in our BundleContext.
      */

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
Wed Aug 11 13:41:34 2010
@@ -40,7 +40,6 @@ public class OsgiInstallerImpl implement
 	/** The actual worker thread. */
     private final OsgiInstallerThread installerThread;
 
-    private long [] counters = new long[COUNTERS_SIZE];
     private PersistentBundleInfo bundleDigestsStorage;
 
     /**
@@ -110,13 +109,6 @@ public class OsgiInstallerImpl implement
 	}
 
 	/**
-	 * @see org.apache.sling.osgi.installer.OsgiInstallerStatistics#getCounters()
-	 */
-	public long [] getCounters() {
-		return counters;
-	}
-
-	/**
 	 * @see org.apache.sling.osgi.installer.OsgiInstaller#addResource(java.lang.String, org.apache.sling.osgi.installer.InstallableResource)
 	 */
 	public void addResource(final String scheme, final InstallableResource r) {
@@ -138,17 +130,10 @@ public class OsgiInstallerImpl implement
 	}
 
 	/**
-	 * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#incrementCounter(int)
+	 * @see org.apache.sling.osgi.installer.OsgiInstallerStatistics#getCounters()
 	 */
-	public void incrementCounter(int index) {
-	    counters[index]++;
-	}
-
-    /**
-     * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#setCounter(int, long)
-     */
-    public void setCounter(int index, long value) {
-        counters[index] = value;
+	public long[] getCounters() {
+        return this.installerThread.getCounters();
     }
 
     /**

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
Wed Aug 11 13:41:34 2010
@@ -22,7 +22,12 @@ package org.apache.sling.osgi.installer.
 /** Base class for tasks that can be executed by the {@link OsgiInstallerImpl} */
 public abstract class OsgiInstallerTask implements Comparable<OsgiInstallerTask> {
 
-    public abstract void execute(OsgiInstallerContext ctx) throws Exception;
+    public enum Result {
+        SUCCESS,
+        NOTHING
+    };
+
+    public abstract Result execute(OsgiInstallerContext ctx);
 
 	protected void logExecution() {
 	    Logger.logInfo("OsgiInstallerTask: executing  " + this);
@@ -41,11 +46,6 @@ public abstract class OsgiInstallerTask 
 	    return true;
 	}
 
-	/** Can the task be retried after {@link #execute(OsgiInstallerContext)} failed? */
-	public boolean canRetry(OsgiInstallerContext ctx) {
-		return true;
-	}
-
 	@Override
 	public final boolean equals(Object o) {
 		if(o instanceof OsgiInstallerTask) {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
Wed Aug 11 13:41:34 2010
@@ -46,7 +46,7 @@ import org.osgi.framework.BundleListener
  *  that are updated or removed during a cycle, and merged with
  *  the main list at the end of the cycle.
  */
-class OsgiInstallerThread extends Thread implements BundleListener {
+class OsgiInstallerThread extends Thread implements BundleListener, OsgiInstallerStatistics
{
 
     private final OsgiInstallerContext ctx;
     private final List<RegisteredResource> newResources = new LinkedList<RegisteredResource>();
@@ -65,6 +65,8 @@ class OsgiInstallerThread extends Thread
     private final BundleTaskCreator bundleTaskCreator;
     private final ConfigTaskCreator configTaskCreator;
 
+    private long [] counters = new long[COUNTERS_SIZE];
+
     OsgiInstallerThread(final OsgiInstallerContext ctx) {
         this.configTaskCreator = new ConfigTaskCreator(ctx.getBundleContext());
         this.bundleTaskCreator = new BundleTaskCreator(ctx.getBundleContext());
@@ -85,6 +87,21 @@ class OsgiInstallerThread extends Thread
         }
     }
 
+    /**
+     * @see org.apache.sling.osgi.installer.OsgiInstallerStatistics#getCounters()
+     */
+    public long [] getCounters() {
+        return counters;
+    }
+
+    public void incrementCounter(int index) {
+        counters[index]++;
+    }
+
+    public void setCounter(int index, long value) {
+        counters[index] = value;
+    }
+
     @Override
     public void run() {
         ctx.getBundleContext().addBundleListener(this);
@@ -100,13 +117,15 @@ class OsgiInstallerThread extends Thread
             	    cleanupInstallableResources();
             	    Logger.logDebug("No tasks to process, going idle");
 
-            	    ctx.setCounter(OsgiInstallerStatistics.WORKER_THREAD_IS_IDLE_COUNTER, 1);
-                    ctx.incrementCounter(OsgiInstallerStatistics.WORKER_THREAD_BECOMES_IDLE_COUNTER);
+            	    this.setCounter(OsgiInstallerStatistics.WORKER_THREAD_IS_IDLE_COUNTER, 1);
+                    this.incrementCounter(OsgiInstallerStatistics.WORKER_THREAD_BECOMES_IDLE_COUNTER);
             	    synchronized (newResources) {
-                        newResources.wait();
+            	        try {
+            	            newResources.wait();
+            	        } catch (InterruptedException ignore) {}
                     }
             	    Logger.logDebug("Notified of new resources, back to work");
-                    ctx.setCounter(OsgiInstallerStatistics.WORKER_THREAD_IS_IDLE_COUNTER,
0);
+                    this.setCounter(OsgiInstallerStatistics.WORKER_THREAD_IS_IDLE_COUNTER,
0);
             	    continue;
             	}
 
@@ -309,34 +328,24 @@ class OsgiInstallerThread extends Thread
         }
     }
 
-    private int executeTasks() throws Exception {
+    private int executeTasks() {
         int counter = 0;
         while(!tasks.isEmpty()) {
             OsgiInstallerTask t = null;
             synchronized (tasks) {
                 t = tasks.first();
+                tasks.remove(t);
             }
-            try {
-                t.execute(ctx);
-                removeTask(t);
-                counter++;
-            } catch(Exception e) {
-            	if(!t.canRetry(ctx)) {
-            	    Logger.logInfo("Task cannot be retried, removing from list:" + t);
-                    removeTask(t);
-            	}
-            	throw e;
+            final OsgiInstallerTask.Result result = t.execute(ctx);
+            switch (result) {
+                case SUCCESS: this.incrementCounter(OsgiInstallerStatistics.OSGI_TASKS_COUNTER);
+                              break;
             }
+            counter++;
         }
         return counter;
     }
 
-    private void removeTask(OsgiInstallerTask t) {
-        synchronized (tasks) {
-            tasks.remove(t);
-        }
-    }
-
     private void cleanupInstallableResources() throws IOException {
         // Cleanup resources that are not marked installable,
         // they have been processed by now
@@ -367,9 +376,9 @@ class OsgiInstallerThread extends Thread
             registeredResources.remove(key);
         }
 
-        ctx.setCounter(OsgiInstallerStatistics.REGISTERED_RESOURCES_COUNTER, resourceCount);
-        ctx.setCounter(OsgiInstallerStatistics.REGISTERED_GROUPS_COUNTER, registeredResources.size());
-        ctx.incrementCounter(OsgiInstallerStatistics.INSTALLER_CYCLES_COUNTER);
+        this.setCounter(OsgiInstallerStatistics.REGISTERED_RESOURCES_COUNTER, resourceCount);
+        this.setCounter(OsgiInstallerStatistics.REGISTERED_GROUPS_COUNTER, registeredResources.size());
+        this.incrementCounter(OsgiInstallerStatistics.INSTALLER_CYCLES_COUNTER);
 
         // List of resources might have changed
         persistentList.save();

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
Wed Aug 11 13:41:34 2010
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.osgi.installer.impl.tasks;
 
-import org.apache.sling.osgi.installer.OsgiInstallerStatistics;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
@@ -43,13 +42,22 @@ public class BundleInstallTask extends O
     	return getClass().getSimpleName() + ": " + resource;
     }
 
-    public void execute(OsgiInstallerContext ctx) throws Exception {
-        final Bundle b = ctx.getBundleContext().installBundle(resource.getURL(), resource.getInputStream());
-        final Version newVersion = new Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
-        ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
-        logExecution();
-        ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
-        ctx.incrementCounter(OsgiInstallerStatistics.OSGI_TASKS_COUNTER);
+    /**
+     * @see org.apache.sling.osgi.installer.impl.OsgiInstallerTask#execute(org.apache.sling.osgi.installer.impl.OsgiInstallerContext)
+     */
+    public Result execute(OsgiInstallerContext ctx) {
+        try {
+            final Bundle b = ctx.getBundleContext().installBundle(resource.getURL(), resource.getInputStream());
+            final Version newVersion = new Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
+            ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
+            logExecution();
+            ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
+            return Result.SUCCESS;
+        } catch (Exception ex) {
+            // if something goes wrong we simply try it again
+            ctx.addTaskToCurrentCycle(this);
+            return Result.NOTHING;
+        }
     }
 
     @Override

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
Wed Aug 11 13:41:34 2010
@@ -18,11 +18,11 @@
  */
 package org.apache.sling.osgi.installer.impl.tasks;
 
-import org.apache.sling.osgi.installer.OsgiInstallerStatistics;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.util.tracker.ServiceTracker;
 
@@ -50,7 +50,7 @@ public class BundleRemoveTask extends Os
     }
 
     @Override
-    public void execute(OsgiInstallerContext ctx) throws Exception {
+    public Result execute(OsgiInstallerContext ctx) {
         logExecution();
         final String symbolicName = (String)resource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
         final Bundle b = ctx.getMatchingBundle(symbolicName);
@@ -58,12 +58,17 @@ public class BundleRemoveTask extends Os
             throw new IllegalStateException("Bundle to remove (" + symbolicName + ") not
found");
         }
         final int state = b.getState();
-        if(state == Bundle.ACTIVE || state == Bundle.STARTING) {
-        	b.stop();
+        try {
+            if (state == Bundle.ACTIVE || state == Bundle.STARTING) {
+            	b.stop();
+            }
+            b.uninstall();
+        } catch (BundleException be) {
+            ctx.addTaskToNextCycle(this);
+            return Result.NOTHING;
         }
-        b.uninstall();
         ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.packageAdminTracker));
-        ctx.incrementCounter(OsgiInstallerStatistics.OSGI_TASKS_COUNTER);
+        return Result.SUCCESS;
     }
 
     @Override

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
Wed Aug 11 13:41:34 2010
@@ -20,7 +20,6 @@ package org.apache.sling.osgi.installer.
 
 import java.text.DecimalFormat;
 
-import org.apache.sling.osgi.installer.OsgiInstallerStatistics;
 import org.apache.sling.osgi.installer.impl.Activator;
 import org.apache.sling.osgi.installer.impl.Logger;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
@@ -57,18 +56,18 @@ public class BundleStartTask extends Osg
 		return getClass().getSimpleName() + ": bundle " + bundleId;
 	}
 
-	public void execute(OsgiInstallerContext ctx) throws Exception {
+	public Result execute(OsgiInstallerContext ctx) {
 		final Bundle b = ctx.getBundleContext().getBundle(bundleId);
 		boolean needToRetry = false;
 
         if(bundleId == 0) {
             Logger.logDebug("Bundle 0 is the framework bundle, ignoring request to start
it");
-            return;
+            return Result.NOTHING;
         }
 
 		if(b == null) {
 		    Logger.logInfo("Cannot start bundle, id not found:" + bundleId);
-			return;
+			return Result.NOTHING;
 		}
 
 		try {
@@ -103,7 +102,7 @@ public class BundleStartTask extends Osg
 	        }
 		}
 		retryCount++;
-		ctx.incrementCounter(OsgiInstallerStatistics.OSGI_TASKS_COUNTER);
+        return Result.SUCCESS;
 	}
 
 	/** Do not execute this task if waiting for events */

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
Wed Aug 11 13:41:34 2010
@@ -20,7 +20,6 @@ package org.apache.sling.osgi.installer.
 
 import java.io.InputStream;
 
-import org.apache.sling.osgi.installer.OsgiInstallerStatistics;
 import org.apache.sling.osgi.installer.impl.Logger;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
@@ -59,7 +58,7 @@ public class BundleUpdateTask extends Os
     }
 
     @Override
-    public void execute(OsgiInstallerContext ctx) throws Exception {
+    public Result execute(OsgiInstallerContext ctx) {
         final String symbolicName = (String)resource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
         final Bundle b = ctx.getMatchingBundle(symbolicName);
         if(b == null) {
@@ -73,44 +72,48 @@ public class BundleUpdateTask extends Os
     	snapshot = ctx.isSnapshot(newVersion);
     	if(currentVersion.equals(newVersion) && !snapshot) {
     	    Logger.logDebug("Same version is already installed, and not a snapshot, ignoring
update:" + resource);
-    		return;
+    		return Result.NOTHING;
     	}
 
-        // If snapshot and ready to update, cancel if digest didn't change - as the list
-        // of RegisteredResources is not saved, this might not have been detected earlier,
-        // if the snapshot was installed and the installer was later restarted
-        if(snapshot) {
-            final String oldDigest = ctx.getInstalledBundleDigest(b);
-            if(resource.getDigest().equals(oldDigest)) {
-                Logger.logDebug("Snapshot digest did not change, ignoring update:" + resource);
-                return;
+    	try {
+            // If snapshot and ready to update, cancel if digest didn't change - as the list
+            // of RegisteredResources is not saved, this might not have been detected earlier,
+            // if the snapshot was installed and the installer was later restarted
+            if(snapshot) {
+                final String oldDigest = ctx.getInstalledBundleDigest(b);
+                if(resource.getDigest().equals(oldDigest)) {
+                    Logger.logDebug("Snapshot digest did not change, ignoring update:" +
resource);
+                    return Result.NOTHING;
+                }
             }
-        }
 
-        logExecution();
-        if(b.getState() == Bundle.ACTIVE) {
-            // bundle was active before the update - restart it once updated, but
-            // in sequence, not right now
-            ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
-        }
-        b.stop();
-        final InputStream is = resource.getInputStream();
-        if(is == null) {
-        	canRetry = false;
-            throw new IllegalStateException(
-                    "RegisteredResource provides null InputStream, cannot update bundle:
"
-                    + resource);
-        }
-        b.update(is);
-        ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
+            logExecution();
+            if(b.getState() == Bundle.ACTIVE) {
+                // bundle was active before the update - restart it once updated, but
+                // in sequence, not right now
+                ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
+            }
+            b.stop();
+            final InputStream is = resource.getInputStream();
+            if(is == null) {
+            	canRetry = false;
+                throw new IllegalStateException(
+                        "RegisteredResource provides null InputStream, cannot update bundle:
"
+                        + resource);
+            }
+            b.update(is);
+            ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
+    	} catch (Exception e) {
+            if ( canRetry ) {
+                ctx.addTaskToCurrentCycle(this);
+                return Result.NOTHING;
+            }
+            Logger.logWarn("Removing failing tasks - unable to retry: " + this, e);
+            return Result.NOTHING;
+    	}
         ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.packageAdminTracker));
         Logger.logDebug("Bundle updated: " + b.getBundleId() + "/" + b.getSymbolicName());
-        ctx.incrementCounter(OsgiInstallerStatistics.OSGI_TASKS_COUNTER);
-    }
-
-    @Override
-    public boolean canRetry(OsgiInstallerContext ctx) {
-    	return canRetry;
+        return Result.SUCCESS;
     }
 
     @Override

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
Wed Aug 11 13:41:34 2010
@@ -59,13 +59,13 @@ public class ConfigInstallTask extends A
 
     @SuppressWarnings("unchecked")
 	@Override
-    public void execute(OsgiInstallerContext ctx) throws Exception {
+    public Result execute(OsgiInstallerContext ctx) {
 
         final ConfigurationAdmin ca = this.getConfigurationAdmin();
         if(ca == null) {
             ctx.addTaskToNextCycle(this);
             Logger.logDebug("ConfigurationAdmin not available, task will be retried later:
" + this);
-            return;
+            return Result.NOTHING;
         }
 
         // Convert data to a configuration Dictionary
@@ -86,29 +86,35 @@ public class ConfigInstallTask extends A
         // Get or create configuration, but do not
         // update if the new one has the same values.
         boolean created = false;
-        Configuration config = getConfiguration(ca, pid, false, ctx);
-        if(config == null) {
-            created = true;
-            config = getConfiguration(ca, pid, true, ctx);
-        } else {
-			if(isSameData(config.getProperties(), resource.getDictionary())) {
-			    Logger.logDebug("Configuration " + config.getPid()
-	                        + " already installed with same data, update request ignored: "
-	                        + resource);
-				config = null;
-			}
-        }
+        try {
+            Configuration config = getConfiguration(ca, pid, false, ctx);
+            if(config == null) {
+                created = true;
+                config = getConfiguration(ca, pid, true, ctx);
+            } else {
+    			if(isSameData(config.getProperties(), resource.getDictionary())) {
+    			    Logger.logDebug("Configuration " + config.getPid()
+    	                        + " already installed with same data, update request ignored:
"
+    	                        + resource);
+    				config = null;
+    			}
+            }
 
-        if(config != null) {
-            logExecution();
-            if (config.getBundleLocation() != null) {
-                config.setBundleLocation(null);
+            if(config != null) {
+                logExecution();
+                if (config.getBundleLocation() != null) {
+                    config.setBundleLocation(null);
+                }
+                config.update(dict);
+                Logger.logInfo("Configuration " + config.getPid()
+                            + " " + (created ? "created" : "updated")
+                            + " from " + resource);
+                return Result.SUCCESS;
             }
-            config.update(dict);
-            Logger.logInfo("Configuration " + config.getPid()
-                        + " " + (created ? "created" : "updated")
-                        + " from " + resource);
+        } catch (Exception e) {
+            ctx.addTaskToNextCycle(this);
         }
+        return Result.NOTHING;
     }
 
     /** True if a and b represent the same config data, ignoring "non-configuration" keys
in the dictionaries */

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java
Wed Aug 11 13:41:34 2010
@@ -43,22 +43,28 @@ public class ConfigRemoveTask extends Ab
         return CONFIG_REMOVE_ORDER + pid.getCompositePid();
     }
 
-    public void execute(OsgiInstallerContext ctx) throws Exception {
+    public Result execute(OsgiInstallerContext ctx) {
 
         final ConfigurationAdmin ca = this.getConfigurationAdmin();
         if(ca == null) {
             ctx.addTaskToNextCycle(this);
             Logger.logDebug("ConfigurationAdmin not available, task will be retried later:
" + this);
-            return;
+            return Result.NOTHING;
         }
 
         logExecution();
-        final Configuration cfg = getConfiguration(ca, pid, false, ctx);
-        if(cfg == null) {
-            Logger.logDebug("Cannot delete config , pid=" + pid + " not found, ignored ("
+ resource + ")");
-        } else {
-            Logger.logInfo("Deleting config " + pid + " (" + resource + ")");
-            cfg.delete();
+        try {
+            final Configuration cfg = getConfiguration(ca, pid, false, ctx);
+            if(cfg == null) {
+                Logger.logDebug("Cannot delete config , pid=" + pid + " not found, ignored
(" + resource + ")");
+            } else {
+                Logger.logInfo("Deleting config " + pid + " (" + resource + ")");
+                cfg.delete();
+                return Result.SUCCESS;
+            }
+        } catch (Exception e) {
+            ctx.addTaskToNextCycle(this);
         }
+        return Result.NOTHING;
     }
 }
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java?rev=984405&r1=984404&r2=984405&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java
Wed Aug 11 13:41:34 2010
@@ -75,7 +75,7 @@ public class SynchronousRefreshPackagesT
     /**
      * @see org.apache.sling.osgi.installer.impl.OsgiInstallerTask#execute(org.apache.sling.osgi.installer.impl.OsgiInstallerContext)
      */
-    public void execute(OsgiInstallerContext ctx) throws Exception {
+    public Result execute(OsgiInstallerContext ctx) {
         logExecution();
         final int targetEventCount = packageRefreshEventsCount + 1;
         final long start = System.currentTimeMillis();
@@ -119,5 +119,6 @@ public class SynchronousRefreshPackagesT
         } finally {
         	ctx.getBundleContext().removeFrameworkListener(this);
         }
+        return Result.SUCCESS;
 	}
 }



Mime
View raw message