incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1369751 - in /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl: ./ tasks/ util/
Date Mon, 06 Aug 2012 08:47:31 GMT
Author: cziegeler
Date: Mon Aug  6 08:47:31 2012
New Revision: 1369751

URL: http://svn.apache.org/viewvc?rev=1369751&view=rev
Log:
SLING-2556 : Installer should detect if installer bundle is refreshed by another bundle update
(WiP)

Added:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/BundleRefresher.java
  (with props)
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/PABundleRefresher.java
  (with props)
Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/AbstractInstallTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/InstallerBundleUpdateTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshBundlesTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/TaskSupport.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/AbstractInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/AbstractInstallTask.java?rev=1369751&r1=1369750&r2=1369751&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/AbstractInstallTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/AbstractInstallTask.java
Mon Aug  6 08:47:31 2012
@@ -21,8 +21,8 @@ package org.apache.sling.installer.core.
 import org.apache.sling.installer.api.tasks.InstallTask;
 import org.apache.sling.installer.api.tasks.TaskResourceGroup;
 import org.apache.sling.installer.core.impl.tasks.TaskSupport;
+import org.apache.sling.installer.core.impl.util.BundleRefresher;
 import org.osgi.framework.BundleContext;
-import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,8 +58,8 @@ public abstract class AbstractInstallTas
         return this.support.getBundleContext();
     }
 
-    protected PackageAdmin getPackageAdmin() {
-        return this.support.getPackageAdmin();
+    protected BundleRefresher getBundleRefresher() {
+        return this.support.getBundleRefresher();
     }
 
     protected StartLevel getStartLevel() {

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/InstallerBundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/InstallerBundleUpdateTask.java?rev=1369751&r1=1369750&r2=1369751&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/InstallerBundleUpdateTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/InstallerBundleUpdateTask.java
Mon Aug  6 08:47:31 2012
@@ -18,6 +18,9 @@
  */
 package org.apache.sling.installer.core.impl.tasks;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.sling.installer.api.tasks.InstallTask;
 import org.apache.sling.installer.api.tasks.InstallationContext;
 import org.apache.sling.installer.api.tasks.ResourceState;
@@ -58,8 +61,9 @@ public class InstallerBundleUpdateTask e
             }
         } else if ( this.count == 1 ) {
             // second step: refresh
-            this.getPackageAdmin().refreshPackages(new Bundle[] {b});
-            ctx.log("Refreshing packages for bundle {}.", b);
+            final List<Bundle> bundles = new ArrayList<Bundle>();
+            bundles.add(b);
+            this.getBundleRefresher().refreshBundles(ctx, bundles, false);
         } else {
             // finished
             this.getResource().setAttribute(ASYNC_ATTR_NAME, null);

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshBundlesTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshBundlesTask.java?rev=1369751&r1=1369750&r2=1369751&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshBundlesTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshBundlesTask.java
Mon Aug  6 08:47:31 2012
@@ -25,24 +25,15 @@ import java.util.Set;
 
 import org.apache.sling.installer.api.tasks.InstallationContext;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.FrameworkEvent;
-import org.osgi.framework.FrameworkListener;
 
 /**
  * Refresh a set of bundles.
  */
 public class RefreshBundlesTask
-    extends AbstractBundleTask
-    implements FrameworkListener{
+    extends AbstractBundleTask {
 
     private static final String REFRESH_PACKAGES_ORDER = "60-";
 
-    /** Max time allowed to refresh packages */
-    private static final int MAX_REFRESH_PACKAGES_WAIT_SECONDS = 90;
-
-    /** Counter for package refresh events. */
-    private volatile long refreshEventCount;
-
     /** Global set of bundles to refresh. */
     private static final Set<Long> BUNDLE_IDS = new HashSet<Long>();
 
@@ -87,46 +78,7 @@ public class RefreshBundlesTask
             BUNDLE_IDS.clear();
         }
         if ( bundles.size() > 0 ) {
-            ctx.log("Refreshing {} bundles: {}", bundles.size(), bundles);
-            this.refreshEventCount = -1;
-            this.getBundleContext().addFrameworkListener(this);
-            try {
-                this.refreshEventCount = 0;
-                this.getPackageAdmin().refreshPackages(bundles.toArray(new Bundle[bundles.size()]));
-                final long start = System.currentTimeMillis();
-                do {
-                    synchronized ( this ) {
-                        try {
-                            ctx.log("Waiting up to {} seconds for bundles refresh", MAX_REFRESH_PACKAGES_WAIT_SECONDS);
-                            this.wait(MAX_REFRESH_PACKAGES_WAIT_SECONDS * 1000);
-                        } catch (final InterruptedException ignore) {
-                            // ignore
-                        }
-                        if ( start + MAX_REFRESH_PACKAGES_WAIT_SECONDS * 1000 < System.currentTimeMillis()
) {
-                            this.getLogger().warn("No FrameworkEvent.PACKAGES_REFRESHED event
received within {}"
-                                            + " seconds after refresh, aborting wait.", 
-                                            MAX_REFRESH_PACKAGES_WAIT_SECONDS);
-                            this.refreshEventCount++;
-                        }
-                    }
-                } while ( this.refreshEventCount < 1);
-            } finally {
-                this.getBundleContext().removeFrameworkListener(this);
-            }
-            ctx.log("Done refreshing {} bundles", bundles.size());
+            this.getBundleRefresher().refreshBundles(ctx, bundles, true);
         }
 	}
-
-    /**
-     * @see org.osgi.framework.FrameworkListener#frameworkEvent(org.osgi.framework.FrameworkEvent)
-     */
-    public void frameworkEvent(final FrameworkEvent event) {
-        if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
-            this.getLogger().debug("FrameworkEvent.PACKAGES_REFRESHED");
-            synchronized (this) {
-                this.refreshEventCount++;
-                this.notify();
-            }
-        }
-    }
 }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java?rev=1369751&r1=1369750&r2=1369751&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/RefreshOptionalPackagesTask.java
