Tuesday, December 25, 2012

How to register an OSGI service

For this , I will use a code segment from wso2 appfactory.

The necessary code should be written inside the activate method which usually resides inside 'internal' package


protected void activate(ComponentContext context) {
BundleContext bundleContext = context.getBundleContext();
try {
MavenBuildDriver driver = new MavenBuildDriver();
bundleContext.registerService(BuildDriver.class.getName(), driver, null);
if (log.isDebugEnabled()) {
log.debug("Appfactory common bundle is activated");
}
} catch (Throwable e) {
log.error("Error in creating appfactory configuration", e);
}
}


In the above code BuildDriver is the interface.
the driver is an object of the class which implements the BuildDriver interface.

The content inside internal is not exposed. refer the pom.xml


                         <Private-Package>
                            org.wso2.carbon.appfactory.maven.build.internal.*,
                            org.wso2.carbon.appfactory.jenkins.build.internal.*
                        </Private-Package>

No comments:

Post a Comment

..