Interface BundleAdapterBuilder

All Superinterfaces:
ComponentBuilder<BundleAdapterBuilder>

public interface BundleAdapterBuilder extends ComponentBuilder<BundleAdapterBuilder>
Builds a Dependency Manager bundle adapter.

The adapter created by this builder will be applied to any bundle that matches the specified bundle state mask and filter condition. For each matching bundle an adapter service will be created based on the adapter implementation class. The adapter will be registered with the specified interface and existing properties from the original bundle plus any extra properties you supply here. The bundle is injected by reflection in adapter class fields having a Bundle type, or using a callback method that you can specify. You can specify reflection based (using method names), or java8 method references for callbacks.

Example which creates a BundleAdapter service for each started bundle (the bundle is added by reflection on a class field that has a "Bundle" type):

 
 public class Activator extends DependencyManagerActivator {
     public void init(BundleContext ctx, DependencyManager dm) throws Exception { 
       bundleAdapter(adapt -> adapt
           .impl(BundleAdapterImpl.class)
           .provides(BundleAdapter.class)
           .mask(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE));
    }
 }
  
Example that creates a BundleAdapter service for each started bundle (the bundle is added using a method reference):
 
 public class Activator extends DependencyManagerActivator {
     public void init(BundleContext ctx, DependencyManager dm) throws Exception { 
       bundleAdapter(adapt -> adapt
           .impl(BundleAdapterImpl.class)
           .provides(BundleAdapter.class)
           .mask(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE)
           .add(BundleAdapterImpl::setBundle));
    }
 }
 
Example that creates a BundleAdapter service for each started bundle (the bundle is added using a method name):
 
 public class Activator extends DependencyManagerActivator {
     public void init(BundleContext ctx, DependencyManager dm) throws Exception { 
       bundleAdapter(adapt -> adapt
           .impl(BundleAdapterImpl.class)
           .provides(BundleAdapter.class)
           .mask(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE)
           .add("setBundle"));
    }
 }
 
