You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2022/02/21 17:18:27 UTC

[unomi] branch UNOMI-552-fix-lifecycle created (now aaf1c94)

This is an automated email from the ASF dual-hosted git repository.

shuber pushed a change to branch UNOMI-552-fix-lifecycle
in repository https://gitbox.apache.org/repos/asf/unomi.git.


      at aaf1c94  Attempt to fix issue with release:prepare locking Unomi startup. - Added a dependency to Unomi in Groovy actions feature - Added a check of bundle states at initialization of Lifecycle Manager, in case it gets started after bundles that are required.

This branch includes the following new commits:

     new aaf1c94  Attempt to fix issue with release:prepare locking Unomi startup. - Added a dependency to Unomi in Groovy actions feature - Added a check of bundle states at initialization of Lifecycle Manager, in case it gets started after bundles that are required.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[unomi] 01/01: Attempt to fix issue with release:prepare locking Unomi startup. - Added a dependency to Unomi in Groovy actions feature - Added a check of bundle states at initialization of Lifecycle Manager, in case it gets started after bundles that are required.

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shuber pushed a commit to branch UNOMI-552-fix-lifecycle
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit aaf1c9485aa5fba5621ed50f12f3e822fa01ed4a
Author: Serge Huber <sh...@jahia.com>
AuthorDate: Mon Feb 21 18:18:20 2022 +0100

    Attempt to fix issue with release:prepare locking Unomi startup.
    - Added a dependency to Unomi in Groovy actions feature
    - Added a check of bundle states at initialization of Lifecycle Manager, in case it gets started after bundles that are required.
---
 .../karaf-kar/src/main/feature/feature.xml         |  2 +-
 .../org/apache/unomi/lifecycle/BundleWatcher.java  | 29 ++++++++++++++--------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/extensions/groovy-actions/karaf-kar/src/main/feature/feature.xml b/extensions/groovy-actions/karaf-kar/src/main/feature/feature.xml
index ff73575..c3aa72a 100644
--- a/extensions/groovy-actions/karaf-kar/src/main/feature/feature.xml
+++ b/extensions/groovy-actions/karaf-kar/src/main/feature/feature.xml
@@ -19,7 +19,7 @@
     <feature name="unomi-groovy-actions" description="${project.name}" version="${project.version}">
         <details>${project.description}</details>
         <feature prerequisite="true" dependency="false">wrap</feature>
-        <feature>unomi-kar</feature>
+        <feature dependency="true">unomi-kar</feature>
         <bundle start-level="85">mvn:org.codehaus.groovy/groovy/3.0.3</bundle>
         <bundle start-level="85">mvn:org.codehaus.groovy/groovy-xml/3.0.3</bundle>
         <bundle start-level="85" start="false">mvn:org.apache.unomi/unomi-groovy-actions-services/${project.version}</bundle>
diff --git a/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java b/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java
index 16e3edf..31eec3b 100644
--- a/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java
+++ b/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java
@@ -16,14 +16,7 @@
  */
 package org.apache.unomi.lifecycle;
 
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,7 +42,7 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener
     private static final Logger logger = LoggerFactory.getLogger(BundleWatcher.class.getName());
 
     private long startupTime;
-    private Map<String, Boolean> requiredBundles;
+    private Map<String, Boolean> requiredBundles = new ConcurrentHashMap<>();
 
     private ScheduledExecutorService scheduler;
     private ScheduledFuture<?> scheduledFuture;
@@ -92,6 +85,7 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener
 
     public void init() {
         scheduler = Executors.newSingleThreadScheduledExecutor();
+        checkExistingBundles();
         bundleContext.addBundleListener(this);
         bundleContext.addServiceListener(this);
         loadLogo();
@@ -123,13 +117,26 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener
         logger.info("Bundle watcher shutdown.");
     }
 
+    public void checkExistingBundles() {
+        for (Bundle bundle : bundleContext.getBundles()) {
+            if (bundle.getSymbolicName().startsWith("org.apache.unomi") && requiredBundles.containsKey(bundle.getSymbolicName())) {
+                if (bundle.getState() == Bundle.ACTIVE) {
+                    requiredBundles.put(bundle.getSymbolicName(), true);
+                } else {
+                    requiredBundles.put(bundle.getSymbolicName(), false);
+                }
+            }
+        }
+        checkStartupComplete();
+    }
+
     @Override
     public void bundleChanged(BundleEvent event) {
         switch (event.getType()) {
             case BundleEvent.STARTING:
                 break;
             case BundleEvent.STARTED:
-                if (event.getBundle().getSymbolicName().startsWith("org.apache.unomi")) {
+                if (event.getBundle().getSymbolicName().startsWith("org.apache.unomi") && requiredBundles.containsKey(event.getBundle().getSymbolicName())) {
                     logger.info("Bundle {} was started.", event.getBundle().getSymbolicName());
                     requiredBundles.put(event.getBundle().getSymbolicName(), true);
                     checkStartupComplete();
@@ -138,7 +145,7 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener
             case BundleEvent.STOPPING:
                 break;
             case BundleEvent.STOPPED:
-                if (event.getBundle().getSymbolicName().startsWith("org.apache.unomi")) {
+                if (event.getBundle().getSymbolicName().startsWith("org.apache.unomi") && requiredBundles.containsKey(event.getBundle().getSymbolicName())) {
                     logger.info("Bundle {} was stopped", event.getBundle().getSymbolicName());
                     requiredBundles.put(event.getBundle().getSymbolicName(), false);
                 }