Interface ServiceDependencyBuilder<S>

Type Parameters:
S - the type of the service dependency
All Superinterfaces:
DependencyBuilder<org.apache.felix.dm.ServiceDependency>, ServiceCallbacksBuilder<S,ServiceDependencyBuilder<S>>

public interface ServiceDependencyBuilder<S> extends DependencyBuilder<org.apache.felix.dm.ServiceDependency>, ServiceCallbacksBuilder<S,ServiceDependencyBuilder<S>>
Builds a Dependency Manager Service Dependency.

Sample code:

 
 public class Activator extends DependencyManagerActivator {
    public void init(BundleContext ctx, DependencyManager dm) throws Exception {
       component(comp -> comp
          .impl(Pojo.class)
          .withSvc(ConfigurationAdmin.class, LogService.class) // varargs of optional (possibly NullObjects) dependencies injected in compatible class fields
          .withSvc(true, Coordinator.class, LogService.class) // varargs of required dependencies injected in compatible class fields
          .withSvc(ConfigurationAdmin.class, "(vendor=apache)") // service with a filter, injected in compatible class fields
          .withSvc(ConfigurationAdmin.class, "(vendor=apache)", true) // required service with a filter, injected in compatible class fields
          .withSvc(ConfigurationAdmin.class, "(vendor=apache)", true, "field") // required service with a filter, injected in a given class field name
          .withSvc(HttpService.class, svc -> svc.required().add(Pojo::setHttpService)) // required dependency injected using a method reference
          .withSvc(Tracked.class, svc -> svc.optional().add(Pojo::addTracked)) // optional dependency, injected using method ref, after the start() callback
    }
 }
  • Method Details

    • filter

      Configures the service dependency filter
      Parameters:
      filter - the service filter
      Returns:
      this builder
    • ref

      ServiceDependencyBuilder<S> ref(org.osgi.framework.ServiceReference<S> ref)
      Configures this dependency with the given ServiceReference.
      Parameters:
      ref - the service reference
      Returns:
      this builder
    • optional

      Configures this dependency as optional.
      Returns:
      this builder
    • required

      Configures this dependency as required.
      Returns:
      this builder
    • required

      ServiceDependencyBuilder<S> required(boolean required)
      Configures whether this dependency is required or not.
      Parameters:
      required - true if the dependency is required, false if not.
      Returns:
      this builder
    • debug

      Configures debug mode
      Parameters:
      label - the label used by debug messages
      Returns:
      this builder
    • propagate

      Propagates the dependency properties to the component service properties.
      Returns:
      this builder
    • propagate

      ServiceDependencyBuilder<S> propagate(boolean propagate)
      Configures whether the dependency properties must be propagated or not to the component service properties.
      Parameters:
      propagate - true if the service dependency properties should be propagated to the properties provided by the component using this dependency.
      Returns:
      this builder
    • propagate

      ServiceDependencyBuilder<S> propagate(Object instance, String method)
      Configures a method that can is called in order to get propagated service properties.
      Parameters:
      instance - an object instance
      method - the method name to call on the object instance. This method returns the propagated service properties.
      Returns:
      this builder
    • propagate

      ServiceDependencyBuilder<S> propagate(Function<org.osgi.framework.ServiceReference<S>,Dictionary<String,Object>> propagate)
      Specifies a function that is called to get the propagated service properties for this service dependency.
      Parameters:
      propagate - a function that is called to get the propagated service properties for this service dependency.
      Returns:
      this builder
    • propagate

      ServiceDependencyBuilder<S> propagate(BiFunction<org.osgi.framework.ServiceReference<S>,S,Dictionary<String,Object>> propagate)
      Specifies a function that is called to get the propagated service properties for this service dependency.
      Parameters:
      propagate - a function that is called to get the propagated service properties for this service dependency.
      Returns:
      this builder
    • defImpl

      ServiceDependencyBuilder<S> defImpl(Object defaultImpl)
      Sets the default implementation if the service is not available.
      Parameters:
      defaultImpl - the implementation used by default when the service is not available.
      Returns:
      this builder
    • timeout

      ServiceDependencyBuilder<S> timeout(long timeout)
      Sets a timeout for this dependency. A timed dependency blocks the invoker thread if the required dependency is currently unavailable, until it comes up again.
      Parameters:
      timeout - the timeout to wait in milliseconds when the service disappears. If the timeout expires, an IllegalStateException is thrown when the missing service is invoked.
      Returns:
      this builder
    • autoConfig

      Injects this dependency in all fields matching the dependency type.
      Returns:
      this builder
    • autoConfig

      ServiceDependencyBuilder<S> autoConfig(boolean autoConfig)
      Configures whether or not the dependency can be injected in all fields matching the dependency type.
      Parameters:
      autoConfig - true if the dependency can be injected in all fields matching the dependency type
      Returns:
      this builder
    • autoConfig

      ServiceDependencyBuilder<S> autoConfig(String field)
      Injects this dependency on the field with the given name
      Parameters:
      field - the field name where the dependency must be injected
      Returns:
      this builder