You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2020/11/24 15:47:18 UTC

[GitHub] [brooklyn-server] ahgittin opened a new pull request #1126: Option to delay catalog initialization / rebind until after required OSGi services are available

ahgittin opened a new pull request #1126:
URL: https://github.com/apache/brooklyn-server/pull/1126


   More details will be in a docs PR which will come shortly and be advertised here


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [brooklyn-server] duncangrant commented on a change in pull request #1126: Option to delay catalog initialization / rebind until after required OSGi services are available

Posted by GitBox <gi...@apache.org>.
duncangrant commented on a change in pull request #1126:
URL: https://github.com/apache/brooklyn-server/pull/1126#discussion_r529707791



##########
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:
       I don't think you want to return here?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [brooklyn-server] ahgittin commented on a change in pull request #1126: Option to delay catalog initialization / rebind until after required OSGi services are available

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [brooklyn-server] duncangrant commented on a change in pull request #1126: Option to delay catalog initialization / rebind until after required OSGi services are available

Posted by GitBox <gi...@apache.org>.
duncangrant commented on a change in pull request #1126:
URL: https://github.com/apache/brooklyn-server/pull/1126#discussion_r529699668



##########
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 };

Review comment:
       Very minor but not the standard java way.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [brooklyn-server] asfgit merged pull request #1126: Option to delay catalog initialization / rebind until after required OSGi services are available

Posted by GitBox <gi...@apache.org>.
asfgit merged pull request #1126:
URL: https://github.com/apache/brooklyn-server/pull/1126


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [brooklyn-server] duncangrant commented on a change in pull request #1126: Option to delay catalog initialization / rebind until after required OSGi services are available

Posted by GitBox <gi...@apache.org>.
duncangrant commented on a change in pull request #1126:
URL: https://github.com/apache/brooklyn-server/pull/1126#discussion_r529707791



##########
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:
       I don't think you want to return here? Or probably you do but then why are you doing a null check on timeout below?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [brooklyn-server] duncangrant commented on a change in pull request #1126: Option to delay catalog initialization / rebind until after required OSGi services are available

Posted by GitBox <gi...@apache.org>.
duncangrant commented on a change in pull request #1126:
URL: https://github.com/apache/brooklyn-server/pull/1126#discussion_r529699668



##########
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 };

Review comment:
       Very minor but not the standard java way.




----------------------------------------------------------------
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:
users@infra.apache.org