You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2018/10/09 13:34:37 UTC
svn commit: r1843267 -
/felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-singleton.mdtext
Author: pderop
Date: Tue Oct 9 13:34:37 2018
New Revision: 1843267
URL: http://svn.apache.org/viewvc?rev=1843267&view=rev
Log:
dm r12 updates
Modified:
felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-singleton.mdtext
Modified: felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-singleton.mdtext
URL: http://svn.apache.org/viewvc/felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-singleton.mdtext?rev=1843267&r1=1843266&r2=1843267&view=diff
==============================================================================
--- felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-singleton.mdtext (original)
+++ felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-singleton.mdtext Tue Oct 9 13:34:37 2018
@@ -2,9 +2,12 @@ Title: Dependency Manager - Singleton Co
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.
-## Example using API
+## Example usage
-To define a singleton component, you can use the DependencyManager.createComponent() method, like in the following example which defines a "TranslationService" osgi service having one required dependency on the "LocalizationService" and one optional dependency on a "LogService".
+To define a singleton component, you can use the DependencyActivatorBase.createComponent() or
+the DependencyManager.createComponent() method,
+like in the following example which defines a "TranslationService" osgi service having one required
+dependency on the "LocalizationService" and one optional dependency on a "LogService".
Dependencies are optional by default, unless you invoke the ServiceDependency.setRequired(boolean) method:
:::java
@@ -15,7 +18,7 @@ Dependencies are optional by default, un
...
}
- public class Activator extends DependencyManagerActivator {
+ public class Activator extends DependencyActivatorBase {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
Component c = createComponent()
.setInterface(TranslationService.class.getName(), null)
@@ -40,7 +43,7 @@ You can also inject dependencies using c
...
}
- public class Activator extends DependencyManagerActivator {
+ public class Activator extends DependencyActivatorBase {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
Component c = createComponent()
.setInterface(TranslationService.class.getName(), null)
@@ -58,35 +61,3 @@ You can also inject dependencies using c
Notice that when you define an optional dependency without using callbacks, then a "NullObject" method is injected in the class field (by reflection) when the actual optional service is not available. In this case any invocation on the optional service won't do anything.
-## Example using lambda API
-
-This is the same example using the Dependency Manager Lambda API:
-
- :::java
- public class Activator extends DependencyManagerActivator {
- public void init(BundleContext ctx, DependencyManager dm) throws Exception {
- component(comp -> comp
- .impl(GoogleBasedTranslationService.class)
- .provides(TranslationService.class)
- .withSvc(LocalizationService.class, true)
- .withSvc(LogService.class, false));
- }
- }
-
-## Example using annotations:
-
-This is the same example as before, using Annotations: (notice that unlike with the api, the dependencies are required by default):
-
- :::java
- @Component
- public class GoogleBasedTranslationService implements TranslationService {
- @ServiceDependency(required=true)
- volatile LocalizationService localizationService;
-
- @ServiceDependency(required=false)
- volatile LogService log;
-
- ...
- }
-
-