ahgittin commented on a change in pull request #1126:
URL: https://github.com/apache/brooklyn-server/pull/1126#discussion_r529842552



##########
File path: 
karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java
##########
@@ -108,21 +136,178 @@ public void initOsgi() {
         }
     }
 
+    Thread fallbackThread = null;
     @Override
     public void startOsgi() {
+        final Bundle bundle = FrameworkUtil.getBundle(this.getClass());
+
+        Framework f = (Framework) bundle.getBundleContext().getBundle(0);
+        int startLevel = f.adapt(FrameworkStartLevel.class).getStartLevel();
+
+        if (areServiceDependenciesReady(bundle, bundle + " bundle 
activation")) {
+            LOG.debug("Starting OSGi catalog/rebind (no service dependencies 
or all already satisfied, on bundle activation)");
+            doStartOsgiAfterBundlesRefreshed();
+
+        } else {
+            ServiceListener sl[] = { null };
+
+
+            sl[0] = new ServiceListener() {
+                @Override
+                public void serviceChanged(ServiceEvent event) {
+                    if (areServiceDependenciesReady(bundle, "ServiceEvent[" + 
event.getServiceReference() + " / " + event.getType() + " - " + 
event.getSource() + "]")) {
+                        LOG.debug("Starting OSGi catalog/rebind - all service 
dependencies satisfied");
+                        bundle.getBundleContext().removeServiceListener(sl[0]);
+                        if (fallbackThread!=null) {
+                            fallbackThread.interrupt();
+                        }
+                        new Thread(() -> {
+                            // do this in a new thread as it takes a while, 
shouldn't run in service listener thread
+                            doStartOsgiAfterBundlesRefreshed();
+                        }).start();
+                    }
+                }
+            };
+
+            Duration timeout;
+            try {
+                timeout = Duration.parse((String) 
getBrooklynProperties().getConfig(BROOKLYN_OSGI_DEPENDENCIES_SERVICES_TIMEOUT));
+            } catch (Exception e) {
+                throw Exceptions.propagateAnnotated("Invalid duration 
specified for '"+BROOKLYN_OSGI_DEPENDENCIES_SERVICES_TIMEOUT+"'", e);
+            }
+            fallbackThread = new Thread(() -> {
+                if (timeout==null) {
+                    LOG.debug("No timeout specified for 
'"+BROOKLYN_OSGI_DEPENDENCIES_SERVICES_TIMEOUT+"'; will wait indefinitely for 
service dependencies");
+                    return;

Review comment:
       good spot - thx, fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to