Mon Aug  6 08:47:31 2012
@@ -59,7 +59,7 @@ public class RefreshOptionalPackagesTask
      */
     public void execute(final InstallationContext ctx) {
         getLogger().info("** Invoking refresh optional packages!");
-        final PackageAdmin packageAdmin = this.getPackageAdmin();
+        final PackageAdmin packageAdmin = null;
 
         ExportedPackage[] exports = null;
         final List<Bundle> refreshBundles = new ArrayList<Bundle>();

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/TaskSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/TaskSupport.java?rev=1369751&r1=1369750&r2=1369751&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/TaskSupport.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/TaskSupport.java
Mon Aug  6 08:47:31 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.sling.installer.core.impl.tasks;
 
+import org.apache.sling.installer.core.impl.util.BundleRefresher;
+import org.apache.sling.installer.core.impl.util.PABundleRefresher;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
@@ -73,8 +75,9 @@ public class TaskSupport {
         return (StartLevel) this.startLevelTracker.getService();
     }
 
-    public PackageAdmin getPackageAdmin() {
-        return (PackageAdmin)this.packageAdminTracker.getService();
+    public BundleRefresher getBundleRefresher() {
+        return new PABundleRefresher((PackageAdmin) this.packageAdminTracker.getService(),
+                        this.bundleContext);
     }
 
 }

Added: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/BundleRefresher.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/BundleRefresher.java?rev=1369751&view=auto
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/BundleRefresher.java
(added)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/BundleRefresher.java
Mon Aug  6 08:47:31 2012
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.installer.core.impl.util;
+
+import java.util.List;
+
+import org.apache.sling.installer.api.tasks.InstallationContext;
+import org.osgi.framework.Bundle;
+
+public interface BundleRefresher {
+
+    void refreshBundles(final InstallationContext ctx, final List<Bundle> bundles,
boolean wait);
+}

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/BundleRefresher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/BundleRefresher.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/BundleRefresher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/PABundleRefresher.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/PABundleRefresher.java?rev=1369751&view=auto
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/PABundleRefresher.java
(added)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/PABundleRefresher.java
Mon Aug  6 08:47:31 2012
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.installer.core.impl.util;
+
+import java.util.List;
+
+import org.apache.sling.installer.api.tasks.InstallationContext;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PABundleRefresher implements BundleRefresher, FrameworkListener {
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /** Max time allowed to refresh packages */
+    private static final int MAX_REFRESH_PACKAGES_WAIT_SECONDS = 90;
+
+    /** Counter for package refresh events. */
+    private volatile long refreshEventCount;
+
+    private final PackageAdmin pckAdmin;
+
+    private final BundleContext bundleContext;
+
+    /** Lock object for syncing. */
+    private  final Object lock = new Object();
+
+    public PABundleRefresher(final PackageAdmin pa, final BundleContext bundleContext) {
+        this.pckAdmin = pa;
+        this.bundleContext = bundleContext;
+    }
+
+    /**
+     * @see org.apache.sling.installer.core.impl.util.BundleRefresher#refreshBundles(org.apache.sling.installer.api.tasks.InstallationContext,
java.util.List, boolean)
+     */
+    public void refreshBundles(final InstallationContext ctx,
+                               final List<Bundle> bundles,
+                               final boolean wait) {
+        if ( bundles.size() > 0 ) {
+            ctx.log("Refreshing {} bundles: {}", bundles.size(), bundles);
+            if ( !wait ) {
+                this.pckAdmin.refreshPackages(bundles.toArray(new Bundle[bundles.size()]));
+            } else {
+                this.refreshEventCount = -1;
+                this.bundleContext.addFrameworkListener(this);
+                try {
+                    this.refreshEventCount = 0;
+                    this.pckAdmin.refreshPackages(bundles.toArray(new Bundle[bundles.size()]));
+                    final long end = System.currentTimeMillis() + (MAX_REFRESH_PACKAGES_WAIT_SECONDS
* 1000);
+                    do {
+                        synchronized ( this.lock ) {
+                            final long waitTime = end - System.currentTimeMillis();
+                            if ( this.refreshEventCount < 1 && waitTime > 0
) {
+                                try {
+                                    ctx.log("Waiting up to {} seconds for bundles refresh",
MAX_REFRESH_PACKAGES_WAIT_SECONDS);
+                                    this.lock.wait(waitTime);
+                                } catch (final InterruptedException ignore) {
+                                    // ignore
+                                }
+                                if ( end <= System.currentTimeMillis() && this.refreshEventCount
< 1 ) {
+                                    logger.warn("No FrameworkEvent.PACKAGES_REFRESHED event
received within {}"
+                                                    + " seconds after refresh, aborting wait.",
+                                                    MAX_REFRESH_PACKAGES_WAIT_SECONDS);
+                                    this.refreshEventCount++;
+                                }
+                            }
+                        }
+                    } while ( this.refreshEventCount < 1);
+                } finally {
+                    this.bundleContext.removeFrameworkListener(this);
+                }
+            }
+            ctx.log("Done refreshing {} bundles", bundles.size());
+        }
+    }
+
+    /**
+     * @see org.osgi.framework.FrameworkListener#frameworkEvent(org.osgi.framework.FrameworkEvent)
+     */
+    public void frameworkEvent(final FrameworkEvent event) {
+        if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
+            logger.debug("FrameworkEvent.PACKAGES_REFRESHED");
+            synchronized (this.lock) {
+                this.refreshEventCount++;
+                this.lock.notify();
+            }
+        }
+    }
+}

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/PABundleRefresher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/PABundleRefresher.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/util/PABundleRefresher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message