Sunday, March 24, 2013

Create Apache Shell Command to check Gemini Blueprint Service

One of the annoying thing in using Eclipse Gemini is that if a dependency service is not available, it will wait for 5 mins (default) and threw timeout exception.  and even if the application context is not created (because of the timeout), the bundle's status is still active.  So I have decided to build a simple command to Apache Shell so that I can find out if there's any unsatisfied dependencies using Apache Felix WebConsole.

First we need to build a fragment bundle to gemini blueprint extender by adding this to the bundle's

Fragment-Host: org.eclipse.gemini.blueprint.extender

Next create a class extending OsgiBundleApplicationContextListener

in the onOsgiApplicationEvent, simply build a map to store all service dependency status.  Since it's collecting event data (and that it is a fragment), so the bundle have to be installed before starting the blueprint extender and other bundles that you want to capture the events.

and build another bundle which implements Apache Shell's Command and simply call the last bundle and prints out the result.

My command's name is "geministatus" (just return "geministatus" in the getName method of  your Command) so when you navigate to the shell tab of your felix webconsole, you can type geministatus and you'll find out if any bundles is waiting for any services to start the application context.