Enterprise Integration Zone is brought to you in partnership with:

I am a graduate of University of Westminster UK (IIT) B Sc Software Engineering ( First Class Honours). I am a Sun Certified Java Programmer for Java 2 platform, 1.5 versions (SCJP 1.5). – 93% and a Sun Certified Web Component Developer 97%. I work as a Software Engineer at WSO2. Achala is a DZone MVB and is not an employee of DZone and has posted 20 posts at DZone. You can read more from them at their website. View Full User Profile

How to register an OSGI service

01.08.2013
| 2190 views |
  • submit to reddit

  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>



Published at DZone with permission of Achala Chathuranga Aponso, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

santhosh replied on Thu, 2014/01/09 - 1:29am


Instead use Apache Felix Implementation Annotation base 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.