Home » Documentation » Apache Felix Subproject Documentation » Apache Felix Dependency Manager

Dependency Manager - Bundle Adapter

Bundle adapters are similar to AdapterService, but instead of adapting a service, they adapt a bundle with a certain set of states (STARTED|INSTALLED|...), and provide a service on top of it.

The bundle adapter will be applied to any bundle that matches the specified bundle state mask and filter conditions, which may match some of the bundle OSGi manifest headers. For each matching bundle an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface and with service properties found from the original bundle OSGi manifest headers plus any extra properties you supply here. If you declare the original bundle as a member it will be injected.

An example:

manager.createBundleAdapterService(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE, 
    "(Bundle-SymbolicName=org.apache.felix.dependencymanager)", true)
    .setInterface(AdapterService.class.getName(), new Hashtable() )


The following attributes are supported.

Annotation attributes:

Required: False
Default: --

The filter used to match some OSGi manifest headers from a given bundle.

Required: False
Default: all directly implemented interfaces.

The interface(s) to use when registering adapters. By default, the interface(s) directly implemented by the annotated class is (are) used.

Required: False
Default: --

Additional properties to use with the service registration.

Required: False

The bundle state mask to apply. The mask is made up of the flags provided by the org.osgi.framework.Bundle states (UNINSTALLED | INSTALLED | RESOLVED | STARTING | STARTED | ACTIVE).

Required: False
Default: true

Specifies if manifest headers from the bundle should be propagated to the exposed service properties.

Required: False
Default: --

Sets the static method used to create the BundleAdapterService implementation instance.

Usage Examples

In the following example, a "VideoPlayer" Service is registered into the OSGi registry each time an active bundle containing a "Video-Path" manifest header is detected:

@BundleAdapterService(filter = "(Video-Path=*)", stateMask = Bundle.ACTIVE, propagate=true)
public class VideoPlayerImpl implements VideoPlayer {
    Bundle bundle; // Injected by reflection

    void play() {
        URL mpegFile = bundle.getEntry(bundle.getHeaders().get("Video-Path"));
        // play the video provided by the bundle ...

    void stop() {}
Rev. 1665812 by marrs on Wed, 11 Mar 2015 09:02:04 +0000
Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.