public abstract class DependencyManagerActivator
extends java.lang.Object
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 and Description |
---|
DependencyManagerActivator() |
Modifier and Type | Method and Description |
---|---|
protected <T> ServiceAdapterBuilder<T> |
adapter(java.lang.Class<T> adaptee)
Creates a service Adapter builder that can be used to create a DM Adapter Component.
|
protected <T> Component |
adapter(java.lang.Class<T> adaptee,
java.util.function.Consumer<ServiceAdapterBuilder<T>> consumer)
Builds a DM Adapter Component using a Java8 style AdapterBuilder.
|
static <T> ServiceAdapterBuilder<T> |
adapter(DependencyManager dm,
java.lang.Class<T> adaptee)
Creates a service Adapter builder that can be used to create an Adapter Component.
|
static <T> Component |
adapter(DependencyManager dm,
java.lang.Class<T> adaptee,
java.util.function.Consumer<ServiceAdapterBuilder<T>> consumer)
Builds an adapter DM Component.
|
protected <T> ServiceAspectBuilder<T> |
aspect(java.lang.Class<T> aspectType)
Creates a service Aspect builder that can be used to create a DM Aspect Component.
|
protected <T> Component |
aspect(java.lang.Class<T> aspect,
java.util.function.Consumer<ServiceAspectBuilder<T>> consumer)
Builds a DM Aspect Component using a Java8 style AspectBuilder.
|
static <T> ServiceAspectBuilder<T> |
aspect(DependencyManager dm,
java.lang.Class<T> aspect)
Creates a service Aspect builder that can be used to create an Aspect Component.
|
static <T> Component |
aspect(DependencyManager dm,
java.lang.Class<T> aspect,
java.util.function.Consumer<ServiceAspectBuilder<T>> consumer)
Builds an aspect DM Component.
|
protected Component |
bundleAdapter(java.util.function.Consumer<BundleAdapterBuilder> consumer)
Builds a DM Bundle Adapter Component.
|
static BundleAdapterBuilder |
bundleAdapter(DependencyManager dm)
Creates a bundle adapter builder that can be used to create a DM bundle adapter Component.
|
static Component |
bundleAdapter(DependencyManager dm,
java.util.function.Consumer<BundleAdapterBuilder> consumer)
Builds a bundle adapter DM Component.
|
static BundleDependencyBuilder |
bundleDependency(Component component)
Creates a DM Bundle Dependency builder.
|
protected ComponentBuilder<?> |
component()
Creates a Component builder that can be used to create a DM Component.
|
static void |
component(Component comp,
java.util.function.Consumer<ComponentBuilder<?>> consumer)
Update an existing component.
|
protected Component |
component(java.util.function.Consumer<ComponentBuilder<?>> consumer)
Builds a DM Component using a Java8 style ComponentBuilder.
|
static ComponentBuilder<?> |
component(DependencyManager dm)
Creates a Component builder that can be used to create a Component.
|
static Component |
component(DependencyManager dm,
java.util.function.Consumer<ComponentBuilder<?>> consumer)
Builds a component using a lambda and a component builder
|
static ConfigurationDependencyBuilder |
confDependency(Component component)
Creates a DM Configuration Dependency builder.
|
protected void |
destroy()
Sub classes may override this method that is called when the Activator is stopped.
|
protected Component |
factoryPidAdapter(java.util.function.Consumer<FactoryPidAdapterBuilder> consumer)
Builds a DM Factory Configuration Adapter Component using a Java8 style FactoryPidAdapterBuilder.
|
static FactoryPidAdapterBuilder |
factoryPidAdapter(DependencyManager dm)
Creates a factory pid adapter that can be used to create a factory adapter Component.
|
static Component |
factoryPidAdapter(DependencyManager dm,
java.util.function.Consumer<FactoryPidAdapterBuilder> consumer)
Builds a DM factory configuration adapter.
|
static <F> FutureDependencyBuilder<F> |
futureDependency(Component component,
java.util.concurrent.CompletableFuture<F> future)
Creates a DM CompletableFuture Dependency builder.
|
BundleContext |
getBC()
Returns the bundle context that is associated with this bundle.
|
DependencyManager |
getDM()
Returns the DependencyManager used to create/managed DM Components.
|
protected abstract void |
init(BundleContext ctx,
DependencyManager dm)
Sub classes must override this method in order to build some DM components.
|
static <T> ServiceDependencyBuilder<T> |
serviceDependency(Component component,
java.lang.Class<T> service)
Creates a DM ServiceDependency builder.
|
void |
start(BundleContext context)
Our Activator is starting.
|
void |
stop(BundleContext context)
Our Activator is stopped.
|
public void start(BundleContext context) throws java.lang.Exception
java.lang.Exception
public void stop(BundleContext context) throws java.lang.Exception
java.lang.Exception
protected abstract void init(BundleContext ctx, DependencyManager dm) throws java.lang.Exception
ctx
- the context associated to the bundledm
- the DependencyManager assocaited to this activatorjava.lang.Exception
- if the activation failsprotected void destroy() throws java.lang.Exception
java.lang.Exception
- if the deactivation failspublic DependencyManager getDM()
public BundleContext getBC()
protected ComponentBuilder<?> component()
protected <T> ServiceAspectBuilder<T> aspect(java.lang.Class<T> aspectType)
T
- the aspect service typeaspectType
- the aspect serviceprotected <T> ServiceAdapterBuilder<T> adapter(java.lang.Class<T> adaptee)
T
- the adapted service type.adaptee
- the adapted serviceprotected Component component(java.util.function.Consumer<ComponentBuilder<?>> consumer)
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.protected <T> Component aspect(java.lang.Class<T> aspect, java.util.function.Consumer<ServiceAspectBuilder<T>> consumer)
T
- the aspect service typeaspect
- the aspect serviceconsumer
- the lambda that will use the AspectBuilder for building the DM aspect component.protected <T> Component adapter(java.lang.Class<T> adaptee, java.util.function.Consumer<ServiceAdapterBuilder<T>> consumer)
T
- the adapted service typeadaptee
- the adapted serviceconsumer
- the lambda that will use the AdapterBuilder for building the DM adapter component.protected Component factoryPidAdapter(java.util.function.Consumer<FactoryPidAdapterBuilder> consumer)
consumer
- the lambda that will use the FactoryPidAdapterBuilder for building the DM factory configuration adapter component.protected Component bundleAdapter(java.util.function.Consumer<BundleAdapterBuilder> consumer)
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.public static ComponentBuilder<?> component(DependencyManager dm)
dm
- the DependencyManager object used to create the component builderpublic static <T> ServiceAspectBuilder<T> aspect(DependencyManager dm, java.lang.Class<T> aspect)
T
- the aspect service typedm
- the DependencyManager object used to register the built componentaspect
- the type of the aspect servicepublic static <T> ServiceAdapterBuilder<T> adapter(DependencyManager dm, java.lang.Class<T> adaptee)
T
- the adapted service typedm
- the DependencyManager object used to register the built componentadaptee
- the type of the adaptee servicepublic static FactoryPidAdapterBuilder factoryPidAdapter(DependencyManager dm)
dm
- the DependencyManager object used to register the built componentpublic static BundleAdapterBuilder bundleAdapter(DependencyManager dm)
dm
- the DependencyManager object used to create the bundle adapter builder.public static <T> ServiceDependencyBuilder<T> serviceDependency(Component component, java.lang.Class<T> service)
T
- the service dependency typecomponent
- the component on which you want to build a new service dependency using the returned builderservice
- the service dependency type.public static ConfigurationDependencyBuilder confDependency(Component component)
component
- the component on which you want to build a new configuration dependency using the returned builderpublic static BundleDependencyBuilder bundleDependency(Component component)
component
- the component on which you want to build a new bundle dependency using the returned builderpublic static <F> FutureDependencyBuilder<F> futureDependency(Component component, java.util.concurrent.CompletableFuture<F> future)
F
- the type of the CompletableFuture result.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.public static Component component(DependencyManager dm, java.util.function.Consumer<ComponentBuilder<?>> consumer)
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.public static void component(Component comp, java.util.function.Consumer<ComponentBuilder<?>> consumer)
comp
- an existing DM componentconsumer
- the lambda that will be used to update the componentpublic static <T> Component aspect(DependencyManager dm, java.lang.Class<T> aspect, java.util.function.Consumer<ServiceAspectBuilder<T>> consumer)
T
- the aspect service typedm
- the DependencyManager object used to register the built componentaspect
- the type of the aspect serviceconsumer
- a lambda used to build the DM aspect componentpublic static <T> Component adapter(DependencyManager dm, java.lang.Class<T> adaptee, java.util.function.Consumer<ServiceAdapterBuilder<T>> consumer)
T
- the adapted service typedm
- the DependencyManager object used to register the built componentadaptee
- the type of the adapted serviceconsumer
- a lambda used to build the DM adapter componentpublic static Component bundleAdapter(DependencyManager dm, java.util.function.Consumer<BundleAdapterBuilder> consumer)
dm
- the DependencyManager object used to register the built componentconsumer
- a lambda used to build the bundle adapter componentpublic static Component factoryPidAdapter(DependencyManager dm, java.util.function.Consumer<FactoryPidAdapterBuilder> consumer)
dm
- the DependencyManager object used to create DM components.consumer
- a lambda used to build the DM factory configuration adapter component