B
- the type of a builder that may extends this builder interface (aspect/adapter).public interface ComponentBuilder<B extends ComponentBuilder<B>>
Components are the main building blocks for OSGi applications. They can publish themselves as a service, and they can have dependencies. These dependencies will influence their life cycle as component will only be activated when all required dependencies are available. This interface is also the base interface for extended components like aspects, adapters, etc ...
Example of a component that depends on a LogServce service. The dependency is injected by reflection on fields having a compatible type with the LogService interface:
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
component(comp -> comp.impl(Pojo.class).withSvc(LogService.class));
}
}
Modifier and Type | Method and Description |
---|---|
B |
autoAdd(boolean autoAdd)
Automatically adds this component to its DependencyManager object.
|
B |
autoConfig(java.lang.Class<?> clazz,
boolean autoConfig)
Configures OSGi object (BundleContext, Component, etc ...) that will be injected in any field having the same OSGi object type.
|
B |
autoConfig(java.lang.Class<?> clazz,
java.lang.String field)
Configures OSGi object (BundleContext, Component, etc ...) that will be injected in a given field.
|
Component |
build()
Builds the real DependencyManager Component.
|
B |
composition(java.lang.Object instance,
java.lang.String getCompositionMethod)
Sets the instance and method to invoke to get back all instances that
are part of a composition and need dependencies injected.
|
B |
composition(java.lang.String getCompositionMethod)
Sets the method to invoke on the service implementation to get back all
instances that are part of a composition and need dependencies injected.
|
B |
composition(java.util.function.Supplier<java.lang.Object[]> getCompositionMethod)
Sets a java8 method reference to a Supplier that returns all instances that are part of a composition and need dependencies injected.
|
B |
debug(java.lang.String label)
Activates debug mode
|
B |
destroy(InstanceCb callback)
Sets an Object instance method reference used as the "destroy" callback.
|
B |
destroy(InstanceCbComponent callback)
Sets an Object instance method reference used as the "destroy" callback.
|
B |
destroy(java.lang.Object callbackInstance,
java.lang.String callback)
Sets a callback instance and the name of the method used as the "destroy" callback.
|
B |
destroy(java.lang.String callback)
Sets the name of the method used as the "destroy" callback.
|
B |
factory(java.lang.Object factory,
java.lang.String createMethod)
Sets the factory to use when creating the implementation.
|
B |
factory(java.util.function.Supplier<?> create)
Configures a factory that can be used to create this component implementation.
|
B |
factory(java.util.function.Supplier<?> factory,
java.util.function.Supplier<java.lang.Object[]> getComposition)
Configures a factory used to create this component implementation using a Factory object and a "getComposition" factory method.
|
<U> B |
factory(java.util.function.Supplier<U> factory,
java.util.function.Function<U,?> create,
java.util.function.Function<U,java.lang.Object[]> getComposition)
Configures a factory that also returns a composition of objects for this component implemenation.
|
<U,V> B |
factory(java.util.function.Supplier<U> factory,
java.util.function.Function<U,V> create)
Configures a factory used to create this component implementation using a Factory object and a method in the Factory object.
|
B |
impl(java.lang.Object impl)
Configures the component implementation.
|
B |
init(InstanceCb callback)
Sets an Object instance method reference used as the "init" callback.
|
B |
init(InstanceCbComponent callback)
Sets an Object instance method reference used as the "init" callback.
|
B |
init(java.lang.Object callbackInstance,
java.lang.String callback)
Sets a callback instance and the name of the method used as the "init" callback.
|
B |
init(java.lang.String callback)
Sets the name of the method used as the "init" callback.
|
B |
listener(ComponentStateListener listener)
Adds a component state listener to this component.
|
B |
properties(java.util.Dictionary<?,?> properties)
Sets the component's service properties
|
B |
properties(FluentProperty... properties)
Deprecated.
Fluent properties are only supported using java8 and this method will be removed in next DM release
|
B |
properties(java.lang.String name,
java.lang.Object value,
java.lang.Object... rest)
Sets the components's service properties using varargs.
|
B |
provides(java.lang.Class<?> iface)
Sets the public interface under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.Class<?>[] ifaces)
Sets the public interfaces under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.Class<?>[] ifaces,
java.util.Dictionary<?,?> properties)
Sets the public interfaces under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.Class<?>[] ifaces,
FluentProperty... properties)
Deprecated.
Fluent properties are only supported using java8 and this method will be removed in next DM release
|
B |
provides(java.lang.Class<?>[] ifaces,
java.lang.String name,
java.lang.Object value,
java.lang.Object... rest)
Sets the public interfaces under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.Class<?> iface,
java.util.Dictionary<?,?> properties)
Sets the public interface under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.Class<?> iface,
FluentProperty... properties)
Deprecated.
Fluent properties are only supported using java8 and this method will be removed in next DM release
|
B |
provides(java.lang.Class<?> iface,
java.lang.String name,
java.lang.Object value,
java.lang.Object... rest)
Sets the public interface under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.String iface)
Sets the public interface under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.String[] ifaces)
Sets the public interfaces under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.String[] ifaces,
java.util.Dictionary<?,?> properties)
Sets the public interfaces under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.String[] ifaces,
FluentProperty... properties)
Deprecated.
Fluent properties are only supported using java8 and this method will be removed in next DM release
|
B |
provides(java.lang.String[] ifaces,
java.lang.String name,
java.lang.Object value,
java.lang.Object... rest)
Sets the public interfaces under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.String iface,
java.util.Dictionary<?,?> properties)
Sets the public interface under which this component should be registered in the OSGi service registry.
|
B |
provides(java.lang.String iface,
FluentProperty... properties)
Deprecated.
Fluent properties are only supported using java8 and this method will be removed in next DM release
|
B |
provides(java.lang.String iface,
java.lang.String name,
java.lang.Object value,
java.lang.Object... rest)
Sets the public interface under which this component should be registered in the OSGi service registry.
|
B |
scope(ServiceScope scope)
Configures the component scope.
|
B |
start(InstanceCb callback)
Sets an Object instance method reference used as the "start" callback.
|
B |
start(InstanceCbComponent callback)
Sets an Object instance method reference used as the "start" callback.
|
B |
start(java.lang.Object callbackInstance,
java.lang.String callback)
Sets the name of the method used as the "start" callback.
|
B |
start(java.lang.String callback)
Sets a callback instance and the name of the method used as the "start" callback.
|
B |
stop(InstanceCb callback)
Sets an Object instance method reference used as the "stop" callback.
|
B |
stop(InstanceCbComponent callback)
Sets an Object instance method reference used as the "stop" callback.
|
B |
stop(java.lang.Object callbackInstance,
java.lang.String callback)
Sets a callback instance and the name of the method used as the "stop" callback.
|
B |
stop(java.lang.String callback)
Sets the name of the method used as the "stop" callback.
|
B |
withBundle(java.util.function.Consumer<BundleDependencyBuilder> consumer)
Adds a bundle dependency.
|
default B |
withCnf(java.lang.Class<?> configType)
Adds a configuration dependency using a configuration type.
|
B |
withCnf(java.util.function.Consumer<ConfigurationDependencyBuilder> consumer)
Adds a configuration dependency.
|
default B |
withCnf(java.lang.String... pids)
Adds multiple configuration dependencies in one single call.
|
B |
withDep(Dependency dependency)
Adds a generic Dependency Manager dependency.
|
<U> B |
withFuture(java.util.concurrent.CompletableFuture<U> future,
java.util.function.Consumer<FutureDependencyBuilder<U>> consumer)
Adds a CompletableFuture dependency.
|
default B |
withSvc(boolean required,
java.lang.Class<?>... services)
Adds in one shot multiple service dependencies injected in compatible class fields.
|
default B |
withSvc(java.lang.Class<?>... services)
Adds in one shot multiple service dependencies injected in compatible class fields.
|
default B |
withSvc(java.lang.Class<?> service,
boolean required)
Adds a service dependency injected in compatible class fields.
|
default <T> B |
withSvc(java.lang.Class<T> service,
java.lang.String filter,
boolean required)
Adds a service dependency injected in compatible class fields.
|
default <T> B |
withSvc(java.lang.Class<T> service,
java.lang.String filter,
java.lang.String field,
boolean required)
Adds a service dependency injected in a given compatible class field.
|
<U> B |
withSvc(java.lang.Class<U> service,
java.util.function.Consumer<ServiceDependencyBuilder<U>> consumer)
Adds a service dependency built using a Consumer lambda that is provided with a ServiceDependencyBuilder.
|
B scope(ServiceScope scope)
B impl(java.lang.Object impl)
impl
- the component implementation (a class, or an Object).B factory(java.lang.Object factory, java.lang.String createMethod)
factory
- the factory instance, or the factory class.createMethod
- the create method called on the factory in order to instantiate the component.B factory(java.util.function.Supplier<?> create)
factory(ComponentImpl::new)", or "factory(() -> new ComponentImpl())
create
- the factory used to create the component implementation.<U,V> B factory(java.util.function.Supplier<U> factory, java.util.function.Function<U,V> create)
factory(Factory::new, Factory::create)
U
- the type of the factory returned by the supplierV
- the type of the object that is returned by the factory create method.factory
- the function used to create the Factory itselfcreate
- the method reference on the Factory method that is used to create the Component implementationB factory(java.util.function.Supplier<?> factory, java.util.function.Supplier<java.lang.Object[]> getComposition)
CompositionManager mngr = new CompositionManager();
...
factory(mngr::create, mngr::getComposition)
factory
- the supplier used to return the main component implementation instancegetComposition
- the supplier that returns the list of instances that are part of the component implementation classes.<U> B factory(java.util.function.Supplier<U> factory, java.util.function.Function<U,?> create, java.util.function.Function<U,java.lang.Object[]> getComposition)
factory(CompositionManager::new, CompositionManager::create, CompositionManager::getComposition).
Here, the CompositionManager will act as a factory (the create method will return the component implementation object), the
CompositionManager.getComposition() method will return all the objects that are also part of the component implementation,
and all of them will be searched for injecting any of the dependencies.U
- the type of the object returned by the supplier factoryfactory
- the function used to create the Factory itselfcreate
- the Factory method used to create the main component implementation objectgetComposition
- the Factory method used to return the list of objects that are also part of the component implementation.B provides(java.lang.Class<?> iface)
iface
- the public interface to register in the OSGI service registry.B provides(java.lang.Class<?> iface, java.lang.String name, java.lang.Object value, java.lang.Object... rest)
iface
- the public interface to register in the OSGI service registry.name
- a property name for the provided servicevalue
- a property value for the provided servicerest
- the rest of property name/value pairs.B provides(java.lang.Class<?> iface, FluentProperty... properties)
provides(MyService.class, property1 -> "value1", property2 -> 123);
iface
- the public interface to register in the OSGI service registry.properties
- a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
FluentProperty
interface that allows to define a property name using a lambda parameter.B provides(java.lang.Class<?> iface, java.util.Dictionary<?,?> properties)
iface
- the public interface to register in the OSGI service registry.properties
- the properties for the provided serviceB provides(java.lang.Class<?>[] ifaces)
ifaces
- list of services provided by the component.B provides(java.lang.Class<?>[] ifaces, java.lang.String name, java.lang.Object value, java.lang.Object... rest)
ifaces
- the public interfaces to register in the OSGI service registry.name
- a property name for the provided servicevalue
- a property value for the provided servicerest
- the rest of property name/value pairs.B provides(java.lang.Class<?>[] ifaces, FluentProperty... properties)
provides(new Class[] { MyService.class, MyService2.class }, property1 -> "value1", property2 -> 123);
ifaces
- the public interfaces to register in the OSGI service registry.properties
- a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
FluentProperty
interface that allows to define a property name using a lambda parameter.B provides(java.lang.Class<?>[] ifaces, java.util.Dictionary<?,?> properties)
ifaces
- the public interfaces to register in the OSGI service registry.properties
- the properties for the provided serviceB provides(java.lang.String iface)
iface
- the service provided by this component.B provides(java.lang.String iface, java.lang.String name, java.lang.Object value, java.lang.Object... rest)
iface
- the public interface to register in the OSGI service registry.name
- a property name for the provided servicevalue
- a property value for the provided servicerest
- the rest of property name/value pairs.B provides(java.lang.String iface, FluentProperty... properties)
provides(MyService.class, property1 -> "value1", property2 -> 123);
iface
- the public interface to register in the OSGI service registry.properties
- a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
FluentProperty
interface that allows to define a property name using a lambda parameter.B provides(java.lang.String iface, java.util.Dictionary<?,?> properties)
iface
- the public interface to register in the OSGI service registry.properties
- the properties for the provided serviceB provides(java.lang.String[] ifaces)
ifaces
- the list of services provided by the component.B provides(java.lang.String[] ifaces, java.lang.String name, java.lang.Object value, java.lang.Object... rest)
ifaces
- the public interfaces to register in the OSGI service registry.name
- a property name for the provided servicevalue
- a property value for the provided servicerest
- the rest of property name/value pairs.B provides(java.lang.String[] ifaces, FluentProperty... properties)
provides(new Class[] { MyService.class, MyService2.class }, property1 -> "value1", property2 -> 123);
ifaces
- the public interfaces to register in the OSGI service registry.properties
- a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
FluentProperty
interface that allows to define a property name using a lambda parameter.B provides(java.lang.String[] ifaces, java.util.Dictionary<?,?> properties)
ifaces
- the public interfaces to register in the OSGI service registry.properties
- the properties for the provided serviceB properties(java.util.Dictionary<?,?> properties)
properties
- the component's service propertiesB properties(java.lang.String name, java.lang.Object value, java.lang.Object... rest)
Example: properties("param1", "value1", "service.ranking", 3)
name
- the first property namevalue
- the first property valuerest
- the rest of properties key/value pairs.B properties(FluentProperty... properties)
properties(param1 -> "value1, param2 -> 2);
When you use this method, you must compile your source code using the "-parameters" option, and the "arg0" parameter
name is now allowed.properties
- the fluent properties<U> B withSvc(java.lang.Class<U> service, java.util.function.Consumer<ServiceDependencyBuilder<U>> consumer)
U
- the type of the dependency serviceservice
- the serviceconsumer
- the lambda used to build the service dependencydefault B withSvc(java.lang.Class<?>... services)
services
- some dependencies to inject in compatible class fields.default B withSvc(boolean required, java.lang.Class<?>... services)
required
- true if the dependency is required, false if notservices
- some dependencies to inject in compatible class fields.default B withSvc(java.lang.Class<?> service, boolean required)
service
- a service dependencyrequired
- true if the dependency is required, false if notdefault <T> B withSvc(java.lang.Class<T> service, java.lang.String filter, boolean required)
T
- the service dependency typeservice
- the service dependency.filter
- the service filterrequired
- true if the dependency is required, false if notdefault <T> B withSvc(java.lang.Class<T> service, java.lang.String filter, java.lang.String field, boolean required)
T
- the service dependency typeservice
- the service dependencyfilter
- the service filterfield
- the class field when the dependency has to be injectedrequired
- true if the dependency is required, false if notB withCnf(java.util.function.Consumer<ConfigurationDependencyBuilder> consumer)
consumer
- the lambda used to build the configuration dependency.default B withCnf(java.lang.String... pids)
pids
- list of configuration pids.default B withCnf(java.lang.Class<?> configType)
configType
- the configuration type that will be injected to the "updated" callbackConfigurationDependencyBuilder
B withBundle(java.util.function.Consumer<BundleDependencyBuilder> consumer)
consumer
- the lambda used to build the bundle dependency.<U> B withFuture(java.util.concurrent.CompletableFuture<U> future, java.util.function.Consumer<FutureDependencyBuilder<U>> consumer)
U
- the type of the result of the CompletableFuture.future
- a CompletableFuture on which the dependency will wait forconsumer
- the builder used to build the dependencyB withDep(Dependency dependency)
B init(java.lang.String callback)
The dependency manager will look for a method of this name with the following signatures, in this order:
callback
- the callback nameB init(java.lang.Object callbackInstance, java.lang.String callback)
The dependency manager will look for a method of this name with the following signatures, in this order:
callbackInstance
- a callback instance object the callback is invoked oncallback
- the callback nameB init(InstanceCb callback)
callback
- an Object instance method reference. The method does not take any parameters.B init(InstanceCbComponent callback)
callback
- an Object instance method reference. The method takes as argument a Component parameter.B start(java.lang.String callback)
The dependency manager will look for a method of this name with the following signatures, in this order:
callback
- the callback nameB start(java.lang.Object callbackInstance, java.lang.String callback)
The dependency manager will look for a method of this name with the following signatures, in this order:
callbackInstance
- a callback instance object the callback is invoked oncallback
- the callback nameB start(InstanceCb callback)
callback
- an Object instance method reference. The method does not take any parameters.B start(InstanceCbComponent callback)
callback
- an Object instance method reference. The method takes as argument a Component parameter.B stop(java.lang.String callback)
The dependency manager will look for a method of this name with the following signatures, in this order:
callback
- the callback nameB stop(java.lang.Object callbackInstance, java.lang.String callback)
The dependency manager will look for a method of this name with the following signatures, in this order:
callbackInstance
- a callback instance object the callback is invoked oncallback
- the callback nameB stop(InstanceCb callback)
callback
- an Object instance method reference. The method does not take any parameters.B stop(InstanceCbComponent callback)
callback
- an Object instance method reference. The method takes as argument a Component parameter.B destroy(java.lang.String callback)
The dependency manager will look for a method of this name with the following signatures, in this order:
callback
- the callback nameB destroy(java.lang.Object callbackInstance, java.lang.String callback)
The dependency manager will look for a method of this name with the following signatures, in this order:
callbackInstance
- a callback instance object the callback is invoked oncallback
- the callback nameB destroy(InstanceCb callback)
callback
- an Object instance method reference. The method does not take any parameters.B destroy(InstanceCbComponent callback)
callback
- an Object instance method reference. The method takes as argument a Component parameter.B autoConfig(java.lang.Class<?> clazz, boolean autoConfig)
clazz
- the OSGi object type (BundleContext, Component, DependencyManager).autoConfig
- true if the OSGi object has to be injected, false if notB autoConfig(java.lang.Class<?> clazz, java.lang.String field)
clazz
- the OSGi object type (BundleContext, Component, DependencyManager).field
- the field that will be injected with the OSGI objectB debug(java.lang.String label)
label
- the debug labelB autoAdd(boolean autoAdd)
autoAdd
- true for automatically adding this component to the DependencyManager object, false if notB composition(java.lang.String getCompositionMethod)
Object[]
.getCompositionMethod
- the method to invokeB composition(java.lang.Object instance, java.lang.String getCompositionMethod)
Object[]
.instance
- the instance that has the methodgetCompositionMethod
- the method to invokeB composition(java.util.function.Supplier<java.lang.Object[]> getCompositionMethod)
Object[]
.getCompositionMethod
- the method to invokeB listener(ComponentStateListener listener)
listener
- the state listenerComponent build()