Author:
Felix Project Team
  • Method Details

    • mask

      BundleAdapterBuilder mask(int mask)
      Sets the bundle state mask to depend on. The OSGi BundleTracker explains this mask in more detail, but it is basically a mask with flags for each potential state a bundle can be in.
      Parameters:
      mask - the mask to use
      Returns:
      this builder
    • filter

      BundleAdapterBuilder filter(String filter)
      Sets the filter condition to depend on. Filters are matched against the full manifest of a bundle.
      Parameters:
      filter - the filter condition
      Returns:
      this builder
    • propagate

      BundleAdapterBuilder propagate(boolean propagate)
      Sets property propagation. If set to true any bundle manifest properties will be added to the service properties of the component that has this dependency (if it registers as a service).
      Parameters:
      propagate - true to propagate the bundle manifest properties
      Returns:
      this builder
    • propagate

      Enables property propagation. Any bundle manifest properties will be added to the service properties of the component that has this dependency (if it registers as a service).
      Returns:
      this builder
    • add

      Sets a "add" callback name invoked on the component implementation instance(s). The callback can be used as hooks whenever the dependency is added. When you specify a callback, the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.
      Parameters:
      callback - the method to call when a bundle was added The following method signature are supported:
      
       callback(Bundle b)
       callback(Component c, Bundle b)
       
      callback - the callback name
      Returns:
      this builder.
    • change

      BundleAdapterBuilder change(String callback)
      Sets a "change" callback name invoked on the component implementation instance(s). The callback can be used as hooks whenever the dependency is changed. When you specify a callback, the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.
      Parameters:
      callback - the method to call when a bundle was changed The following method signature are supported:
      
       callback(Bundle b)
       callback(Component c, Bundle b)
       
      callback - the callback name
      Returns:
      this builder.
    • remove

      BundleAdapterBuilder remove(String callback)
      Sets a "remove" callback name invoked on the component implementation instance(s). The callback can be used as hooks whenever the dependency is removed. When you specify a callback, the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.
      Parameters:
      callback - the method to call when a bundle was removed The following method signature are supported:
      
       callback(Bundle b)
       callback(Component c, Bundle b)
       
      callback - the callback name
      Returns:
      this builder.
    • callbackInstance

      BundleAdapterBuilder callbackInstance(Object callbackInstance)
      Sets a callback instance to use when invoking reflection based callbacks.
      Parameters:
      callbackInstance - the instance to call the reflection based callbacks on
      Returns:
      this builder.
      See Also:
    • add

      <T> BundleAdapterBuilder add(CbBundle<T> add)
      Sets a reference to a callback method invoked on one of the component implementation classes. The method reference must point to a Component implementation class method, it is called when the bundle is added and takes as argument a Bundle.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked.
      Parameters:
      add - the method reference invoked when a bundle is added.
      Returns:
      this builder
    • change

      <T> BundleAdapterBuilder change(CbBundle<T> change)
      Sets a reference to a callback method invoked on one of the component implementation classes. The method reference must point to a Component implementation class method, it is called when the bundle is changed and takes as argument a Bundle.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked.
      Parameters:
      change - the method reference invoked when a bundle has changed.
      Returns:
      this builder
    • remove

      <T> BundleAdapterBuilder remove(CbBundle<T> remove)
      Sets a reference to a callback method invoked on one of the component implementation classes. The method reference must point to a Component implementation class method, it is called when the bundle is removed and takes as argument a Bundle.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked.
      Parameters:
      remove - the method reference invoked when a bundle is removed.
      Returns:
      this builder
    • add

      Sets a reference to a callback method invoked on one of the component implementation classes. The method reference must point to a Component implementation class method, it is called when the bundle is added and takes as argument a Bundle and a Component.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked.
      Parameters:
      add - the method reference invoked when a bundle is added.
      Returns:
      this builder
    • change

      <T> BundleAdapterBuilder change(CbBundleComponent<T> change)
      Sets a reference to a callback method invoked on one of the component implementation classes. The method reference must point to a Component implementation class method, it is called when the bundle is changed and takes as argument a Bundle and a Component.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked.
      Parameters:
      change - the method reference invoked when a bundle has changed.
      Returns:
      this builder
    • remove

      <T> BundleAdapterBuilder remove(CbBundleComponent<T> remove)
      Sets a reference to a callback method invoked on one of the component implementation classes. The method reference must point to a Component implementation class method, it is called when the bundle is removed and takes as argument a Bundle and a Component.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked.
      Parameters:
      remove - the method reference invoked when a bundle is removed.
      Returns:
      this builder
    • add

      Sets a reference to a callback method invoked on a given Object instance. The method reference is invoked when the bundle is added and takes as argument a Bundle.
      Parameters:
      add - the method reference invoked when a bundle is added.
      Returns:
      this builder
    • change

      Sets a reference to a callback method invoked on a given Object instance. The method reference is invoked when the bundle has changed and takes as argument a Bundle.
      Parameters:
      change - the method reference invoked when a bundle has changed.
      Returns:
      this builder
    • remove

      Sets a reference to a callback method invoked on a given Object instance. The method reference is invoked when the bundle is removed and takes as argument a Bundle.
      Parameters:
      remove - the method reference invoked when a bundle is removed.
      Returns:
      this builder
    • add

      Sets a reference to a callback method invoked on a given Object instance. The method reference is invoked when the bundle is added and takes as argument a Bundle and a Component.
      Parameters:
      add - the method reference invoked when a bundle is added.
      Returns:
      this builder
    • change

      Sets a reference to a callback method invoked on a given Object instance. The method reference is invoked when the bundle has changed and takes as argument a Bundle and a Component.
      Parameters:
      change - the method reference invoked when a bundle has changed.
      Returns:
      this builder
    • remove

      Sets a reference to a callback method invoked on a given Object instance. The method reference is invoked when the bundle is removed and takes as argument a Bundle and a Component.
      Parameters:
      remove - the method reference invoked when a bundle is removed.
      Returns:
      this builder