THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Usage example of a Service whose dependency filter is configured from ConfigAdmin, using a "named" dependency
(please check Apache Felix Dependency Manager - Using Annotations - Lifecycle#Dynamic Dependency Configuration for more informations about "named" dependencies):
Code Block |
---|
/** * A Service whose service dependency "otherService" filter is configured from ConfigAdmin */ @Service class X { private Dictionary m_config; /** * Initialize our service from config ... and store the config for later usage (from our init method) */ @ConfigurationDependency(pid="MyPid") void configure(Dictionary conf) { m_config = config; } /** * All unnamed dependencies are injected: we can now configure other named * dependencies, using the already injected configuration. * The returned Map will be used to configure our "otherService" Dependency. */ @Init Map init() { return new HashMap() {{ put("otherService.filter", m_config.get("filter")); put("otherService.required", m_config.get("required")); }}; } /** * This named dependency filter/required flag will be configured by our init method (see above). */ @ServiceDependency(name="otherService") void bindOtherService(OtherService other) { } /** * All dependencies are injected and our service is now ready to be published. * Notice that you can also use the publisher service attribute if you need * to take control on service exposition. */ @Start void start() { } } |
...