Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/DictionaryAspectConfiguration.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/DictionaryAspectConfiguration.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/DictionaryAspectConfiguration.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/DictionaryAspectConfiguration.java Tue Feb 9 21:44:38 2016 @@ -29,7 +29,7 @@ import aQute.bnd.annotation.metatype.Met * * @author <a href="mailto:[email protected]">Felix Project Team</a> */ -@OCD(name="Spell Checker Aspect Dictionary (annotation)", +@OCD(name="Spell Checker Aspect Dictionary", description = "Declare here the list of english words to be added into the default english dictionary") public interface DictionaryAspectConfiguration { @AD(description = "Dictionary aspect words")
Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/DictionaryConfiguration.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/DictionaryConfiguration.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/DictionaryConfiguration.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/DictionaryConfiguration.java Tue Feb 9 21:44:38 2016 @@ -29,7 +29,7 @@ import aQute.bnd.annotation.metatype.Met * * @author <a href="mailto:[email protected]">Felix Project Team</a> */ -@OCD(name="Spell Checker Dictionary (annotation)", +@OCD(name="Spell Checker Dictionary", factory = true, description = "Declare here some Dictionary instances, allowing to instantiates some DictionaryService services for a given dictionary language") public interface DictionaryConfiguration { Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/README URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/README?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/README (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/annot/README Tue Feb 9 21:44:38 2016 @@ -23,21 +23,21 @@ internally used by the SpellChecker comm A DictionaryService is defined using a FactoryConfigurationAdapterService , allowing to instantiate many "DictionaryService" instances when some configurations are added to the -"Spell Checker Dictionary (annotation)" factory pid from web console. +"Spell Checker Dictionary" factory pid from web console. The factory pid configuration metatypes are defined using the bnd "metatype" annotations (see DictionaryConfiguration.java). The DictionaryService is decorated with a DictionaryAspect, which you can instantiate by adding a -configuration to the "Spell Checker Aspect Dictionary (annotation)" factory pid from web console. The -aspect configuration metatype is also declared using the bnd metatype annotations (see -DictionaryAspectConfiguration.java). +configuration to the "Spell Checker Aspect Dictionary" factory pid from web console. The +aspect configuration metatype is also declared using the bnd metatype annotations (see DictionaryAspectConfiguration.java). -Before running this sample, go to webconsole (http://localhost:8080/system/console/configMgr), and add some words in the -"Spell Checker Dictionary (annotation)" section, and in the "Spell Checker Aspect Dictionary (annotation)" configurations. +Start the test: click on "dictionary.annot.bndrun" descriptor, and run it. +Then go to webconsole (http://localhost:8080/system/console/configMgr), and add some words in the +"Spell Checker Dictionary" section, and in the "Spell Checker Aspect Dictionary" configurations. Then go to gogo shell, and type dm help. You will normally see the dictionary.annotation:spellcheck command. -Type +Then type: - dictionary.annotation:spellcheck <some words that you have configured in webconsole> + spellcheck <some words that you have configured in webconsole> and the command will check for proper word existence. Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/DictionaryAspectConfiguration.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/DictionaryAspectConfiguration.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/DictionaryAspectConfiguration.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/DictionaryAspectConfiguration.java Tue Feb 9 21:44:38 2016 @@ -29,7 +29,7 @@ import aQute.bnd.annotation.metatype.Met * * @author <a href="mailto:[email protected]">Felix Project Team</a> */ -@OCD(name="Spell Checker Aspect Dictionary (api)", +@OCD(name="Spell Checker Aspect Dictionary", description = "Declare here the list of english words to be added into the default english dictionary") public interface DictionaryAspectConfiguration { @AD(description = "Dictionary aspect words") Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/DictionaryConfiguration.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/DictionaryConfiguration.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/DictionaryConfiguration.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/DictionaryConfiguration.java Tue Feb 9 21:44:38 2016 @@ -29,7 +29,7 @@ import aQute.bnd.annotation.metatype.Met * * @author <a href="mailto:[email protected]">Felix Project Team</a> */ -@OCD(name="Spell Checker Dictionary (api)", +@OCD(name="Spell Checker Dictionary", factory = true, description = "Declare here some Dictionary instances, allowing to instantiates some DictionaryService services for a given dictionary language") public interface DictionaryConfiguration { Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/README URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/README?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/README (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dictionary/api/README Tue Feb 9 21:44:38 2016 @@ -23,22 +23,23 @@ internally used by the SpellChecker comm A DictionaryService is defined using a FactoryConfigurationAdapterService , allowing to instantiate many "DictionaryService" instances when some configurations are added to the -"Spell Checker Configuration (api)" factory pid from web +"Spell Checker Configuration" factory pid from web console. The factory pid configuration metatypes are defined using the bnd "metatype" annotations (see DictionaryConfiguration.java). The DictionaryService is decorated with a DictionaryAspect, which you can instantiate by adding a -configuration to the "Spell Checker Aspect Dictionary (api)" pid from web console. The +configuration to the "Spell Checker Aspect Dictionary" pid from web console. The aspect configuration metatype is also declared using the bnd metatype annotations (see DictionaryAspectConfiguration.java). -Before running this sample, go to webconsole (http://localhost:8080/system/console/configMgr), and add some -words in the "Spell Checker Dictionary (api)" and in the "Spell Checker Aspect Dictionary (api)" configurations. +Start the test: click on "dictionary.api.bndrun" descriptor, and run it. +Then go to webconsole (http://localhost:8080/system/console/configMgr), and add some words in the +"Spell Checker Dictionary" section, and in the "Spell Checker Aspect Dictionary" configurations. -Then go to gogo shell, and type dm help. You will normally see the dictionary:spellcheck command. +Then go to gogo shell, and type dm help. You will normally see the dictionary.annotation:spellcheck command. Then type: + + spellcheck <some words that you have configured in webconsole> - dictionary:spellcheck <some words that you have configured in webconsole> - -and the command will check for proper word existence in the configuration. +and the command will check for proper word existence. Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/DynamicDependency.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/DynamicDependency.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/DynamicDependency.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/DynamicDependency.java Tue Feb 9 21:44:38 2016 @@ -60,11 +60,9 @@ public class DynamicDependency { /** * This is the first callback: we are injected with our configuration. */ - @ConfigurationDependency(pidClass=DynamicDependencyConfiguration.class) - public void updated(Dictionary<String, Object> properties) throws ConfigurationException { - // We use the bnd "Configurable" helper in order to get an implementation for our DictionaryConfiguration interface. - if (properties != null) { - DynamicDependencyConfiguration cnf = Configurable.createConfigurable(DynamicDependencyConfiguration.class, properties); + @ConfigurationDependency + public void updated(DynamicDependencyConfiguration cnf) throws ConfigurationException { + if (cnf != null) { storageType = cnf.storageType(); storageRequired = cnf.storageRequired(); } Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/DynamicDependencyConfiguration.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/DynamicDependencyConfiguration.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/DynamicDependencyConfiguration.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/DynamicDependencyConfiguration.java Tue Feb 9 21:44:38 2016 @@ -27,7 +27,7 @@ import aQute.bnd.annotation.metatype.Met * * @author <a href="mailto:[email protected]">Felix Project Team</a> */ -@OCD(name = "Dynamic Dependency Configuration (annotation)", +@OCD(name = "Dynamic Dependency Configuration", description = "Declare here the configuration for the DynamicDependency component.") public interface DynamicDependencyConfiguration { Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/README URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/README?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/README (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/annot/README Tue Feb 9 21:44:38 2016 @@ -16,21 +16,37 @@ */ This sample shows how to define a dynamic dependency using annotations. +Using annotation, you can still dynamically configure from your @Init method +some dependencies which has a "name" attribute. Such dependencies will then +be injected after your @Init method, but before your @Start method (if the dependencies +are required), or after your @Start method (if the dependencies are optional). When you declare a Component: - the configuration (if any) is first injected (updated callback). - then all required dependencies are injected, except "named" dependencies whose required flag and filter can be configured dynamically from the init method. -- then the init method (annotated with @Init) is invoked; And from there you are then able return a Map that will be used +- then the init method (annotated with @Init) is invoked; And from there you are then able to return a Map that will be used to configure the required flag and the filter of all named dependencies. - then the start callback (annotated with @Start) is invoked when all required dependencies are injected, including named dependencies that have been configured from the init method. In this sample, the "DynamicDependency" Components configures in its "init" method the dependency having a "storage" name. the dependency "required" flag and filter string are loaded from a Configuration PID -(see the "Dynamic Dependency Configuration (annotation)" PID, from webconsole), which is defined using +(see the "Dynamic Dependency Configuration" PID, from webconsole), which is defined using Bnd MetaType Annotations. -So, you have configure the "Dynamic Dependency Configuration (annotation)" PID from web console before playing with this sample; then -just type "log info|grep dynamicdep.annot" under the gogo shell. + + +So, first, click on the "dynamicdep.annot.bndrun" descriptor, and run it. +Then go to webconsole (http://localhost:8080/system/console/configMgr), and configure the "Dynamic Dependency Configuration" PID. +then just type "log warn" under the gogo shell: + +log warn + +Then you normally see something like: + +2016.02.08 21:49:26 WARNING - Bundle: org.apache.felix.dependencymanager.samples.dynamicdep.annot - MapDBStorage.store(gabu,zo) +2016.02.08 21:49:26 WARNING - Bundle: org.apache.felix.dependencymanager.samples.dynamicdep.annot - start +2016.02.08 21:49:26 WARNING - Bundle: org.apache.felix.dependencymanager.samples.dynamicdep.annot - init: storage type=mapdb, storageRequired=true + Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/api/DynamicDependencyConfiguration.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/api/DynamicDependencyConfiguration.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/api/DynamicDependencyConfiguration.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/api/DynamicDependencyConfiguration.java Tue Feb 9 21:44:38 2016 @@ -27,7 +27,7 @@ import aQute.bnd.annotation.metatype.Met * * @author <a href="mailto:[email protected]">Felix Project Team</a> */ -@OCD(name = "Dynamic Dependency Configuration (api)", +@OCD(name = "Dynamic Dependency Configuration", description = "Declare here the configuration for the DynamicDependency component.") public interface DynamicDependencyConfiguration { @AD(description = "Enter the storage type to use", Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/api/README URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/api/README?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/api/README (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/dynamicdep/api/README Tue Feb 9 21:44:38 2016 @@ -17,16 +17,27 @@ This sample shows how to define a dynamic dependency from a Component's init method. -When you declare a Component: +Let's recap the lifecycle of a DM component: - the configuration (if any) is first injected (updated callback). +- then optional dependencies on class fields are injected. - then all required dependencies are injected. - then the init(Component c) method is invoked; And from there you are then able to add dynamic dependencies using any previously injected services (either configuration injected in update method, or other injected services declared from the Activator). - then the start callback is invoked when all required dependencies declared from the init method are injected. -In this sample, the "DynamicDependency" Components defines in its "init" method a dynamic dependency on a Storage service. +In this sample, the "DynamicDependency" Component defines in its "init" method a dynamic dependency on a Storage service. But it first loads the "storage type" and "storage required" dependency informations from a Configuration PID -(see the "Dynamic Dependency Configuration (api)" PID from webconsole), which is defined using Bnd MetaType Annotations. -So, you have configure the "Dynamic Dependency Configuration (api)" PID from web console before playing with this sample; then -just type "log info|grep dynamicdep.api" under the gogo shell. +(see the "Dynamic Dependency Configuration" PID from webconsole), which is defined using Bnd MetaType Annotations. + +So, first, click on the "dynamicdep.api.bndrun" descriptor, and run it. +Then go to webconsole (http://localhost:8080/system/console/configMgr), and configure the "Dynamic Dependency Configuration" PID. +then just type "log warn" under the gogo shell: + +log warn + +Then you normally see something like: + +2016.02.08 21:54:16 WARNING - Bundle: org.apache.felix.dependencymanager.samples.dynamicdep.api - MapDBStorage.store(gabu,zo) +2016.02.08 21:54:16 WARNING - Bundle: org.apache.felix.dependencymanager.samples.dynamicdep.api - start +2016.02.08 21:54:16 WARNING - Bundle: org.apache.felix.dependencymanager.samples.dynamicdep.api - init: storage type=mapdb, storageRequired=true Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/README URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/README?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/README (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/README Tue Feb 9 21:44:38 2016 @@ -18,7 +18,13 @@ This sample provides an example with one service consumer and a service provider, both declared using DM Annotations. The ServiceConsumer is also depending on a configuration pid (see org.apache.felix.dependencymanager.samples.conf.Configurator). -To see logs, just type this under gogo shell: -g! log info|grep hello.annot +Click on "hello.annot.bndrun" descriptor and run it. Then just type: + +g! log warn + +and you should see: + +2016.02.08 21:57:47 WARNING - Bundle: org.apache.felix.dependencymanager.samples.hello.annot - ServiceProviderImpl.hello +2016.02.08 21:57:47 WARNING - Bundle: org.apache.felix.dependencymanager.samples.hello.annot - ServiceConsumer.start: calling service.hello() ... Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/ServiceConsumer.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/ServiceConsumer.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/ServiceConsumer.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/ServiceConsumer.java Tue Feb 9 21:44:38 2016 @@ -48,7 +48,7 @@ public class ServiceConsumer { @Start public void start() { - log.log(LogService.LOG_INFO, "ServiceConsumer.start: calling service.hello() ..."); + log.log(LogService.LOG_WARNING, "ServiceConsumer.start: calling service.hello() ..."); this.service.hello(); } } Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/ServiceProviderImpl.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/ServiceProviderImpl.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/ServiceProviderImpl.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/annot/ServiceProviderImpl.java Tue Feb 9 21:44:38 2016 @@ -34,6 +34,6 @@ public class ServiceProviderImpl impleme @Override public void hello() { - log.log(LogService.LOG_INFO, "ServiceProviderImpl.hello"); + log.log(LogService.LOG_WARNING, "ServiceProviderImpl.hello"); } } Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/README URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/README?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/README (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/README Tue Feb 9 21:44:38 2016 @@ -17,7 +17,13 @@ This sample provides a DM Activator declaring one service consumer and a service provider. The ServiceConsumer is also depending on a configuration pid (see org.apache.felix.dependencymanager.samples.conf.Configurator). -To see logs, just type this under gogo shell: -g! log info|grep hello.annot +Click on "hello.api.bndrun" descriptor and run it. Then just type: + +g! log warn + +and you should see: + +2016.02.08 21:59:31 WARNING - Bundle: org.apache.felix.dependencymanager.samples.hello.api - ServiceProviderImpl.hello +2016.02.08 21:59:31 WARNING - Bundle: org.apache.felix.dependencymanager.samples.hello.api - ServiceConsumer.start: calling service.hello() Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/ServiceConsumer.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/ServiceConsumer.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/ServiceConsumer.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/ServiceConsumer.java Tue Feb 9 21:44:38 2016 @@ -37,7 +37,7 @@ public class ServiceConsumer { } public void start() { - log.log(LogService.LOG_INFO, "ServiceConsumer.start: calling service.hello()"); + log.log(LogService.LOG_WARNING, "ServiceConsumer.start: calling service.hello()"); this.service.hello(); } } Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/ServiceProviderImpl.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/ServiceProviderImpl.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/ServiceProviderImpl.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/api/ServiceProviderImpl.java Tue Feb 9 21:44:38 2016 @@ -30,6 +30,6 @@ public class ServiceProviderImpl impleme @Override public void hello() { - log.log(LogService.LOG_INFO, "ServiceProviderImpl.hello"); + log.log(LogService.LOG_WARNING, "ServiceProviderImpl.hello"); } } Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java Tue Feb 9 21:44:38 2016 @@ -18,6 +18,9 @@ */ package org.apache.felix.dependencymanager.samples.tpool; +import java.util.Properties; + +import org.apache.felix.dependencymanager.samples.tpool.executor.ComponentExecutorFactoryImpl; import org.apache.felix.dm.ComponentExecutorFactory; import org.apache.felix.dm.DependencyActivatorBase; import org.apache.felix.dm.DependencyManager; @@ -32,7 +35,18 @@ public class Activator extends Dependenc @Override public void init(BundleContext context, DependencyManager mgr) throws Exception { mgr.add(createComponent() - .setInterface(ComponentExecutorFactory.class.getName(), null) - .setImplementation(ComponentExecutorFactoryImpl.class)); + .setInterface(ComponentExecutorFactory.class.getName(), null) + .setImplementation(ComponentExecutorFactoryImpl.class)); + + // Create two synchronous components + mgr.add(createComponent().setImplementation(new MyComponent("Component 1"))); + mgr.add(createComponent().setImplementation(new MyComponent("Component 2"))); + + // And two components which will be managed and started concurrently. + Properties properties = new Properties(); + properties.put("parallel", "true"); + + mgr.add(createComponent().setImplementation(new MyComponent("Parallel Component 3")).setServiceProperties(properties)); + mgr.add(createComponent().setImplementation(new MyComponent("Parallel Component 4")).setServiceProperties(properties)); } } Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/MyComponent.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/MyComponent.java?rev=1729464&view=auto ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/MyComponent.java (added) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/MyComponent.java Tue Feb 9 21:44:38 2016 @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.dependencymanager.samples.tpool; + +/** + * A first component that is not handled in parallel. + * @author <a href="mailto:[email protected]">Felix Project Team</a> + */ +public class MyComponent { + private final String m_name; + + MyComponent(String name) { + m_name = name; + } + + public void start() throws InterruptedException { + System.out.println("Starting Component " + m_name + " current thread=" + Thread.currentThread()); + } +} Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/README URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/README?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/README (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/README Tue Feb 9 21:44:38 2016 @@ -14,17 +14,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +The Activator you will find in this example registers a ComponentExecutorFactory in the OSGi service +registry to enable parallel activation of (some or all) components -The Activator you will find in this bundle registers a ComponentExecutorFactory in the OSGi service -registry to enable parallelism. DependencyManager core will use the Executor returned by the -ComponentExecutorFactory in order to handle components dependencies/lifecycle callbacks -concurrently. - -Important note: since we are using the DM API to declare our threadpool, we have to disable -parallelism for our "org.apache.felix.dependencymanager.samples.tpool.ThreadPool" component. -To do so, we define the following OSGi service property (see the bnd.bnd configuration file): +DM uses a whiteboard pattern approach in order to handle components concurrently: your application has to register a ComponentExecutorFactory in +the registry and DM will use it when deciding if components must be started concurrently (or not). By implementing yourself a ComponentExecutorFactory, +you are allowed to first decide if a given component should be started concurrently, and also choose the threadpool you like, +possibly a standard jdk threadpool, or some other advanced queuing libraries, like "hawtdispatch" ... --> +The ComponentExecutorFactory has a single method: -org.apache.felix.dependencymanager.parallelism=!org.apache.felix.dependencymanager.samples.tpool,* + /** + * Returns an Executor used to handle and start the given component, or null if the component must be started synchronously. + */ + public Executor getExecutorFor(Component component) { + } + +To indicate that DM should "wait for" a ComponentExecutorFactory before starting to handle any components, then you have to declare +in the bundle context properties the following parameter: + org.apache.felix.dependencymanager.parallelism=* + +Using the above property will ensure that DM cache any added DM components until ComponentExecutorFactory is available from the OSGi registry. +Hence, using the above property avoids you to use start level service in order to make sure all components are started concurrently, even if the +bundle containing your ComponentExecutorFactory service is started lastly. + +Finally, if you want to start all components in parallel, except some; then you can specify the list of packages to be excluded like this: + + org.apache.felix.dependencymanager.parallelism=!package.to.exclude,* + +Here, components having a package that is starting with "package.to.exclude" won't be started concurrently. + +Now, let's describe the example: it registers a ComponentExecutorFactory that only makes concurrent components +which provide a "parallel=true" service property (you can specify a service property even if the component does not register any services). +Since we define ComponentExecutorFactory using DM API, we also have to disable parallelism for it, by declaring its package in the following parameter from +the bundle context properties: + + org.apache.felix.dependencymanager.parallelism=!org.apache.felix.dependencymanager.samples.tpool.executor,* + +To start the example, click on "tpool.bndrun" descriptor and run it. +You will then see: + +Starting Component Component 1 current thread=Thread[main,5,main] +Starting Component Component 2 current thread=Thread[main,5,main] +Starting Component Parallel Component 3 current thread=Thread[pool-3-thread-1,5,main] +Starting Component Parallel Component 4 current thread=Thread[pool-3-thread-2,5,main] + +Here, the Component 3 and 4 are started in the threadpool, while the Component 2 is started synchronously from the main thread. \ No newline at end of file Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/executor/ComponentExecutorFactoryImpl.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/executor/ComponentExecutorFactoryImpl.java?rev=1729464&view=auto ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/executor/ComponentExecutorFactoryImpl.java (added) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/executor/ComponentExecutorFactoryImpl.java Tue Feb 9 21:44:38 2016 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.dependencymanager.samples.tpool.executor; + +import java.util.Dictionary; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +import org.apache.felix.dm.Component; +import org.apache.felix.dm.ComponentDeclaration; +import org.apache.felix.dm.ComponentExecutorFactory; + +/** + * @author <a href="mailto:[email protected]">Felix Project Team</a> + */ +public class ComponentExecutorFactoryImpl implements ComponentExecutorFactory { + final static Executor m_threadPool = Executors.newFixedThreadPool(4); + + /** + * Make concurrent a component only if it has a "parallel=true" property. + */ + @Override + public Executor getExecutorFor(Component component) { + ComponentDeclaration decl = component.getComponentDeclaration(); + Dictionary<String, Object> properties = decl.getServiceProperties(); + if (properties != null && "true".equals(properties.get("parallel"))) { + // the component will be handled in the threadpool. + return m_threadPool; + } else { + // the component won't be handled in parallel. + return null; + } + } +} Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/tpool.bnd URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/tpool.bnd?rev=1729464&r1=1729463&r2=1729464&view=diff ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/tpool.bnd (original) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/tpool.bnd Tue Feb 9 21:44:38 2016 @@ -14,8 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # -Private-Package: \ - org.apache.felix.dependencymanager.samples.tpool +Private-Package: \ + org.apache.felix.dependencymanager.samples.tpool,\ + org.apache.felix.dependencymanager.samples.tpool.executor Bundle-Activator: org.apache.felix.dependencymanager.samples.tpool.Activator Bundle-Description: Dependency Manager threadpool used by examples Bundle-Name: Dependency Manager Examples ThreadPool \ No newline at end of file Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/tpool.bndrun URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/tpool.bndrun?rev=1729464&view=auto ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/tpool.bndrun (added) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.samples/tpool.bndrun Tue Feb 9 21:44:38 2016 @@ -0,0 +1,44 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +-runfw: org.apache.felix.framework;version='[5.2.0,5.2.0]' +-runee: JavaSE-1.8 +-runsystemcapabilities: ${native_capability} + +-resolve.effective: active;skip:="osgi.service" + +-runbundles: \ + org.apache.felix.metatype;version=1.0.4,\ + org.apache.felix.log;version=1.0.1,\ + org.apache.felix.gogo.command;version=0.14.0,\ + org.apache.felix.gogo.runtime;version=0.12.0,\ + org.apache.felix.gogo.shell;version=0.10.0,\ + org.apache.felix.configadmin;version=1.8.6,\ + org.apache.felix.eventadmin;version=1.4.3,\ + biz.aQute.bndlib;version=2.3.0,\ + org.apache.felix.dependencymanager;version=latest,\ + org.apache.felix.dependencymanager.shell;version=latest,\ + org.apache.felix.dependencymanager.runtime;version=latest,\ + org.apache.felix.dependencymanager.samples.tpool;version=latest + +-runproperties: \ + org.apache.felix.dependencymanager.parallel='!org.apache.felix.dependencymanager.samples.tpool.executor, *',\ + org.apache.felix.dependencymanager.loglevel=2,\ + org.apache.felix.log.maxSize=100000,\ + org.apache.felix.log.storeDebug=true + + +
