sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-launchpad-installer] 05/07: SLING-2552 : Correctly handle register/unregister of OSGi installer
Date Tue, 07 Nov 2017 09:53:22 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.launchpad.installer-1.1.4
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-launchpad-installer.git

commit 7d4c6ca165ca5b3b6e11e2474ffd9d767501195f
Author: Carsten Ziegeler <cziegeler@apache.org>
AuthorDate: Wed Aug 1 12:39:41 2012 +0000

    SLING-2552 : Correctly handle register/unregister of OSGi installer
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/launchpad/installer@1367962 13f79535-47bb-0310-9956-ffa450edef68
---
 .../installer/impl/LaunchpadListener.java          | 25 ++++++++++++++++++----
 .../launchpad/installer/impl/ServicesListener.java |  6 +++++-
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadListener.java
b/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadListener.java
index 22836a1..62b9780 100644
--- a/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadListener.java
+++ b/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadListener.java
@@ -35,12 +35,29 @@ public class LaunchpadListener implements InstallationListener {
      */
     public void onEvent(final InstallationEvent event) {
         if ( event.getType() == InstallationEvent.TYPE.STARTED ) {
+            this.start();
+        } else if ( event.getType() == InstallationEvent.TYPE.SUSPENDED ) {
+            this.stop();
+        }
+    }
+
+    /**
+     * Suspend the startup handler (if not already done so)
+     */
+    public void start() {
+        if ( !started ) {
             this.startupHandler.waitWithStartup(true);
             started = true;
-        } else if ( event.getType() == InstallationEvent.TYPE.SUSPENDED ) {
-            if ( started ) {
-                this.startupHandler.waitWithStartup(false);
-            }
+        }
+    }
+
+    /**
+     * Make sure the startup handler is not in suspended state
+     */
+    public void stop() {
+        if ( started ) {
+            this.startupHandler.waitWithStartup(false);
+            started = false;
         }
     }
 
diff --git a/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java
b/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java
index 03f7883..732b53c 100644
--- a/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java
+++ b/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java
@@ -57,6 +57,8 @@ public class ServicesListener {
     /** Boolean marker to not reprocess things. */
     private volatile boolean installed = false;
 
+    private LaunchpadListener launchpadListener;
+
     /**
      * Start listeners
      */
@@ -84,7 +86,7 @@ public class ServicesListener {
         if ( installer != null && lcp != null && handler != null ) {
             if ( !this.installed ) {
                 this.installed = true;
-                final LaunchpadListener launchpadListener = new LaunchpadListener(handler);
+                this.launchpadListener = new LaunchpadListener(handler);
                 final Dictionary<String, Object> props = new Hashtable<String, Object>();
                 props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Launchpad Startup
Listener");
                 props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
@@ -102,9 +104,11 @@ public class ServicesListener {
         this.providerListener.deactivate();
         this.startupListener.deactivate();
         if ( this.launchpadListenerReg != null ) {
+            this.launchpadListener.stop();
             this.launchpadListenerReg.unregister();
             this.launchpadListenerReg = null;
         }
+        this.launchpadListener = null;
     }
 
     /**

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message