You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:53:03 UTC

[sling-org-apache-sling-launchpad-installer] 02/06: SLING-2376 : New Startup Features

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.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-launchpad-installer.git

commit f72cee273453c35307ecb694fe007c843463d44b
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Jan 19 16:16:55 2012 +0000

    SLING-2376 : New Startup Features
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/launchpad/installer@1233447 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  4 +-
 .../installer/impl/LaunchpadListener.java          | 47 ++++++++++++++++++++++
 .../launchpad/installer/impl/ServicesListener.java | 30 +++++++++++++-
 3 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 71b2261..d8ded26 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,13 +55,13 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.launchpad.api</artifactId>
-            <version>1.0.0</version>
+            <version>1.0.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.installer.core</artifactId>
-            <version>3.2.2</version>
+            <version>3.3.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
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
new file mode 100644
index 0000000..22836a1
--- /dev/null
+++ b/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadListener.java
@@ -0,0 +1,47 @@
+/*
+ * 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.launchpad.installer.impl;
+
+import org.apache.sling.installer.api.event.InstallationEvent;
+import org.apache.sling.installer.api.event.InstallationListener;
+import org.apache.sling.launchpad.api.StartupHandler;
+
+public class LaunchpadListener implements InstallationListener {
+
+    private final StartupHandler startupHandler;
+
+    private volatile boolean started = false;
+
+    public LaunchpadListener(final StartupHandler startupHandler) {
+        this.startupHandler = startupHandler;
+    }
+
+    /**
+     * @see org.apache.sling.installer.api.event.InstallationListener#onEvent(org.apache.sling.installer.api.event.InstallationEvent)
+     */
+    public void onEvent(final InstallationEvent event) {
+        if ( event.getType() == InstallationEvent.TYPE.STARTED ) {
+            this.startupHandler.waitWithStartup(true);
+            started = true;
+        } else if ( event.getType() == InstallationEvent.TYPE.SUSPENDED ) {
+            if ( started ) {
+                this.startupHandler.waitWithStartup(false);
+            }
+        }
+    }
+
+}
\ No newline at end of file
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 170c2d0..6d7f08c 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
@@ -19,13 +19,16 @@
 package org.apache.sling.launchpad.installer.impl;
 
 import org.apache.sling.installer.api.OsgiInstaller;
+import org.apache.sling.installer.api.event.InstallationListener;
 import org.apache.sling.launchpad.api.LaunchpadContentProvider;
+import org.apache.sling.launchpad.api.StartupHandler;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 
 /**
  * The <code>ServicesListener</code> listens for the required services
@@ -43,12 +46,21 @@ public class ServicesListener {
     /** The listener for the provider. */
     private final Listener providerListener;
 
+    /** The listener for the startup handler. */
+    private final Listener startupListener;
+
+    private ServiceRegistration launchpadListenerReg;
+
+    private volatile boolean installed = false;
+
     public ServicesListener(final BundleContext bundleContext) {
         this.bundleContext = bundleContext;
         this.installerListener = new Listener(OsgiInstaller.class.getName());
         this.providerListener = new Listener(LaunchpadContentProvider.class.getName());
+        this.startupListener = new Listener(StartupHandler.class.getName());
         this.installerListener.start();
         this.providerListener.start();
+        this.startupListener.start();
     }
 
     public synchronized void notifyChange() {
@@ -57,7 +69,22 @@ public class ServicesListener {
         final LaunchpadContentProvider lcp = (LaunchpadContentProvider)this.providerListener.getService();
 
         if ( installer != null && lcp != null ) {
-            LaunchpadConfigInstaller.install(installer, lcp);
+            if ( !installed ) {
+                installed = true;
+                LaunchpadConfigInstaller.install(installer, lcp);
+            }
+        }
+        final StartupHandler handler = (StartupHandler)this.startupListener.getService();
+        if ( handler != null ) {
+            if ( launchpadListenerReg == null ) {
+                final LaunchpadListener launchpadListener = new LaunchpadListener(handler);
+                launchpadListenerReg = this.bundleContext.registerService(InstallationListener.class.getName(), launchpadListener, null);
+            }
+        } else {
+            if ( launchpadListenerReg != null ) {
+                launchpadListenerReg.unregister();
+                launchpadListenerReg = null;
+            }
         }
     }
 
@@ -67,6 +94,7 @@ public class ServicesListener {
     public void deactivate() {
         this.installerListener.deactivate();
         this.providerListener.deactivate();
+        this.startupListener.deactivate();
     }
 
     protected final class Listener implements ServiceListener {

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