Apache Felix Dependency Manager - Getting StartedPage edited by Marcel OffermansGetting StartedWhen developing an OSGi bundle that has dependencies and possibly registers services, there are two classes in particular we need to implement:
When using the dependency manager, your bundle activator is a subclass of DependencyActivatorBase. It needs to implement two life cycle methods: init and destroy. Both methods take two arguments: BundleContext and DependencyManager. The latter is your interface to the declarative API you can use to define your services and dependencies. The following paragraphs will show various examples that explain how to do this. Subsequently, some more advanced scenarios will be covered that involve listening to dependency and service state changes and interacting with the OSGi framework from within your service implementation. Registering a serviceThe first example is about registering a service. We extend DependencyActivatorBase and in the init method we use the reference to the DependencyManager to create and add a service. For this service we subsequently set its interface and implementation. In this case the interface is the Store interface, the second parameter, null, allows you to provide properties along with the service registration. For the implementation, we only mention the Class of the implementation, which means the dependency manager will lazily instantiate it. In this case, there is not much point in doing that because the service has no dependencies, but if it had, the instantiation would only happen when those dependencies were resolved. public class Activator extends DependencyActivatorBase { public void init(BundleContext context, DependencyManager manager) throws Exception { manager.add(createService() .setInterface(Store.class.getName(), null) .setImplementation(MemoryStore.class) ); } public void destroy(BundleContext context, DependencyManager manager) throws Exception {} }
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Felix > Apache Felix Dependency Manager - Gett... confluence
- [CONF] Apache Felix > Apache Felix Dependency Manager -... confluence
- [CONF] Apache Felix > Apache Felix Dependency Manager -... confluence
- [CONF] Apache Felix > Apache Felix Dependency Manager -... confluence
- [CONF] Apache Felix > Apache Felix Dependency Manager -... confluence
- [CONF] Apache Felix > Apache Felix Dependency Manager -... confluence
- [CONF] Apache Felix > Apache Felix Dependency Manager -... confluence
- [CONF] Apache Felix > Apache Felix Dependency Manager -... confluence
- [CONF] Apache Felix > Apache Felix Dependency Manager -... confluence
