Reputation: 13861
We are running Apache ServiceMix 4 ESB which runs an Apache Karaf container based on OSGi. OSGi offers facilities, which are exposed in the ServiceMix console, that report information on the state of bundles installed in the container:
osgi:list
I've searched high and low. Now I'm asking: Does anyone know of any working examples, guides on using the API or other guidance in accessing this information from within code running in the ESB? Ideally, I would like to:
Please share any information available on this, or just any avenues from which to start better researching it.
Thanks.
Upvotes: 1
Views: 3048
Reputation: 11502
Blueprint is of limited use for this, since Blueprint is by definition declarative and you want to do something programatically. However, Blueprint can set you on your way by injecting a bundle context. Once you have a bundle context you can use the org.osgi.framework
APIs to get all the bundles (context.getBundles()
), query their state, start and stop them, and so on.
Your requirement 3), loading a bundle, doesn't really make sense in an OSGi context, since their lifecycle is that they get installed and then started. If a bundle hasn't been installed it won't be included in getBundles(), but it can be installed using the context.
To inject the context into a Blueprint bean, use a special property:
<bean class="SomeClass">
<property name="context" ref="blueprintBundleContext"/>
</bean>
I've borrowed that example from Enterprise OSGi in Action, but there's a very good Blueprint tutorial on developerWorks: http://www.ibm.com/developerworks/opensource/library/os-osgiblueprint/
A similar question was asked recently, which you may also find useful: How should I implement the OSGi console into a Bundle? (ss
is similar to bundle:list
, although it doesn't give any Blueprint-specific information).
Upvotes: 2