Reputation: 555
I am working on a project that requires to monitor and manage (start, stop, install, uninstall, update) OSGi bundles in an OSGi based application using pre-programed instructions, similar to java reflections, the OSGi application can reflect upon itself by monitoring itself and its context, it can update or remove some bundle or can add(install and start) a new bundle.
For example, there is a chat application developed using OSGi bundles. In order to add self-managing characteristics to it, there need to be a mechanism to monitor and manage (install/uninstall, start/stop, update) OSGi bundles autonomically (without human intervention or as little human involvement as possible). Any idea how this can be achieved?
I tried to explain the problem, but feel free to ask if you dont understand my question.
P.S. I am using OSGi Equinox framework.
Regards.
Upvotes: 1
Views: 1022
Reputation: 15372
You might want to look at Apache Felix FileInstall source code. It is probably the simplest 'management agent' that can be used to fully manage an OSGi framework (including the oh so important Configuration Admin).
Upvotes: 1
Reputation: 662
The OSGi framework already includes such a mechanism and gives you full control over the bundles lifecycle using the most basic OSGi interfaces.
If you want to control it from inside an OSGi bundle, let's call it a management agent bundle, you can use the BundleContext of this bundle to:
org.osgi.framework.BundleContext
installBundle(java.lang.String location) Installs a bundle from the specified location identifier. getBundles() Returns a list of all installed bundles. getBundle(long id) Returns the bundle with the specified identifier.
Once you have the Bundle object, you can lookup everything about the bundle, like name, imported packages, etc; and start, stop, update the bundle. So, there you can implement whatever logic your zero-administration policy states (e.g. restart all plugin bundles when an error occurs, or search for a suitable plugin and install it when new content has to be rendered, or whatever)
Now, if you want to do all this from "outside" OSGi, you will have to publish some kind of interface for outside in your management agent bundle. One possibility could be a web page (OSGi contains a simple embedded web server, check the HTTPService). There are many others, depending on what you want to achieve.
Hope this helps :)
Upvotes: 3
Reputation: 2748
The BundleListener class might also be useful to you, it will notify you of any bundles starting or stopping.
Upvotes: 1
Reputation: 11502
Have a look at the org.osgi.framework
javadoc. From the bundle context of your bundle, you can install and get bundles. The bundle API allows you to stop, start, and update bundles.
Upvotes: 1