blob: 206c9e9dcdf8d2d67155aaba76cbf1820b370e8f [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001package org.apache.felix.dm.lambda;
2
3import java.util.Dictionary;
4import java.util.concurrent.CompletableFuture;
5import java.util.function.Consumer;
6import java.util.function.Function;
7import java.util.function.Supplier;
8import java.util.stream.Stream;
9
10import org.apache.felix.dm.Component;
Pierre De Rop11527502016-02-18 21:07:16 +000011import org.apache.felix.dm.lambda.callbacks.Cb;
Pierre De Ropfaca2892016-01-31 23:27:05 +000012import org.apache.felix.dm.lambda.callbacks.CbComponent;
Pierre De Rop11527502016-02-18 21:07:16 +000013import org.apache.felix.dm.lambda.callbacks.InstanceCb;
14import org.apache.felix.dm.lambda.callbacks.InstanceCbComponent;
Pierre De Ropfaca2892016-01-31 23:27:05 +000015
16/**
17 * Builds a Dependency Manager Component. Components are the main building blocks for OSGi applications.
18 * They can publish themselves as a service, and they can have dependencies.
19 * These dependencies will influence their life cycle as component will only be activated when all
20 * required dependencies are available.
21 *
22 * <p> This interface is also the base interface for extended components like aspects, adapters, etc ...
23 *
24 * <p> Example of a component that depends on a ConfigurationAdmin service. The dependency is injected by reflection
25 * on a class field which type matches the ConfigurationAdmin interface:
26 *
27 * <pre>{@code
28 * public class Activator extends DependencyManagerActivator {
Pierre De Rop11527502016-02-18 21:07:16 +000029 * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
30 * component(comp -> comp.impl(Configurator.class).withSvc(ConfigurationAdmin.class));
Pierre De Ropfaca2892016-01-31 23:27:05 +000031 * }
32 * }
33 * } </pre>
34 *
35 * @param <B> the type of a builder that may extends this builder interface (aspect/adapter).
36 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
37 */
38public interface ComponentBuilder<B extends ComponentBuilder<B>> {
Pierre De Rop11527502016-02-18 21:07:16 +000039
Pierre De Ropfaca2892016-01-31 23:27:05 +000040 /**
41 * Configures the component implementation. Can be a class name, or a component implementation object.
42 *
43 * @param impl the component implementation (a class, or an Object).
44 * @return this builder
45 */
46 B impl(Object impl);
47
48 /**
49 * Sets the factory to use to create the implementation. You can specify both the factory class and method to invoke. The method should return the implementation,
50 * and can use any method to create it. Actually, this can be used together with setComposition to create a composition of instances that work together to implement
51 * a component. The factory itself can also be instantiated lazily by not specifying an instance, but a Class.
52 *
53 * @param factory the factory instance, or the factory class.
54 * @param createMethod the create method called on the factory in order to instantiate the component instance.
55 * @return this builder
56 */
57 B factory(Object factory, String createMethod);
58
59 /**
60 * Configures a factory that can be used to create this component implementation.
61 * Example:
62 *
63 * <pre> {@code
64 * factory(ComponentImpl::new)", or "factory(() -> new ComponentImpl())
65 * }</pre>
66 *
67 * @param create the factory used to create the component implementation.
68 * @return this builder
69 */
70 B factory(Supplier<?> create);
71
72 /**
73 * Configures a factory used to create this component implementation using a Factory object and a method in the Factory object.
74 * Example:
75 *
76 * <pre> {@code
77 * factory(Factory::new, Factory::create)
78 * }</pre>
79 *
80 * @param <U> the type of the factory returned by the supplier
81 * @param <V> the type of the object that is returned by the factory create method.
82 * @param factory the function used to create the Factory itself
83 * @param create the method reference on the Factory method that is used to create the Component implementation
84 * @return this builder
85 */
86 <U, V> B factory(Supplier<U> factory, Function<U, V> create);
87
88 /**
Pierre De Rop11527502016-02-18 21:07:16 +000089 * Configures a factory used to create this component implementation using a Factory object and a "getComposition" factory method.
90 * the Factory method may then return multiple objects that will be part of this component implementation, and
91 * all of them will be searched for injecting any of the dependencies.
Pierre De Ropfaca2892016-01-31 23:27:05 +000092 *
93 * Example:
94 *
95 * <pre> {@code
96 * CompositionManager mngr = new CompositionManager();
97 * ...
98 * factory(mngr::create, mngr::getComposition)
99 * }</pre>
100 *
101 * @param factory the supplier used to return the main component implementation instance
102 * @param getComposition the supplier that returns the list of instances that are part of the component implementation classes.
103 * @return this builder
104 */
105 B factory(Supplier<?> factory, Supplier<Object[]> getComposition);
106
107 /**
108 * Configures a factory that also returns a composition of objects for this component implemenation.
109 *
110 * Example:
111 *
112 * <pre> {@code
113 * factory(CompositionManager::new, CompositionManager::create, CompositionManager::getComposition).
114 * }</pre>
115 *
Pierre De Rop11527502016-02-18 21:07:16 +0000116 * Here, the CompositionManager will act as a factory (the create method will return the component implementation object), the
117 * CompositionManager.getComposition() method will return all the objects that are also part of the component implementation,
118 * and all of them will be searched for injecting any of the dependencies.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000119 *
120 * @param <U> the type of the object returned by the supplier factory
121 * @param factory the function used to create the Factory itself
122 * @param create the Factory method used to create the main component implementation object
123 * @param getComposition the Factory method used to return the list of objects that are also part of the component implementation.
124 * @return this builder
125 */
126 <U> B factory(Supplier<U> factory, Function<U, ?> create, Function<U, Object[]> getComposition);
127
128 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000129 * Sets the public interface under which this component should be registered in the OSGi service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000130 *
Pierre De Rop11527502016-02-18 21:07:16 +0000131 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000132 * @return this builder
133 */
134 B provides(Class<?> iface);
135
136 /**
137 * Sets the public interface under which this component should be registered in the OSGi service registry.
138 *
Pierre De Rop11527502016-02-18 21:07:16 +0000139 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000140 * @param name a property name for the provided service
141 * @param value a property value for the provided service
142 * @param rest the rest of property name/value pairs.
143 * @return this builder.
144 */
145 B provides(Class<?> iface, String name, Object value, Object ... rest);
146
147 /**
148 * Sets the public interface under which this component should be registered in the OSGi service registry.
149 * Warning: you can only use this method if you compile your application using the "-parameters" javac option.
150 *
151 * code example:
152 *
153 * <pre> {@code
154 * provides(MyService.class, property1 -> "value1", property2 -> 123);
155 * }</pre>
156 *
Pierre De Rop11527502016-02-18 21:07:16 +0000157 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000158 * @param properties a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
Pierre De Rop0aac1362016-02-02 19:46:08 +0000159 * {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000160 * @return this builder.
161 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000162 B provides(Class<?> iface, FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000163
164 /**
165 * Sets the public interface under which this component should be registered in the OSGi service registry.
Pierre De Rop11527502016-02-18 21:07:16 +0000166 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000167 * @param properties the properties for the provided service
168 * @return this builder.
169 */
170 B provides(Class<?> iface, Dictionary<?,?> properties);
171
172 /**
173 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
174 *
175 * @param ifaces list of services provided by the component.
176 * @return this builder.
177 */
178 B provides(Class<?>[] ifaces);
179
180 /**
181 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
182 *
183 * @param ifaces the public interfaces to register in the OSGI service registry.
184 * @param name a property name for the provided service
185 * @param value a property value for the provided service
186 * @param rest the rest of property name/value pairs.
187 * @return this builder.
188 */
189 B provides(Class<?>[] ifaces, String name, Object value, Object ... rest);
190
191 /**
192 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
193 * Warning: you can only use this method if you compile your application using the "-parameters" javac option.
194 * code example:
195 *
196 * <pre> {@code
197 * provides(new Class[] { MyService.class, MyService2.class }, property1 -> "value1", property2 -> 123);
198 * }</pre>
199 *
200 * @param ifaces the public interfaces to register in the OSGI service registry.
201 * @param properties a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
Pierre De Rop0aac1362016-02-02 19:46:08 +0000202 * {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000203 * @return this builder.
204 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000205 B provides(Class<?>[] ifaces, FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000206
207 /**
208 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
Pierre De Rop11527502016-02-18 21:07:16 +0000209 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000210 * @param ifaces the public interfaces to register in the OSGI service registry.
211 * @param properties the properties for the provided service
212 * @return this builder.
213 */
214 B provides(Class<?>[] ifaces, Dictionary<?,?> properties);
215
216 /**
217 * Sets the public interface under which this component should be registered in the OSGi service registry.
218 *
219 * @param iface the service provided by this component.
220 * @return this builder.
221 */
222 B provides(String iface);
223
224 /**
225 * Sets the public interface under which this component should be registered in the OSGi service registry.
226 *
Pierre De Rop11527502016-02-18 21:07:16 +0000227 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000228 * @param name a property name for the provided service
229 * @param value a property value for the provided service
230 * @param rest the rest of property name/value pairs.
231 * @return this builder.
232 */
233 B provides(String iface, String name, Object value, Object ... rest);
234
235 /**
236 * Sets the public interface under which this component should be registered in the OSGi service registry.
237 * Warning: you can only use this method if you compile your application using the "-parameters" javac option.
238 * code example:
239 *
240 * <pre> {@code
241 * provides(MyService.class, property1 -> "value1", property2 -> 123);
242 * }</pre>
243 *
Pierre De Rop11527502016-02-18 21:07:16 +0000244 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000245 * @param properties a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
Pierre De Rop0aac1362016-02-02 19:46:08 +0000246 * {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000247 * @return this builder.
248 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000249 B provides(String iface, FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000250
251 /**
252 * Sets the public interface under which this component should be registered in the OSGi service registry.
Pierre De Rop11527502016-02-18 21:07:16 +0000253 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000254 * @param properties the properties for the provided service
255 * @return this builder.
256 */
257 B provides(String iface, Dictionary<?,?> properties);
258
259 /**
260 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
261 *
262 * @param ifaces the list of services provided by the component.
263 * @return this builder.
264 */
265 B provides(String[] ifaces);
266
267 /**
268 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
269 *
270 * @param ifaces the public interfaces to register in the OSGI service registry.
271 * @param name a property name for the provided service
272 * @param value a property value for the provided service
273 * @param rest the rest of property name/value pairs.
274 * @return this builder.
275 */
276 B provides(String[] ifaces, String name, Object value, Object ... rest);
277
278 /**
279 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
280 * Warning: you can only use this method if you compile your application using the "-parameters" javac option.
281 *
282 * code example:
283 * <pre> {@code
284 * provides(new Class[] { MyService.class, MyService2.class }, property1 -> "value1", property2 -> 123);
285 * }</pre>
286 *
287 * @param ifaces the public interfaces to register in the OSGI service registry.
288 * @param properties a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
Pierre De Rop0aac1362016-02-02 19:46:08 +0000289 * {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000290 * @return this builder.
291 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000292 B provides(String[] ifaces, FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000293
294 /**
295 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
Pierre De Rop11527502016-02-18 21:07:16 +0000296 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000297 * @param ifaces the public interfaces to register in the OSGI service registry.
298 * @param properties the properties for the provided service
299 * @return this builder.
300 */
301 B provides(String[] ifaces, Dictionary<?,?> properties);
302
303 /**
304 * Sets the component's service properties
305 * @param properties the component's service properties
306 * @return this builder
307 */
308 B properties(Dictionary<?,?> properties);
309
310 /**
311 * Sets the components's service properties using varargs. The number of parameters must be even, representing a list of pair property key-value.
312 *
313 * <pre> {@code
314 * Example: properties("param1", "value1", "service.ranking", 3)
315 * }</pre>
316 *
317 * @param name the first property name
318 * @param value the first property value
319 * @param rest the rest of properties key/value pairs.
320 * @return this builder
321 */
322 B properties(String name, Object value, Object ... rest);
323
324 /**
325 * Sets the components's service properties using List of lamda properties.
326 *
327 * Example:
328 *
329 * <pre> {@code
330 * properties(param1 -> "value1, param2 -> 2);
331 * }</pre>
332 *
333 * When you use this method, you must compile your source code using the "-parameters" option, and the "arg0" parameter
334 * name is now allowed.
335 *
336 * @param properties the fluent properties
337 * @return this builder
338 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000339 B properties(FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000340
341 /**
342 * Adds a required/autoconfig service dependency.
343 *
344 * @param service the service dependency filter
345 * @param filter the service filter
346 * @return this builder
347 */
Pierre De Rop11527502016-02-18 21:07:16 +0000348 B withSvc(Class<?> service, String filter);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000349
350 /**
351 * Adds in one shot multiple required/autoconfig service dependencies.
352 * @param services the dependencies that are required and that will be injected in any field with the same dependency type.
353 * @return this builder
354 */
Pierre De Rop11527502016-02-18 21:07:16 +0000355 B withSvc(Class<?> ... services);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000356
357 /**
358 * Adds a service dependency built using a Consumer lambda that is provided with a ServiceDependencyBuilder.
359 *
360 * @param <U> the type of the dependency service
361 * @param service the service
362 * @param consumer the lambda for building the service dependency
363 * @return this builder.
364 */
Pierre De Rop11527502016-02-18 21:07:16 +0000365 <U> B withSvc(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000366
367 /**
368 * Adds a configuration dependency.
369 * @param consumer the lambda used to build the configuration dependency.
370 * @return this builder.
371 */
372 B withCnf(Consumer<ConfigurationDependencyBuilder> consumer);
373
374 /**
375 * Adds multiple configuration dependencies in one single call. All configurations are injected by default in the "updated" callback.
376 * @param pids list of configuration pids.
377 * @return this builder
378 */
379 @SuppressWarnings("unchecked")
380 default B withCnf(String ... pids) {
381 Stream.of(pids).forEach(pid -> withCnf(cnf -> cnf.pid(pid)));
382 return (B) this;
383 }
384
385 /**
Pierre De Ropfaca2892016-01-31 23:27:05 +0000386 * Adds a bundle dependency.
387 * @param consumer the lambda used to build the bundle dependency.
388 * @return this builder.
389 */
390 B withBundle(Consumer<BundleDependencyBuilder> consumer);
391
392 /**
393 * Adds a CompletableFuture dependency.
394 *
395 * @param <U> the type of the result of the CompletableFuture.
396 * @param future a CompletableFuture on which the dependency will wait for
397 * @param consumer the builder used to build the dependency
398 * @return this builder.
399 */
400 <U> B withFuture(CompletableFuture<U> future, Consumer<FutureDependencyBuilder<U>> consumer);
401
402 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000403 * Sets the instance to invoke with the reflection based lifecycle callbacks. By default, reflection based
404 * lifecycle callbacks (init/start/stop/destroy) methods are invoked on the component implementation instance(s).
405 * But you can set a specific callback instance using this method.
406 * <p>
407 * Specifying an instance means you can create a manager
408 * that will be invoked whenever the life cycle of a component changes and this manager
409 * can then decide how to expose this life cycle to the actual component, offering an
410 * important indirection when developing your own component models.
411 *
412 * @see #init(String)
413 * @see #start(String)
414 * @see #stop(String)
415 * @see #destroy(String)
416 * @param lifecycleCallbackInstance the instance the lifecycle callback will be invoked on.
417 * @return this builder.
418 */
419 B lifecycleCallbackInstance(Object lifecycleCallbackInstance);
420
421 /**
Pierre De Ropfaca2892016-01-31 23:27:05 +0000422 * Sets the name of the method used as the "init" callback. This method, when found, is
423 * invoked as part of the life cycle management of the component implementation.
424 * This method is useful because when it is invoked, all required dependencies defines in the Activator
425 * are already injected, and you can then add more extra dependencies from the init() method.
426 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
427 * The dependency manager will look for a method of this name with the following signatures,
428 * in this order:
429 * <ol>
430 * <li>method(Component component)</li>
431 * <li>method()</li>
432 * </ol>
433 *
434 * @param callback the callback name
435 * @return this builder.
436 */
437 B init(String callback);
438
439 /**
440 * Sets the name of the method used as the "start" callback. This method, when found, is
441 * invoked as part of the life cycle management of the component implementation. The
442 * dependency manager will look for a method of this name with the following signatures,
443 * in this order:
444 * <ol>
445 * <li>method(Component component)</li>
446 * <li>method()</li>
447 * </ol>
448 *
449 * @param callback the callback name
450 * @return this builder.
451 */
452 B start(String callback);
453
454 /**
455 * Sets the name of the method used as the "stop" callback. This method, when found, is
456 * invoked as part of the life cycle management of the component implementation. The
457 * dependency manager will look for a method of this name with the following signatures,
458 * in this order:
459 * <ol>
460 * <li>method(Component component)</li>
461 * <li>method()</li>
462 * </ol>
463 *
464 * @param callback the callback name
465 * @return this builder.
466 */
467 B stop(String callback);
468
469 /**
470 * Sets the name of the method used as the "destroy" callback. This method, when found, is
471 * invoked as part of the life cycle management of the component implementation. The
472 * dependency manager will look for a method of this name with the following signatures,
473 * in this order:
474 * <ol>
475 * <li>method(Component component)</li>
476 * <li>method()</li>
477 * </ol>
478 *
479 * @param callback the callback name
480 * @return this builder.
481 */
482 B destroy(String callback);
Pierre De Rop11527502016-02-18 21:07:16 +0000483
Pierre De Ropfaca2892016-01-31 23:27:05 +0000484 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000485 * Sets a reference to a component implementation class "init" callback method.
486 * This method does not take any arguments and is
487 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000488 * This method is useful because when it is invoked, all required dependencies defines in the Activator
489 * are already injected, and you can then add more extra dependencies from the init() method.
490 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000491 *
Pierre De Rop11527502016-02-18 21:07:16 +0000492 * @param <T> the type of the component class on which the callback is invoked on.
493 * @param callback a method reference must point to method from the component instance class(es).
Pierre De Ropfaca2892016-01-31 23:27:05 +0000494 * @return this builder
495 */
Pierre De Rop11527502016-02-18 21:07:16 +0000496 <T> B init(Cb<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000497
498 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000499 * Sets a reference to a component implementation class "start" callback method.
500 * This method does not take any arguments and is
501 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000502 *
Pierre De Rop11527502016-02-18 21:07:16 +0000503 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000504 * @param callback a method reference must point to method from one of the component instance classes.
505 * @return this builder.
506 */
Pierre De Rop11527502016-02-18 21:07:16 +0000507 <T> B start(Cb<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000508
509 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000510 * Sets a reference to a component implementation class "stop" callback method.
511 * This method does not take any arguments and is
512 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000513 *
Pierre De Rop11527502016-02-18 21:07:16 +0000514 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000515 * @param callback a method reference must point to method from one of the component instance classes.
516 * @return this builder.
517 */
Pierre De Rop11527502016-02-18 21:07:16 +0000518 <T> B stop(Cb<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000519
520 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000521 * Sets a reference to a component implementation class "destroy" callback method.
522 * This method does not take any arguments and is
523 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000524 *
Pierre De Rop11527502016-02-18 21:07:16 +0000525 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000526 * @param callback a method reference must point to method from one of the component instance classes.
527 * @return this builder.
528 */
Pierre De Rop11527502016-02-18 21:07:16 +0000529 <T> B destroy(Cb<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000530
531 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000532 * Sets a reference to a component implementation class "init" callback method.
533 * This method takes a Component argument and is
534 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000535 * This method is useful because when it is invoked, all required dependencies defines in the Activator
536 * are already injected, and you can then add more extra dependencies from the init() method.
537 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000538 *
Pierre De Rop11527502016-02-18 21:07:16 +0000539 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000540 * @param callback a method reference must point to method from one of the component instance classes. The method takes as argument a Component parameter.
541 * @return this builder
542 */
Pierre De Rop11527502016-02-18 21:07:16 +0000543 <T> B init(CbComponent<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000544
545 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000546 * Sets a reference to a component implementation class "start" callback method.
547 * This method takes a Component argument and is
548 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000549 *
Pierre De Rop11527502016-02-18 21:07:16 +0000550 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000551 * @param callback a method reference must point to method from one of the component instance classes. The method takes as argument a Component parameter.
552 * @return this builder.
553 */
Pierre De Rop11527502016-02-18 21:07:16 +0000554 <T> B start(CbComponent<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000555
556 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000557 * Sets a reference to a component implementation class "stop" callback method.
558 * This method takes a Component argument and is
559 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000560 *
Pierre De Rop11527502016-02-18 21:07:16 +0000561 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000562 * @param callback a method reference must point to method from one of the component instance classes. The method takes as argument a Component parameter.
563 * @return this builder.
564 */
Pierre De Rop11527502016-02-18 21:07:16 +0000565 <T> B stop(CbComponent<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000566
567 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000568 * Sets a reference to a component implementation class "destroy" callback method.
569 * This method takes a Component argument and is
570 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000571 *
Pierre De Rop11527502016-02-18 21:07:16 +0000572 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000573 * @param callback a method reference must point to method from one of the component instance classes. The method takes as argument a Component parameter.
574 * @return this builder.
575 */
Pierre De Rop11527502016-02-18 21:07:16 +0000576 <T> B destroy(CbComponent<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000577
578 /**
579 * Sets an Object instance method reference used as the "init" callback. It is invoked as part of the life cycle management of the component
580 * implementation.
581 * This method is useful because when it is invoked, all required dependencies defines in the Activator
582 * are already injected, and you can then add more extra dependencies from the init() method.
583 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
584 * The method does not take any parameters.
585 *
586 * @param callback an Object instance method reference. The method does not take any parameters.
587 * @return this builder
588 */
Pierre De Rop11527502016-02-18 21:07:16 +0000589 B initInstance(InstanceCb callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000590
591 /**
592 * Sets an Object instance method reference used as the "start" callback. This method reference must point to method from one
593 * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
594 * The method does not take any parameters.
595 *
596 * @param callback an Object instance method reference. The method does not take any parameters.
597 * @return this builder.
598 */
Pierre De Rop11527502016-02-18 21:07:16 +0000599 B startInstance(InstanceCb callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000600
601 /**
602 * Sets an Object instance method reference used as the "stop" callback. It is invoked as part of the life cycle management of the component
603 * implementation.
604 * This method is useful because when it is invoked, all required dependencies defines in the Activator
605 * are already injected, and you can then add more extra dependencies from the init() method.
606 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
607 * The method does not take any parameters.
608 *
609 * @param callback an Object instance method reference. The method does not take any parameters.
610 * @return this builder
611 */
Pierre De Rop11527502016-02-18 21:07:16 +0000612 B stopInstance(InstanceCb callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000613
614 /**
615 * Sets an Object instance method reference used as the "destroy" callback. It is invoked as part of the life cycle management of the component
616 * implementation.
617 * This method is useful because when it is invoked, all required dependencies defines in the Activator
618 * are already injected, and you can then add more extra dependencies from the init() method.
619 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
620 * The method does not take any parameters.
621 *
622 * @param callback an Object instance method reference. The method does not take any parameters.
623 * @return this builder
624 */
Pierre De Rop11527502016-02-18 21:07:16 +0000625 B destroyInstance(InstanceCb callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000626
627 /**
628 * Sets an Object instance method reference used as the "init" callback. It is invoked as part of the life cycle management of the component
629 * implementation.
630 * This method is useful because when it is invoked, all required dependencies defines in the Activator
631 * are already injected, and you can then add more extra dependencies from the init() method.
632 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
633 * The method takes as argument a Component parameter.
634 *
Pierre De Rop11527502016-02-18 21:07:16 +0000635 * @param callback an Object instance method reference. The method takes as argument a Component parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000636 * @return this builder
637 */
Pierre De Rop11527502016-02-18 21:07:16 +0000638 B initInstance(InstanceCbComponent callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000639
640 /**
641 * Sets an Object instance method reference used as the "start" callback. This method reference must point to method from one
642 * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
643 * The method takes as argument a Component parameter.
644 *
645 * @param callback an Object instance method reference. The method takes as argument a Component parameter.
646 * @return this builder.
647 */
Pierre De Rop11527502016-02-18 21:07:16 +0000648 B startInstance(InstanceCbComponent callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000649
650 /**
651 * Sets an Object instance method reference used as the "stop" callback. This method reference must point to method from one
652 * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
653 * The method takes as argument a Component parameter.
654 *
655 * @param callback an Object instance method reference. The method takes as argument a Component parameter.
656 * @return this builder.
657 */
Pierre De Rop11527502016-02-18 21:07:16 +0000658 B stopInstance(InstanceCbComponent callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000659
660 /**
661 * Sets an Object instance method reference used as the "destroy" callback. This method reference must point to method from one
662 * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
663 * The method takes as argument a Component parameter.
664 *
665 * @param callback an Object instance method reference. The method takes as argument a Component parameter.
666 * @return this builder.
667 */
Pierre De Rop11527502016-02-18 21:07:16 +0000668 B destroyInstance(InstanceCbComponent callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000669
670 /**
671 * Configures OSGi object (BundleContext, Component, etc ...) that will be injected in any field having the same OSGi object type.
672 * @param clazz the OSGi object type (BundleContext, Component, DependencyManager).
673 * @param autoConfig true if the OSGi object has to be injected, false if not
674 * @return this builder
675 */
676 B autoConfig(Class<?> clazz, boolean autoConfig);
677
678 /**
679 * Configures OSGi object (BundleContext, Component, etc ...) that will be injected in a given field.
680 * @param clazz the OSGi object type (BundleContext, Component, DependencyManager).
681 * @param field the field that will be injected with the OSGI object
682 * @return this builder
683 */
684 B autoConfig(Class<?> clazz, String field);
685
686 /**
687 * Activates debug mode
688 * @param label the debug label
689 * @return this builder
690 */
691 B debug(String label);
692
693 /**
694 * Automatically adds this component to its DependencyManager object. When a lambda builds a Component using this builder, by default
695 * the built component is auto added to its DependencyManager object, unless you invoke autoAdd(false).
696 *
697 * @param autoAdd true for automatically adding this component to the DependencyManager object, false if not
698 * @return this builder
699 */
700 B autoAdd(boolean autoAdd);
701
702 /**
703 * Sets the method to invoke on the service implementation to get back all
704 * instances that are part of a composition and need dependencies injected.
Pierre De Rop11527502016-02-18 21:07:16 +0000705 * All of them will be searched to inject any of the dependencies. The method that
Pierre De Ropfaca2892016-01-31 23:27:05 +0000706 * is invoked must return an <code>Object[]</code>.
707 *
708 * @param getCompositionMethod the method to invoke
709 * @return this builder
710 */
711 B composition(String getCompositionMethod);
712
713 /**
714 * Sets the instance and method to invoke to get back all instances that
715 * are part of a composition and need dependencies injected. All of them
Pierre De Rop11527502016-02-18 21:07:16 +0000716 * will be searched to inject any of the dependencies. The method that is
Pierre De Ropfaca2892016-01-31 23:27:05 +0000717 * invoked must return an <code>Object[]</code>.
718 *
719 * @param instance the instance that has the method
720 * @param getCompositionMethod the method to invoke
721 * @return this builder
722 */
723 B composition(Object instance, String getCompositionMethod);
724
725 /**
726 * Sets a java8 method reference to a Supplier that returns all instances that are part of a composition and need dependencies injected.
727 * All of them will be searched for any of the dependencies. The method that
728 * is invoked must return an <code>Object[]</code>.
729 *
730 * @param getCompositionMethod the method to invoke
731 * @return this builder
732 */
733 B composition(Supplier<Object[]> getCompositionMethod);
734
735 /**
736 * Builds the real DependencyManager Component.
737 * @return the real DependencyManager Component.
738 */
739 Component build();
740}