To register a service, an instance of the implementation class needs to be created and registered with the framework. Interactions with the framework are performed with an instance of BundleContext
—typically provided in the BundleActivator.start
method and stored for later use. The *FeedParser
classes from the previous chapter will be extended to support registration as a service instead of the Equinox extension registry.
A bundle's activator is a class that is instantiated and coupled to the lifetime of the bundle. When a bundle is started, if a manifest entry Bundle-Activator
exists, then the corresponding class is instantiated. As long as it implements the BundleActivator
interface, the start
method will be called. This method is passed as an instance of BundleContext
, which is the bundle's connection to the hosting OSGi framework.
Create a class in the com.packtpub.e4.advanced.feeds
project called com.packtpub.e4.advanced.feeds...