S
- the type of the service dependencypublic interface ServiceDependencyBuilder<S> extends DependencyBuilder<ServiceDependency>, ServiceCallbacksBuilder<S,ServiceDependencyBuilder<S>>
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
}
}
Modifier and Type | Method and Description |
---|---|
ServiceDependencyBuilder<S> |
autoConfig()
Injects this dependency in all fields matching the dependency type.
|
ServiceDependencyBuilder<S> |
autoConfig(boolean autoConfig)
Configures whether or not the dependency can be injected in all fields matching the dependency type.
|
ServiceDependencyBuilder<S> |
autoConfig(java.lang.String field)
Injects this dependency on the field with the given name
|
ServiceDependencyBuilder<S> |
debug(java.lang.String label)
Configures debug mode
|
ServiceDependencyBuilder<S> |
defImpl(java.lang.Object defaultImpl)
Sets the default implementation if the service is not available.
|
ServiceDependencyBuilder<S> |
filter(java.lang.String filter)
Configures the service dependency filter
|
ServiceDependencyBuilder<S> |
optional()
Configures this dependency as optional.
|
ServiceDependencyBuilder<S> |
propagate()
Propagates the dependency properties to the component service properties.
|
ServiceDependencyBuilder<S> |
propagate(java.util.function.BiFunction<<any>,S,java.util.Dictionary<java.lang.String,java.lang.Object>> propagate)
Specifies a function that is called to get the propagated service properties for this service dependency.
|
ServiceDependencyBuilder<S> |
propagate(boolean propagate)
Configures whether the dependency properties must be propagated or not to the component service properties.
|
ServiceDependencyBuilder<S> |
propagate(java.util.function.Function<<any>,java.util.Dictionary<java.lang.String,java.lang.Object>> propagate)
Specifies a function that is called to get the propagated service properties for this service dependency.
|
ServiceDependencyBuilder<S> |
propagate(java.lang.Object instance,
java.lang.String method)
Configures a method that can is called in order to get propagated service properties.
|
ServiceDependencyBuilder<S> |
ref(<any> ref)
Configures this dependency with the given ServiceReference.
|
ServiceDependencyBuilder<S> |
required()
Configures this dependency as required.
|
ServiceDependencyBuilder<S> |
required(boolean required)
Configures whether this dependency is required or not.
|
ServiceDependencyBuilder<S> |
timeout(long timeout)
Sets a timeout for this dependency.
|
build
add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, callbackInstance, change, change, change, change, change, change, change, change, change, change, change, change, change, change, change, change, change, change, change, dereference, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, swap, swap, swap, swap, swap, swap, swap, swap, swap, swap, swap, swap, swap, swap, swap
ServiceDependencyBuilder<S> filter(java.lang.String filter)
filter
- the service filterServiceDependencyBuilder<S> ref(<any> ref)
ref
- the service referenceServiceDependencyBuilder<S> optional()
ServiceDependencyBuilder<S> required()
ServiceDependencyBuilder<S> required(boolean required)
required
- true if the dependency is required, false if not.ServiceDependencyBuilder<S> debug(java.lang.String label)
label
- the label used by debug messagesServiceDependencyBuilder<S> propagate()
ServiceDependencyBuilder<S> propagate(boolean propagate)
propagate
- true if the service dependency properties should be propagated to the properties provided by the component using this dependency.ServiceDependencyBuilder<S> propagate(java.lang.Object instance, java.lang.String method)
instance
- an object instancemethod
- the method name to call on the object instance. This method returns the propagated service properties.ServiceDependencyBuilder<S> propagate(java.util.function.Function<<any>,java.util.Dictionary<java.lang.String,java.lang.Object>> propagate)
propagate
- a function that is called to get the propagated service properties for this service dependency.ServiceDependencyBuilder<S> propagate(java.util.function.BiFunction<<any>,S,java.util.Dictionary<java.lang.String,java.lang.Object>> propagate)
propagate
- a function that is called to get the propagated service properties for this service dependency.ServiceDependencyBuilder<S> defImpl(java.lang.Object defaultImpl)
defaultImpl
- the implementation used by default when the service is not available.ServiceDependencyBuilder<S> timeout(long timeout)
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.ServiceDependencyBuilder<S> autoConfig()
ServiceDependencyBuilder<S> autoConfig(boolean autoConfig)
autoConfig
- true if the dependency can be injected in all fields matching the dependency typeServiceDependencyBuilder<S> autoConfig(java.lang.String field)
field
- the field name where the dependency must be injected