Package org.apache.felix.dm.lambda
Class DependencyManagerActivator
java.lang.Object
org.apache.felix.dm.lambda.DependencyManagerActivator
- All Implemented Interfaces:
org.osgi.framework.BundleActivator
public abstract class DependencyManagerActivator
extends Object
implements org.osgi.framework.BundleActivator
Defines a base for Activators in order to build DependencyManager Components using a java8 style.
Code example using auto configured fields:
import org.apache.felix.dm.lambda.DependencyManagerActivator;
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
component(comp -> comp
.provides(Service.class, property -> "value")
.impl(ServiceImpl.class)
.withSvc(LogService.class, ConfigurationAdmni.class) // both services are required and injected in class fields with compatible types.
}
}
Code example using reflection callbacks:
import org.apache.felix.dm.lambda.DependencyManagerActivator;
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
component(comp -> comp
.provides(Service.class, property -> "value")
.impl(ServiceImpl.class)
.withSvc(LogService.class, svc -> svc.add("setLog"))
.withSvc(ConfigurationAdmni.class, svc -> svc.add("setConfigAdmin")))
}
}
Code example using method references:
import org.apache.felix.dm.lambda.DependencyManagerActivator;
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
component(comp -> comp
.provides(Service.class, property -> "value")
.impl(ServiceImpl.class)
.withSvc(LogService.class, svc -> svc.add(ServiceImpl::setLog))
.withSvc(ConfigurationAdmni.class, svc -> svc.add(ServiceImpl::setConfigAdmin)))
}
}
When a dependency is not explicitly defined as "required" or "optional",
then it is assumed to be optional by default, like it is the case with the original DM API.
You can change the default mode using the "org.apache.felix.dependencymanager.lambda.defaultRequiredDependency system property"
(see Felix dm-lambda online documentation).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> ServiceAdapterBuilder<T> Creates a service Adapter builder that can be used to create a DM Adapter Component.protected <T> org.apache.felix.dm.Componentadapter(Class<T> adaptee, Consumer<ServiceAdapterBuilder<T>> consumer) Builds a DM Adapter Component using a Java8 style AdapterBuilder.static <T> ServiceAdapterBuilder<T> Creates a service Adapter builder that can be used to create an Adapter Component.static <T> org.apache.felix.dm.Componentadapter(org.apache.felix.dm.DependencyManager dm, Class<T> adaptee, Consumer<ServiceAdapterBuilder<T>> consumer) Builds an adapter DM Component.protected <T> ServiceAspectBuilder<T> Creates a service Aspect builder that can be used to create a DM Aspect Component.protected <T> org.apache.felix.dm.Componentaspect(Class<T> aspect, Consumer<ServiceAspectBuilder<T>> consumer) Builds a DM Aspect Component using a Java8 style AspectBuilder.static <T> ServiceAspectBuilder<T> Creates a service Aspect builder that can be used to create an Aspect Component.static <T> org.apache.felix.dm.Componentaspect(org.apache.felix.dm.DependencyManager dm, Class<T> aspect, Consumer<ServiceAspectBuilder<T>> consumer) Builds an aspect DM Component.protected org.apache.felix.dm.ComponentbundleAdapter(Consumer<BundleAdapterBuilder> consumer) Builds a DM Bundle Adapter Component.static BundleAdapterBuilderbundleAdapter(org.apache.felix.dm.DependencyManager dm) Creates a bundle adapter builder that can be used to create a DM bundle adapter Component.static org.apache.felix.dm.ComponentbundleAdapter(org.apache.felix.dm.DependencyManager dm, Consumer<BundleAdapterBuilder> consumer) Builds a bundle adapter DM Component.static BundleDependencyBuilderbundleDependency(org.apache.felix.dm.Component component) Creates a DM Bundle Dependency builder.protected ComponentBuilder<?> Creates a Component builder that can be used to create a DM Component.protected org.apache.felix.dm.Componentcomponent(Consumer<ComponentBuilder<?>> consumer) Builds a DM Component using a Java8 style ComponentBuilder.static voidcomponent(org.apache.felix.dm.Component comp, Consumer<ComponentBuilder<?>> consumer) Update an existing component.static ComponentBuilder<?> component(org.apache.felix.dm.DependencyManager dm) Creates a Component builder that can be used to create a Component.static org.apache.felix.dm.Componentcomponent(org.apache.felix.dm.DependencyManager dm, Consumer<ComponentBuilder<?>> consumer) Builds a component using a lambda and a component builderconfDependency(org.apache.felix.dm.Component component) Creates a DM Configuration Dependency builder.protected voiddestroy()Sub classes may override this method that is called when the Activator is stopped.protected org.apache.felix.dm.ComponentfactoryPidAdapter(Consumer<FactoryPidAdapterBuilder> consumer) Builds a DM Factory Configuration Adapter Component using a Java8 style FactoryPidAdapterBuilder.static FactoryPidAdapterBuilderfactoryPidAdapter(org.apache.felix.dm.DependencyManager dm) Creates a factory pid adapter that can be used to create a factory adapter Component.static org.apache.felix.dm.ComponentfactoryPidAdapter(org.apache.felix.dm.DependencyManager dm, Consumer<FactoryPidAdapterBuilder> consumer) Builds a DM factory configuration adapter.static <F> FutureDependencyBuilder<F> futureDependency(org.apache.felix.dm.Component component, CompletableFuture<F> future) Creates a DM CompletableFuture Dependency builder.org.osgi.framework.BundleContextgetBC()Returns the bundle context that is associated with this bundle.org.apache.felix.dm.DependencyManagergetDM()Returns the DependencyManager used to create/managed DM Components.protected abstract voidinit(org.osgi.framework.BundleContext ctx, org.apache.felix.dm.DependencyManager dm) Sub classes must override this method in order to build some DM components.static <T> ServiceDependencyBuilder<T> serviceDependency(org.apache.felix.dm.Component component, Class<T> service) Creates a DM ServiceDependency builder.voidstart(org.osgi.framework.BundleContext context) Our Activator is starting.voidstop(org.osgi.framework.BundleContext context) Our Activator is stopped.
-
Constructor Details
-
DependencyManagerActivator
public DependencyManagerActivator()
-
-
Method Details
-
start
Our Activator is starting.- Specified by:
startin interfaceorg.osgi.framework.BundleActivator- Throws:
Exception
-
stop
Our Activator is stopped.- Specified by:
stopin interfaceorg.osgi.framework.BundleActivator- Throws:
Exception
-
init
protected abstract void init(org.osgi.framework.BundleContext ctx, org.apache.felix.dm.DependencyManager dm) throws Exception Sub classes must override this method in order to build some DM components.- Parameters:
ctx- the context associated to the bundledm- the DependencyManager assocaited to this activator- Throws:
Exception- if the activation fails
-
destroy
Sub classes may override this method that is called when the Activator is stopped.- Throws:
Exception- if the deactivation fails
-
getDM
public org.apache.felix.dm.DependencyManager getDM()Returns the DependencyManager used to create/managed DM Components.- Returns:
- the DependencyManager associated to this Activator
-
getBC
public org.osgi.framework.BundleContext getBC()Returns the bundle context that is associated with this bundle.- Returns:
- the bundle context
-
component
Creates a Component builder that can be used to create a DM Component.- Returns:
- a Component builder that can be used to create a DM Component.
-
aspect
Creates a service Aspect builder that can be used to create a DM Aspect Component.- Type Parameters:
T- the aspect service type- Parameters:
aspectType- the aspect service- Returns:
- a service Aspect builder.
-
adapter
Creates a service Adapter builder that can be used to create a DM Adapter Component.- Type Parameters:
T- the adapted service type.- Parameters:
adaptee- the adapted service- Returns:
- a service Adapter builder.
-
component
Builds a DM Component using a Java8 style ComponentBuilder.- Parameters:
consumer- the lambda that will use the ComponentBuilder for building the DM component. The component is auto-added to the DependencyManager, unless the lambda calls the ComponentBuilder.autoAdd(false) method.- Returns:
- a newly built DM component.
-
aspect
protected <T> org.apache.felix.dm.Component aspect(Class<T> aspect, Consumer<ServiceAspectBuilder<T>> consumer) Builds a DM Aspect Component using a Java8 style AspectBuilder. The component is auto-added to the DependencyManager, unless the lambda calls the AspectBuilder.autoAdd(false) method.- Type Parameters:
T- the aspect service type- Parameters:
aspect- the aspect serviceconsumer- the lambda that will use the AspectBuilder for building the DM aspect component.- Returns:
- the DM component build by the consumer of the aspect builder
-
adapter
protected <T> org.apache.felix.dm.Component adapter(Class<T> adaptee, Consumer<ServiceAdapterBuilder<T>> consumer) Builds a DM Adapter Component using a Java8 style AdapterBuilder. The component is auto-added to the DependencyManager, unless the lambda calls the AdapterBuilder.autoAdd(false) method.- Type Parameters:
T- the adapted service type- Parameters:
adaptee- the adapted serviceconsumer- the lambda that will use the AdapterBuilder for building the DM adapter component.- Returns:
- a newly built DM component.
-
factoryPidAdapter
protected org.apache.felix.dm.Component factoryPidAdapter(Consumer<FactoryPidAdapterBuilder> consumer) Builds a DM Factory Configuration Adapter Component using a Java8 style FactoryPidAdapterBuilder. The component is auto-added to the DependencyManager, unless the lambda calls the FactoryPidAdapterBuilder.autoAdd(false) method.- Parameters:
consumer- the lambda that will use the FactoryPidAdapterBuilder for building the DM factory configuration adapter component.- Returns:
- a newly built DM component.
-
bundleAdapter
Builds a DM Bundle Adapter Component.- Parameters:
consumer- the lambda used to build the actual bundle adapter. The component is auto-added to the DependencyManager, unless the lambda calls the BundleAdapter.autoAdd(false) method.- Returns:
- a newly built DM component.
-
component
Creates a Component builder that can be used to create a Component.- Parameters:
dm- the DependencyManager object used to create the component builder- Returns:
- a Component builder that can be used to create a Component.
-
aspect
public static <T> ServiceAspectBuilder<T> aspect(org.apache.felix.dm.DependencyManager dm, Class<T> aspect) Creates a service Aspect builder that can be used to create an Aspect Component.- Type Parameters:
T- the aspect service type- Parameters:
dm- the DependencyManager object used to register the built componentaspect- the type of the aspect service- Returns:
- a service Aspect builder that can be used to create an Aspect Component.
-
adapter
public static <T> ServiceAdapterBuilder<T> adapter(org.apache.felix.dm.DependencyManager dm, Class<T> adaptee) Creates a service Adapter builder that can be used to create an Adapter Component.- Type Parameters:
T- the adapted service type- Parameters:
dm- the DependencyManager object used to register the built componentadaptee- the type of the adaptee service- Returns:
- a service Adapter builder that can be used to create an Adapter Component.
-
factoryPidAdapter
Creates a factory pid adapter that can be used to create a factory adapter Component.- Parameters:
dm- the DependencyManager object used to register the built component- Returns:
- a factory pid adapter that can be used to create a factory adapter Component.
-
bundleAdapter
Creates a bundle adapter builder that can be used to create a DM bundle adapter Component.- Parameters:
dm- the DependencyManager object used to create the bundle adapter builder.- Returns:
- a bundle adapter builder that can be used to create a DM bundle adapter Component.
-
serviceDependency
public static <T> ServiceDependencyBuilder<T> serviceDependency(org.apache.felix.dm.Component component, Class<T> service) Creates a DM ServiceDependency builder.- Type Parameters:
T- the service dependency type- Parameters:
component- the component on which you want to build a new service dependency using the returned builderservice- the service dependency type.- Returns:
- a DM ServiceDependency builder.
-
confDependency
public static ConfigurationDependencyBuilder confDependency(org.apache.felix.dm.Component component) Creates a DM Configuration Dependency builder.- Parameters:
component- the component on which you want to build a new configuration dependency using the returned builder- Returns:
- a DM Configuration Dependency builder.
-
bundleDependency
Creates a DM Bundle Dependency builder.- Parameters:
component- the component on which you want to build a new bundle dependency using the returned builder- Returns:
- a DM Configuration Dependency builder.
-
futureDependency
public static <F> FutureDependencyBuilder<F> futureDependency(org.apache.felix.dm.Component component, CompletableFuture<F> future) Creates a DM CompletableFuture Dependency builder.- Type Parameters:
F- the type of the CompletableFuture result.- Parameters:
component- the component on which you want to build a new completable future dependency using the returned builder.future- the future the dependency built using the returned builder will depend on.- Returns:
- a CompletableFuture dependency builder.
-
component
public static org.apache.felix.dm.Component component(org.apache.felix.dm.DependencyManager dm, Consumer<ComponentBuilder<?>> consumer) Builds a component using a lambda and a component builder- Parameters:
dm- the DependencyManager where the component is auto-added (unless the component.autoAdd(false) is called)consumer- a lambda that is called to build the component. When the lambda is called, it will be provided with a ComponentBuilder object that is used to build the actual DM component.- Returns:
- the built DM component.
-
component
public static void component(org.apache.felix.dm.Component comp, Consumer<ComponentBuilder<?>> consumer) Update an existing component. Typically, this method can be used from a Component.init method, where more dependencies has to be added.- Parameters:
comp- an existing DM componentconsumer- the lambda that will be used to update the component
-
aspect
public static <T> org.apache.felix.dm.Component aspect(org.apache.felix.dm.DependencyManager dm, Class<T> aspect, Consumer<ServiceAspectBuilder<T>> consumer) Builds an aspect DM Component.- Type Parameters:
T- the aspect service type- Parameters:
dm- the DependencyManager object used to register the built componentaspect- the type of the aspect serviceconsumer- a lambda used to build the DM aspect component- Returns:
- a new DM aspect component. The aspect component is auto-added into the dm object, unless the lambda calls the AspectBuilder.autoAdd(false) method.
-
adapter
public static <T> org.apache.felix.dm.Component adapter(org.apache.felix.dm.DependencyManager dm, Class<T> adaptee, Consumer<ServiceAdapterBuilder<T>> consumer) Builds an adapter DM Component.- Type Parameters:
T- the adapted service type- Parameters:
dm- the DependencyManager object used to register the built componentadaptee- the type of the adapted serviceconsumer- a lambda used to build the DM adapter component- Returns:
- a new DM adapter component. The adapter component is auto-added into the dm object, unless the lambda calls the AspectBuilder.autoAdd(false) method is called.
-
bundleAdapter
public static org.apache.felix.dm.Component bundleAdapter(org.apache.felix.dm.DependencyManager dm, Consumer<BundleAdapterBuilder> consumer) Builds a bundle adapter DM Component.- Parameters:
dm- the DependencyManager object used to register the built componentconsumer- a lambda used to build the bundle adapter component- Returns:
- a new bundle adapter component. The adapter component is auto-added into the dm object, unless the lambda calls the AspectBuilder.autoAdd(false) method is called.
-
factoryPidAdapter
public static org.apache.felix.dm.Component factoryPidAdapter(org.apache.felix.dm.DependencyManager dm, Consumer<FactoryPidAdapterBuilder> consumer) Builds a DM factory configuration adapter.- Parameters:
dm- the DependencyManager object used to create DM components.consumer- a lambda used to build the DM factory configuration adapter component- Returns:
- a new DM factory configuration adapter component. The adapter component is auto-added into the dm object, unless the lambda calls the FactoryPidAdapterBuilder.autoAdd(false) method is called
-