blob: 7d87a129450b26fbd00fe68853c32b48c78d80b1 [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001package org.apache.felix.dm.lambda;
2
3import java.util.Dictionary;
Pierre De Rop11527502016-02-18 21:07:16 +00004import java.util.function.Function;
Pierre De Ropfaca2892016-01-31 23:27:05 +00005
6import org.apache.felix.dm.BundleDependency;
7import org.apache.felix.dm.lambda.callbacks.CbBundle;
Pierre De Rop11527502016-02-18 21:07:16 +00008import org.apache.felix.dm.lambda.callbacks.CbBundleComponent;
9import org.apache.felix.dm.lambda.callbacks.InstanceCbBundle;
10import org.apache.felix.dm.lambda.callbacks.InstanceCbBundleComponent;
Pierre De Ropfaca2892016-01-31 23:27:05 +000011import org.osgi.framework.Bundle;
12
13/**
Pierre De Rop11527502016-02-18 21:07:16 +000014 * Builds a Dependency Manager Bundle Dependency.
15 * The Dependency is required by default, but you can
16 * control the default mode (required or optional) using the "org.apache.felix.dependencymanager.lambda.dependencymode"
17 * system property which can be set to either "required" or "optional" ("required" by default).
Pierre De Ropfaca2892016-01-31 23:27:05 +000018 *
Pierre De Rop11527502016-02-18 21:07:16 +000019 * <p> Example of a Pojo Component which tracks a started bundle having a given bundle symbolic name:
Pierre De Ropfaca2892016-01-31 23:27:05 +000020 *
21 * <pre> {@code
22 * public class Activator extends DependencyManagerActivator {
Pierre De Rop11527502016-02-18 21:07:16 +000023 * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
Pierre De Ropfaca2892016-01-31 23:27:05 +000024 * String BSN = "org.apache.felix.dependencymanager";
25 * component(comp -> comp
Pierre De Rop11527502016-02-18 21:07:16 +000026 * .impl(Pojo.class)
27 * .withBundle(b -> b.mask(Bundle.ACTIVE).filter("(Bundle-SymbolicName=" + BSN + ")").add(Pojo::add).remove(Pojo::remove)));
Pierre De Ropfaca2892016-01-31 23:27:05 +000028 *
29 * }
30 * }
31 * } </pre>
32 *
33 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
34 */
35public interface BundleDependencyBuilder extends DependencyBuilder<BundleDependency> {
36 /**
Pierre De Rop11527502016-02-18 21:07:16 +000037 * Enables auto configuration for this dependency. This means the component implementation class fields will be
Pierre De Ropfaca2892016-01-31 23:27:05 +000038 * injected with this bundle dependency automatically.
39 *
40 * @param autoConfig <code>true</code> to enable auto configuration
41 * @return the bundle dependency builder
42 */
43 public BundleDependencyBuilder autoConfig(boolean autoConfig);
44
45 /**
Pierre De Rop11527502016-02-18 21:07:16 +000046 * Enables auto configuration for this dependency. This means the component implementation class fields will be
Pierre De Ropfaca2892016-01-31 23:27:05 +000047 * injected with this bundle dependency automatically.
48 *
49 * @return the bundle dependency builder
50 */
51 public BundleDependencyBuilder autoConfig();
52
53 /**
Pierre De Rop11527502016-02-18 21:07:16 +000054 * Sets the dependency to be required. By default, the dependency is required, but you can specify the default mode
55 * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
Pierre De Ropfaca2892016-01-31 23:27:05 +000056 *
57 * @param required <code>true</code> if this bundle dependency is required (true by default).
58 * @return the bundle dependency builder
59 */
60 public BundleDependencyBuilder required(boolean required);
61
62 /**
Pierre De Rop11527502016-02-18 21:07:16 +000063 * Sets the dependency to be required. By default, the dependency is required, but you can specify the default mode
64 * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
Pierre De Ropfaca2892016-01-31 23:27:05 +000065 *
66 * @return the bundle dependency builder
67 */
68 public BundleDependencyBuilder required();
69
70 /**
71 * Sets the bundle to depend on directly.
72 *
73 * @param bundle the bundle to depend on
74 * @return the bundle dependency builder
75 */
76 public BundleDependencyBuilder bundle(Bundle bundle);
77
78 /**
79 * Sets the filter condition to depend on. Filters are matched against the full manifest of a bundle.
80 *
81 * @param filter the filter condition
82 * @return the bundle dependency builder
83 */
84 public BundleDependencyBuilder filter(String filter);
85
86 /**
87 * Sets the bundle state mask to depend on. The OSGi BundleTracker explains this mask in more detail, but
88 * it is basically a mask with flags for each potential state a bundle can be in.
89 *
90 * @param mask the mask to use
91 * @return the bundle dependency builder
92 */
93 public BundleDependencyBuilder mask(int mask);
94
95 /**
96 * Sets property propagation. If set to <code>true</code> any bundle manifest properties will be added
97 * to the service properties of the component that has this dependency (if it registers as a service).
98 *
99 * @param propagate <code>true</code> to propagate the bundle manifest properties
100 * @return the bundle dependency builder
101 */
102 public BundleDependencyBuilder propagate(boolean propagate);
103
104 /**
105 * Sets property propagation. any bundle manifest properties will be added
106 * to the service properties of the component that has this dependency (if it registers as a service).
107 *
108 * @return the bundle dependency builder
109 */
110 public BundleDependencyBuilder propagate();
111
112 /**
113 * Sets an Object instance and a callback method used to propagate some properties to the provided service properties.
114 * The method will be invoked on the specified object instance and must have one of the following signatures:
Pierre De Rop11527502016-02-18 21:07:16 +0000115 *
116 * <p><ul><li>Dictionary callback(Bundle bundle)</ul>
117 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000118 * @param instance the Object instance which is used to retrieve propagated service properties
119 * @param method the method to invoke for retrieving the properties to be propagated to the service properties.
120 * @return this service dependency. builder
121 */
122 public BundleDependencyBuilder propagate(Object instance, String method);
123
124 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000125 * Sets a reference to a method on an Object instance used to propagate some bundle properties to the provided service properties.
126 *
127 * @param propagate a function which accepts a Bundle argument and which returns some properties that will be
128 * propagated to the provided component service properties.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000129 * @return this service dependency. builder
130 */
Pierre De Rop11527502016-02-18 21:07:16 +0000131 public BundleDependencyBuilder propagate(Function<Bundle, Dictionary<?, ?>> propagate);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000132
133 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000134 * Sets a "add" <code>callback</code> method to invoke on the component implementation instance(s).
135 * The callback is invoked when the bundle is added, and the following signatures are supported:
Pierre De Ropfaca2892016-01-31 23:27:05 +0000136 *
Pierre De Rop11527502016-02-18 21:07:16 +0000137 * <p><ol>
138 * <li>method(Bundle)</li>
139 * <li>method(Component, Bundle)</li>
140 * </ol>
141 *
142 * @param callback the add callback
Pierre De Ropfaca2892016-01-31 23:27:05 +0000143 * @return this builder
144 */
Pierre De Rop11527502016-02-18 21:07:16 +0000145 BundleDependencyBuilder add(String callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000146
147 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000148 * Sets a "change" <code>callback</code> method to invoke on the component implementation instance(s).
149 * The callback is invoked when the bundle state has changed, and the following signatures are supported:
Pierre De Ropfaca2892016-01-31 23:27:05 +0000150 *
Pierre De Rop11527502016-02-18 21:07:16 +0000151 * <p><ol>
152 * <li>method(Bundle)</li>
153 * <li>method(Component, Bundle)</li>
154 * </ol>
155 *
156 * @param callback the change callback
Pierre De Ropfaca2892016-01-31 23:27:05 +0000157 * @return this builder
158 */
Pierre De Rop11527502016-02-18 21:07:16 +0000159 BundleDependencyBuilder change(String callback);
160
161 /**
162 * Sets a "remove" <code>callback</code> method to invoke on the component implementation instance(s).
163 * The callback is invoked when the bundle is removed, and the following signatures are supported:
164 * <p><ol>
165 * <li>method(Bundle)</li>
166 * <li>method(Component, Bundle)</li>
167 * </ol>
168 *
169 * @param callback the remove callback
170 * @return this builder
171 */
172 BundleDependencyBuilder remove(String callback);
173
174 /**
175 * Specifies a callback instance used to invoke the reflection based callbacks on it.
176 * @param callbackInstance the instance to invoke the callbacks on
177 * @return this builder
178 * @see #add(String)
179 * @see #change(String)
180 * @see #remove(String)
181 */
182 BundleDependencyBuilder callbackInstance(Object callbackInstance);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000183
184 /**
185 * Sets a <code>callback</code> method reference which is invoked when a bundle is added.
Pierre De Rop11527502016-02-18 21:07:16 +0000186 * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000187 *
188 * @param <T> the type of the component implementation class on which the callback is invoked on.
189 * @param add the method reference invoked when a bundle is added.
190 * @return this builder
191 */
Pierre De Rop11527502016-02-18 21:07:16 +0000192 <T> BundleDependencyBuilder add(CbBundle<T> add);
193
Pierre De Ropfaca2892016-01-31 23:27:05 +0000194 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000195 * Sets a <code>callback</code> method reference which is invoked when a bundle is changed.
196 * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000197 *
198 * @param <T> the type of the component implementation class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000199 * @param change the method reference invoked when a bundle has changed.
Pierre De Rop11527502016-02-18 21:07:16 +0000200 * @return this builder
201 */
202 <T> BundleDependencyBuilder change(CbBundle<T> change);
203
204 /**
205 * Sets a <code>callback</code> method reference which is invoked when a bundle is removed.
206 * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
207 *
208 * @param <T> the type of the component implementation class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000209 * @param remove the method reference invoked when a bundle is removed.
210 * @return this builder
211 */
Pierre De Rop11527502016-02-18 21:07:16 +0000212 <T> BundleDependencyBuilder remove(CbBundle<T> remove);
213
Pierre De Ropfaca2892016-01-31 23:27:05 +0000214 /**
215 * Sets a <code>callback</code> method reference which is invoked when a bundle is added.
Pierre De Rop11527502016-02-18 21:07:16 +0000216 * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000217 *
218 * @param <T> the type of the component implementation class on which the callback is invoked on.
219 * @param add the method reference invoked when a bundle is added.
220 * @return this builder
221 */
Pierre De Rop11527502016-02-18 21:07:16 +0000222 <T> BundleDependencyBuilder add(CbBundleComponent<T> add);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000223
224 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000225 * Sets a <code>callback</code> method reference which is invoked when a bundle is changed.
226 * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000227 *
228 * @param <T> the type of the component implementation class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000229 * @param change the method reference invoked when a bundle has changed.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000230 * @return this builder
231 */
Pierre De Rop11527502016-02-18 21:07:16 +0000232 <T> BundleDependencyBuilder change(CbBundleComponent<T> change);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000233
234 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000235 * Sets a <code>callback</code> method reference which is invoked when a bundle is removed.
236 * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
237 *
238 * @param <T> the type of the component implementation class on which the callback is invoked on.
239 * @param remove the method reference invoked when a bundle is removed.
240 * @return this builder
241 */
242 <T> BundleDependencyBuilder remove(CbBundleComponent<T> remove);
243
244 /**
245 * Sets a method reference on an Object instance which is invoked when a bundle is added.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000246 * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
247 *
248 * @param add the method reference invoked when a bundle is added.
249 * @return this builder
250 */
Pierre De Rop11527502016-02-18 21:07:16 +0000251 BundleDependencyBuilder add(InstanceCbBundle add);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000252
253 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000254 * Sets a method reference on an Object instance which is invoked when a bundle is changed.
255 * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000256 *
Pierre De Rop11527502016-02-18 21:07:16 +0000257 * @param change the method reference invoked when a bundle is changed.
258 * @return this builder
259 */
260 BundleDependencyBuilder change(InstanceCbBundle change);
261
262 /**
263 * Sets a method reference on an Object instance which is invoked when a bundle is removed.
264 * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
265 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000266 * @param remove the method reference invoked when a bundle is removed.
267 * @return this builder
268 */
Pierre De Rop11527502016-02-18 21:07:16 +0000269 BundleDependencyBuilder remove(InstanceCbBundle remove);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000270
271 /**
272 * Sets a <code>callback instance</code> method reference which is invoked when a bundle is added.
Pierre De Rop11527502016-02-18 21:07:16 +0000273 * The method reference must point to an Object instance method, and takes as arguments a Bundle and a Component.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000274 *
275 * @param add the method reference invoked when a bundle is added.
276 * @return this builder
277 */
Pierre De Rop11527502016-02-18 21:07:16 +0000278 BundleDependencyBuilder add(InstanceCbBundleComponent add);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000279
280 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000281 * Sets a <code>callback instance</code> method reference which is invoked when a bundle is changed.
282 * The method reference must point to an Object instance method, and takes as argument a Bundle and a Component.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000283 *
Pierre De Rop11527502016-02-18 21:07:16 +0000284 * @param change the method reference invoked when a bundle is changed.
285 * @return this builder
286 */
287 BundleDependencyBuilder change(InstanceCbBundleComponent change);
288
289 /**
290 * Sets a <code>callback instance</code> method reference which is invoked when a bundle is removed.
291 * The method reference must point to an Object instance method, and takes as argument a Bundle and a Component.
292 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000293 * @param remove the method reference invoked when a bundle is removed.
294 * @return this builder
295 */
Pierre De Rop11527502016-02-18 21:07:16 +0000296 BundleDependencyBuilder remove(InstanceCbBundleComponent remove);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000297}