[BROOKLYN-183] Fix detection of OSGi framework Fix the code detecting if we are running within an OSGi framework.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ed6f1df1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ed6f1df1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ed6f1df1 Branch: refs/heads/master Commit: ed6f1df199c268fdf2811abd15a3de967840b1ee Parents: c61f719 Author: Ciprian Ciubotariu <cheepe...@gmx.net> Authored: Thu Nov 19 12:27:39 2015 +0200 Committer: Ciprian Ciubotariu <cheepe...@gmx.net> Committed: Thu Nov 19 12:27:39 2015 +0200 ---------------------------------------------------------------------- .../apache/brooklyn/util/core/osgi/Osgis.java | 22 +++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ed6f1df1/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java index be24dc1..8777032 100644 --- a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java +++ b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java @@ -318,12 +318,10 @@ public class Osgis { * @todo Use felixCacheDir ? */ public static Framework getFramework(String felixCacheDir, boolean clean) { - final Bundle frameworkBundle = FrameworkUtil.getBundle(Framework.class); - if (frameworkBundle != null) { + final Bundle bundle = FrameworkUtil.getBundle(Osgis.class); + if (bundle != null) { // already running inside an OSGi container - final BundleContext ctx = frameworkBundle.getBundleContext(); - final ServiceReference<?> ref = ctx.getServiceReference(Framework.class); - return (Framework) ctx.getService(ref); + return (Framework) bundle.getBundleContext().getBundle(0); } else { // not running inside OSGi container return EmbeddedFelixFramework.newFrameworkStarted(felixCacheDir, clean, null); @@ -338,12 +336,12 @@ public class Osgis { * @param framework */ public static void ungetFramework(Framework framework) { - final Bundle frameworkBundle = FrameworkUtil.getBundle(Framework.class); - if (frameworkBundle != null) { - // already running inside an OSGi container - final BundleContext ctx = frameworkBundle.getBundleContext(); - final ServiceReference<?> ref = ctx.getServiceReference(Framework.class); - ctx.ungetService(ref); + final Bundle bundle = FrameworkUtil.getBundle(Osgis.class); + if (bundle != null) { +// // already running inside an OSGi container +// final BundleContext ctx = bundle.getBundleContext(); +// final ServiceReference<Framework> ref = ctx.getServiceReference(Framework.class); +// ctx.ungetService(ref); } else { EmbeddedFelixFramework.stopFramework(framework); } @@ -352,7 +350,7 @@ public class Osgis { /** Tells if Brooklyn is running in an OSGi environment or not. */ public static boolean isBrooklynInsideFramework() { - return FrameworkUtil.getBundle(Framework.class) != null; + return FrameworkUtil.getBundle(Osgis.class) != null; } /** @deprecated since 0.9.0, replaced with {@link OsgiUtils#getVersionedId(org.osgi.framework.Bundle) } */