Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame^] | 1 | package org.apache.felix.dm.lambda; |
| 2 | |
| 3 | import org.apache.felix.dm.ConfigurationDependency; |
| 4 | import org.apache.felix.dm.lambda.callbacks.CbComponentDictionary; |
| 5 | import org.apache.felix.dm.lambda.callbacks.CbDictionary; |
| 6 | import org.apache.felix.dm.lambda.callbacks.CbTypeComponentDictionary; |
| 7 | import org.apache.felix.dm.lambda.callbacks.CbTypeDictionary; |
| 8 | |
| 9 | /** |
| 10 | * Builds a Dependency Manager Configuration Dependency. |
| 11 | * By default, the updated callback is "updated", like in original DM API. |
| 12 | * |
| 13 | * <p> Code example with a component that defines a Configuration Dependency. the ServiceImpl modified method |
| 14 | * callback is declared using a method reference (see the "cb(ServiceImpl::modified)" code): |
| 15 | * |
| 16 | * <pre> {@code |
| 17 | * public class Activator extends DependencyManagerActivator { |
| 18 | * public void activate() throws Exception { |
| 19 | * component(comp -> comp |
| 20 | * .impl(ServiceImpl.class) |
| 21 | * .withConf(conf -> conf.pid(ServiceConsumer.class).cb(ServiceImpl::modified))); |
| 22 | * } |
| 23 | * } |
| 24 | * }</pre> |
| 25 | * |
| 26 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 27 | */ |
| 28 | public interface ConfigurationDependencyBuilder extends DependencyBuilder<ConfigurationDependency> { |
| 29 | /** |
| 30 | * Sets the pid for this configuration dependency. |
| 31 | * |
| 32 | * @param pid the configuration dependendency pid. |
| 33 | * @return this builder |
| 34 | */ |
| 35 | ConfigurationDependencyBuilder pid(String pid); |
| 36 | |
| 37 | /** |
| 38 | * Sets the class which fqdn represents the pid for this configuration dependency. Usually, this class can optionally be annotated with metatypes bnd annotations. |
| 39 | * |
| 40 | * @param pidClass the class which fqdn represents the pid for this configuration dependency. |
| 41 | * @return this builder |
| 42 | */ |
| 43 | ConfigurationDependencyBuilder pid(Class<?> pidClass); |
| 44 | |
| 45 | /** |
| 46 | * Sets propagation of the configuration properties to the service properties (false by default). |
| 47 | * All public configuration properties (not starting with a dot) will be propagated to the component service properties. |
| 48 | * |
| 49 | * @return this builder |
| 50 | */ |
| 51 | ConfigurationDependencyBuilder propagate(); |
| 52 | |
| 53 | /** |
| 54 | * Sets propagation of the configuration properties to the service properties (false by default). |
| 55 | * |
| 56 | * @param propagate true if all public configuration properties (not starting with a dot) must be propagated to the component service properties (false by default) |
| 57 | * @return this builder |
| 58 | */ |
| 59 | ConfigurationDependencyBuilder propagate(boolean propagate); |
| 60 | |
| 61 | /** |
| 62 | * Configures whether or not the component instance should be instantiated at the time the updated callback is invoked. |
| 63 | * By default, when the callback is applied on an external object instance, the component is not instantiated, but in this case |
| 64 | * you can force the creation of the component instances by calling this method. |
| 65 | * |
| 66 | * @param needsInstance true if the component instance should be instantiated at the time the updated callback is invoked on an external object instance. |
| 67 | * @return this builder |
| 68 | */ |
| 69 | ConfigurationDependencyBuilder needsInstance(boolean needsInstance); |
| 70 | |
| 71 | /** |
| 72 | * Sets a <code>callback</code> to call on the component instance(s) when the configuration is updated. |
| 73 | * |
| 74 | * @param updateMethod the callback to call on the component instance(s) when the configuration is updated. |
| 75 | * @return this builder |
| 76 | */ |
| 77 | ConfigurationDependencyBuilder cb(String updateMethod); |
| 78 | |
| 79 | /** |
| 80 | * Sets a <code>callback instance</code> to call on a given object instance when the configuration is updated. |
| 81 | * When the updated method is invoked, the Component implementation has not yet been instantiated, unless you have called |
| 82 | * the @link {@link #needsInstance(boolean)} method with "true". |
| 83 | * |
| 84 | * @param callbackInstance the object instance on which the updatedMethod is invoked |
| 85 | * @param updateMethod the callback to call on the callbackInstance when the configuration is updated. |
| 86 | * @return this builder |
| 87 | */ |
| 88 | ConfigurationDependencyBuilder cbi(Object callbackInstance, String updateMethod); |
| 89 | |
| 90 | /** |
| 91 | * Sets a <code>callback</code> method reference used to invoke an update method. The method reference must point to a method from one of the component |
| 92 | * implementation classes, and is invoked when the configuration is updated. |
| 93 | * |
| 94 | * @param <T> the type of the component implementation class on which the callback is invoked on. |
| 95 | * @param callback the callback method reference which must point to a method from one of the component implementation classes. The method |
| 96 | * takes as argument a Dictionary. |
| 97 | * @return this builder |
| 98 | */ |
| 99 | <T> ConfigurationDependencyBuilder cb(CbTypeDictionary<T> callback); |
| 100 | |
| 101 | /** |
| 102 | * Sets the <code>callback</code> method reference used to invoke an update method. The method reference must point to a method from one of the |
| 103 | * component implementation classes, and is invoked when the configuration is updated. |
| 104 | * |
| 105 | * @param <T> the type of the component implementation class on which the callback is invoked on. |
| 106 | * @param callback the callback method reference used to invoke an update method on the component instance(s) when the configuration is updated. |
| 107 | * The method takes as argument a Component and a Dictionary. |
| 108 | * @return this builder |
| 109 | */ |
| 110 | <T> ConfigurationDependencyBuilder cb(CbTypeComponentDictionary<T> callback); |
| 111 | |
| 112 | /** |
| 113 | * Sets a <code>callback instance</code> method reference used to invoke the update method. The method reference must point to an Object instance |
| 114 | * method which takes as argument a Dictionary. |
| 115 | * |
| 116 | * @param updated a method reference that points to an Object instance method which takes as argument a Dictionary. |
| 117 | * @return this builder |
| 118 | */ |
| 119 | ConfigurationDependencyBuilder cbi(CbDictionary updated); |
| 120 | |
| 121 | /** |
| 122 | * Sets a <code>callback instance</code> method reference used to invoke the update method. The method reference must point to an Object instance method |
| 123 | * which takes as argument a Component and a Dictionary. |
| 124 | * |
| 125 | * @param updated a method reference that points to an Object instance method which takes as argument a Component and a Dictionary. |
| 126 | * @return this builder |
| 127 | */ |
| 128 | ConfigurationDependencyBuilder cbi(CbComponentDictionary updated); |
| 129 | } |