blob: 40ba0c567a897c712822b2216b431c234c45dc7a [file] [log] [blame]
Pierre De Rop6e8f9212016-02-20 21:44:59 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Pierre De Ropfaca2892016-01-31 23:27:05 +000019package org.apache.felix.dm.lambda;
20
21import java.util.Dictionary;
22import java.util.concurrent.CompletableFuture;
23import java.util.function.Consumer;
24import java.util.function.Function;
25import java.util.function.Supplier;
26import java.util.stream.Stream;
27
28import org.apache.felix.dm.Component;
Pierre De Rop11527502016-02-18 21:07:16 +000029import org.apache.felix.dm.lambda.callbacks.Cb;
Pierre De Ropfaca2892016-01-31 23:27:05 +000030import org.apache.felix.dm.lambda.callbacks.CbComponent;
Pierre De Rop11527502016-02-18 21:07:16 +000031import org.apache.felix.dm.lambda.callbacks.InstanceCb;
32import org.apache.felix.dm.lambda.callbacks.InstanceCbComponent;
Pierre De Ropfaca2892016-01-31 23:27:05 +000033
34/**
Pierre De Rop6e8f9212016-02-20 21:44:59 +000035 * Builds a Dependency Manager Component. <p> Components are the main building blocks for OSGi applications.
Pierre De Ropfaca2892016-01-31 23:27:05 +000036 * They can publish themselves as a service, and they can have dependencies.
37 * These dependencies will influence their life cycle as component will only be activated when all
Pierre De Rop6e8f9212016-02-20 21:44:59 +000038 * required dependencies are available. This interface is also the base interface for extended components like
39 * aspects, adapters, etc ...
Pierre De Ropfaca2892016-01-31 23:27:05 +000040 *
41 * <p> Example of a component that depends on a ConfigurationAdmin service. The dependency is injected by reflection
42 * on a class field which type matches the ConfigurationAdmin interface:
43 *
44 * <pre>{@code
45 * public class Activator extends DependencyManagerActivator {
Pierre De Rop11527502016-02-18 21:07:16 +000046 * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
47 * component(comp -> comp.impl(Configurator.class).withSvc(ConfigurationAdmin.class));
Pierre De Ropfaca2892016-01-31 23:27:05 +000048 * }
49 * }
50 * } </pre>
51 *
52 * @param <B> the type of a builder that may extends this builder interface (aspect/adapter).
53 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
54 */
55public interface ComponentBuilder<B extends ComponentBuilder<B>> {
Pierre De Rop11527502016-02-18 21:07:16 +000056
Pierre De Ropfaca2892016-01-31 23:27:05 +000057 /**
58 * Configures the component implementation. Can be a class name, or a component implementation object.
59 *
60 * @param impl the component implementation (a class, or an Object).
61 * @return this builder
62 */
63 B impl(Object impl);
64
65 /**
Pierre De Rop57ffa3f2016-02-19 12:54:30 +000066 * Sets the factory to use when creating the implementation. You can specify both the factory class and method to invoke. The method should return the implementation,
Pierre De Ropfaca2892016-01-31 23:27:05 +000067 * 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
68 * a component. The factory itself can also be instantiated lazily by not specifying an instance, but a Class.
69 *
70 * @param factory the factory instance, or the factory class.
Pierre De Rop6e8f9212016-02-20 21:44:59 +000071 * @param createMethod the create method called on the factory in order to instantiate the component.
Pierre De Ropfaca2892016-01-31 23:27:05 +000072 * @return this builder
73 */
74 B factory(Object factory, String createMethod);
75
76 /**
77 * Configures a factory that can be used to create this component implementation.
78 * Example:
79 *
80 * <pre> {@code
81 * factory(ComponentImpl::new)", or "factory(() -> new ComponentImpl())
82 * }</pre>
83 *
84 * @param create the factory used to create the component implementation.
85 * @return this builder
86 */
87 B factory(Supplier<?> create);
88
89 /**
90 * Configures a factory used to create this component implementation using a Factory object and a method in the Factory object.
91 * Example:
92 *
93 * <pre> {@code
94 * factory(Factory::new, Factory::create)
95 * }</pre>
96 *
97 * @param <U> the type of the factory returned by the supplier
98 * @param <V> the type of the object that is returned by the factory create method.
99 * @param factory the function used to create the Factory itself
100 * @param create the method reference on the Factory method that is used to create the Component implementation
101 * @return this builder
102 */
103 <U, V> B factory(Supplier<U> factory, Function<U, V> create);
104
105 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000106 * Configures a factory used to create this component implementation using a Factory object and a "getComposition" factory method.
107 * the Factory method may then return multiple objects that will be part of this component implementation, and
Pierre De Rop57ffa3f2016-02-19 12:54:30 +0000108 * all of them will be searched when injecting any of the dependencies.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000109 *
110 * Example:
111 *
112 * <pre> {@code
113 * CompositionManager mngr = new CompositionManager();
114 * ...
115 * factory(mngr::create, mngr::getComposition)
116 * }</pre>
117 *
118 * @param factory the supplier used to return the main component implementation instance
119 * @param getComposition the supplier that returns the list of instances that are part of the component implementation classes.
120 * @return this builder
121 */
122 B factory(Supplier<?> factory, Supplier<Object[]> getComposition);
123
124 /**
125 * Configures a factory that also returns a composition of objects for this component implemenation.
126 *
127 * Example:
128 *
129 * <pre> {@code
130 * factory(CompositionManager::new, CompositionManager::create, CompositionManager::getComposition).
131 * }</pre>
132 *
Pierre De Rop11527502016-02-18 21:07:16 +0000133 * Here, the CompositionManager will act as a factory (the create method will return the component implementation object), the
134 * CompositionManager.getComposition() method will return all the objects that are also part of the component implementation,
135 * and all of them will be searched for injecting any of the dependencies.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000136 *
137 * @param <U> the type of the object returned by the supplier factory
138 * @param factory the function used to create the Factory itself
139 * @param create the Factory method used to create the main component implementation object
140 * @param getComposition the Factory method used to return the list of objects that are also part of the component implementation.
141 * @return this builder
142 */
143 <U> B factory(Supplier<U> factory, Function<U, ?> create, Function<U, Object[]> getComposition);
144
145 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000146 * Sets the public interface under which this component should be registered in the OSGi service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000147 *
Pierre De Rop11527502016-02-18 21:07:16 +0000148 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000149 * @return this builder
150 */
151 B provides(Class<?> iface);
152
153 /**
154 * Sets the public interface under which this component should be registered in the OSGi service registry.
155 *
Pierre De Rop11527502016-02-18 21:07:16 +0000156 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000157 * @param name a property name for the provided service
158 * @param value a property value for the provided service
159 * @param rest the rest of property name/value pairs.
160 * @return this builder.
161 */
162 B provides(Class<?> iface, String name, Object value, Object ... rest);
163
164 /**
165 * Sets the public interface under which this component should be registered in the OSGi service registry.
166 * Warning: you can only use this method if you compile your application using the "-parameters" javac option.
167 *
168 * code example:
169 *
170 * <pre> {@code
171 * provides(MyService.class, property1 -> "value1", property2 -> 123);
172 * }</pre>
173 *
Pierre De Rop11527502016-02-18 21:07:16 +0000174 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000175 * @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 +0000176 * {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000177 * @return this builder.
178 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000179 B provides(Class<?> iface, FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000180
181 /**
182 * Sets the public interface under which this component should be registered in the OSGi service registry.
Pierre De Rop11527502016-02-18 21:07:16 +0000183 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000184 * @param properties the properties for the provided service
185 * @return this builder.
186 */
187 B provides(Class<?> iface, Dictionary<?,?> properties);
188
189 /**
190 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
191 *
192 * @param ifaces list of services provided by the component.
193 * @return this builder.
194 */
195 B provides(Class<?>[] ifaces);
196
197 /**
198 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
199 *
200 * @param ifaces the public interfaces to register in the OSGI service registry.
201 * @param name a property name for the provided service
202 * @param value a property value for the provided service
203 * @param rest the rest of property name/value pairs.
204 * @return this builder.
205 */
206 B provides(Class<?>[] ifaces, String name, Object value, Object ... rest);
207
208 /**
209 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
210 * Warning: you can only use this method if you compile your application using the "-parameters" javac option.
211 * code example:
212 *
213 * <pre> {@code
214 * provides(new Class[] { MyService.class, MyService2.class }, property1 -> "value1", property2 -> 123);
215 * }</pre>
216 *
217 * @param ifaces the public interfaces to register in the OSGI service registry.
218 * @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 +0000219 * {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000220 * @return this builder.
221 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000222 B provides(Class<?>[] ifaces, FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000223
224 /**
225 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
Pierre De Rop11527502016-02-18 21:07:16 +0000226 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000227 * @param ifaces the public interfaces to register in the OSGI service registry.
228 * @param properties the properties for the provided service
229 * @return this builder.
230 */
231 B provides(Class<?>[] ifaces, Dictionary<?,?> properties);
232
233 /**
234 * Sets the public interface under which this component should be registered in the OSGi service registry.
235 *
236 * @param iface the service provided by this component.
237 * @return this builder.
238 */
239 B provides(String iface);
240
241 /**
242 * Sets the public interface under which this component should be registered in the OSGi service registry.
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 name a property name for the provided service
246 * @param value a property value for the provided service
247 * @param rest the rest of property name/value pairs.
248 * @return this builder.
249 */
250 B provides(String iface, String name, Object value, Object ... rest);
251
252 /**
253 * Sets the public interface under which this component should be registered in the OSGi service registry.
254 * Warning: you can only use this method if you compile your application using the "-parameters" javac option.
255 * code example:
256 *
257 * <pre> {@code
258 * provides(MyService.class, property1 -> "value1", property2 -> 123);
259 * }</pre>
260 *
Pierre De Rop11527502016-02-18 21:07:16 +0000261 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000262 * @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 +0000263 * {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000264 * @return this builder.
265 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000266 B provides(String iface, FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000267
268 /**
269 * Sets the public interface under which this component should be registered in the OSGi service registry.
Pierre De Rop11527502016-02-18 21:07:16 +0000270 * @param iface the public interface to register in the OSGI service registry.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000271 * @param properties the properties for the provided service
272 * @return this builder.
273 */
274 B provides(String iface, Dictionary<?,?> properties);
275
276 /**
277 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
278 *
279 * @param ifaces the list of services provided by the component.
280 * @return this builder.
281 */
282 B provides(String[] ifaces);
283
284 /**
285 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
286 *
287 * @param ifaces the public interfaces to register in the OSGI service registry.
288 * @param name a property name for the provided service
289 * @param value a property value for the provided service
290 * @param rest the rest of property name/value pairs.
291 * @return this builder.
292 */
293 B provides(String[] ifaces, String name, Object value, Object ... rest);
294
295 /**
296 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
297 * Warning: you can only use this method if you compile your application using the "-parameters" javac option.
298 *
299 * code example:
300 * <pre> {@code
301 * provides(new Class[] { MyService.class, MyService2.class }, property1 -> "value1", property2 -> 123);
302 * }</pre>
303 *
304 * @param ifaces the public interfaces to register in the OSGI service registry.
305 * @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 +0000306 * {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000307 * @return this builder.
308 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000309 B provides(String[] ifaces, FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000310
311 /**
312 * Sets the public interfaces under which this component should be registered in the OSGi service registry.
Pierre De Rop11527502016-02-18 21:07:16 +0000313 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000314 * @param ifaces the public interfaces to register in the OSGI service registry.
315 * @param properties the properties for the provided service
316 * @return this builder.
317 */
318 B provides(String[] ifaces, Dictionary<?,?> properties);
319
320 /**
321 * Sets the component's service properties
322 * @param properties the component's service properties
323 * @return this builder
324 */
325 B properties(Dictionary<?,?> properties);
326
327 /**
328 * Sets the components's service properties using varargs. The number of parameters must be even, representing a list of pair property key-value.
329 *
330 * <pre> {@code
331 * Example: properties("param1", "value1", "service.ranking", 3)
332 * }</pre>
333 *
334 * @param name the first property name
335 * @param value the first property value
336 * @param rest the rest of properties key/value pairs.
337 * @return this builder
338 */
339 B properties(String name, Object value, Object ... rest);
340
341 /**
342 * Sets the components's service properties using List of lamda properties.
343 *
344 * Example:
345 *
346 * <pre> {@code
347 * properties(param1 -> "value1, param2 -> 2);
348 * }</pre>
349 *
350 * When you use this method, you must compile your source code using the "-parameters" option, and the "arg0" parameter
351 * name is now allowed.
352 *
353 * @param properties the fluent properties
354 * @return this builder
355 */
Pierre De Rop0aac1362016-02-02 19:46:08 +0000356 B properties(FluentProperty ... properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000357
358 /**
359 * Adds a required/autoconfig service dependency.
360 *
361 * @param service the service dependency filter
362 * @param filter the service filter
363 * @return this builder
364 */
Pierre De Rop11527502016-02-18 21:07:16 +0000365 B withSvc(Class<?> service, String filter);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000366
367 /**
368 * Adds in one shot multiple required/autoconfig service dependencies.
369 * @param services the dependencies that are required and that will be injected in any field with the same dependency type.
370 * @return this builder
371 */
Pierre De Rop11527502016-02-18 21:07:16 +0000372 B withSvc(Class<?> ... services);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000373
374 /**
375 * Adds a service dependency built using a Consumer lambda that is provided with a ServiceDependencyBuilder.
376 *
377 * @param <U> the type of the dependency service
378 * @param service the service
379 * @param consumer the lambda for building the service dependency
380 * @return this builder.
381 */
Pierre De Rop11527502016-02-18 21:07:16 +0000382 <U> B withSvc(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000383
384 /**
385 * Adds a configuration dependency.
386 * @param consumer the lambda used to build the configuration dependency.
387 * @return this builder.
388 */
389 B withCnf(Consumer<ConfigurationDependencyBuilder> consumer);
390
391 /**
392 * Adds multiple configuration dependencies in one single call. All configurations are injected by default in the "updated" callback.
393 * @param pids list of configuration pids.
394 * @return this builder
395 */
396 @SuppressWarnings("unchecked")
397 default B withCnf(String ... pids) {
398 Stream.of(pids).forEach(pid -> withCnf(cnf -> cnf.pid(pid)));
399 return (B) this;
400 }
401
402 /**
Pierre De Ropfaca2892016-01-31 23:27:05 +0000403 * Adds a bundle dependency.
404 * @param consumer the lambda used to build the bundle dependency.
405 * @return this builder.
406 */
407 B withBundle(Consumer<BundleDependencyBuilder> consumer);
408
409 /**
410 * Adds a CompletableFuture dependency.
411 *
412 * @param <U> the type of the result of the CompletableFuture.
413 * @param future a CompletableFuture on which the dependency will wait for
414 * @param consumer the builder used to build the dependency
415 * @return this builder.
416 */
417 <U> B withFuture(CompletableFuture<U> future, Consumer<FutureDependencyBuilder<U>> consumer);
418
419 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000420 * Sets the instance to invoke with the reflection based lifecycle callbacks. By default, reflection based
421 * lifecycle callbacks (init/start/stop/destroy) methods are invoked on the component implementation instance(s).
422 * But you can set a specific callback instance using this method.
423 * <p>
424 * Specifying an instance means you can create a manager
425 * that will be invoked whenever the life cycle of a component changes and this manager
426 * can then decide how to expose this life cycle to the actual component, offering an
427 * important indirection when developing your own component models.
428 *
429 * @see #init(String)
430 * @see #start(String)
431 * @see #stop(String)
432 * @see #destroy(String)
433 * @param lifecycleCallbackInstance the instance the lifecycle callback will be invoked on.
434 * @return this builder.
435 */
436 B lifecycleCallbackInstance(Object lifecycleCallbackInstance);
437
438 /**
Pierre De Ropfaca2892016-01-31 23:27:05 +0000439 * Sets the name of the method used as the "init" callback. This method, when found, is
440 * invoked as part of the life cycle management of the component implementation.
441 * This method is useful because when it is invoked, all required dependencies defines in the Activator
442 * are already injected, and you can then add more extra dependencies from the init() method.
443 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
Pierre De Rop57ffa3f2016-02-19 12:54:30 +0000444 * <p>The dependency manager will look for a method of this name with the following signatures,
Pierre De Ropfaca2892016-01-31 23:27:05 +0000445 * in this order:
446 * <ol>
447 * <li>method(Component component)</li>
448 * <li>method()</li>
449 * </ol>
450 *
451 * @param callback the callback name
452 * @return this builder.
453 */
454 B init(String callback);
455
456 /**
457 * Sets the name of the method used as the "start" callback. This method, when found, is
Pierre De Rop57ffa3f2016-02-19 12:54:30 +0000458 * invoked as part of the life cycle management of the component implementation. <p>The
Pierre De Ropfaca2892016-01-31 23:27:05 +0000459 * dependency manager will look for a method of this name with the following signatures,
460 * in this order:
461 * <ol>
462 * <li>method(Component component)</li>
463 * <li>method()</li>
464 * </ol>
465 *
466 * @param callback the callback name
467 * @return this builder.
468 */
469 B start(String callback);
470
471 /**
472 * Sets the name of the method used as the "stop" callback. This method, when found, is
Pierre De Rop57ffa3f2016-02-19 12:54:30 +0000473 * invoked as part of the life cycle management of the component implementation. <p>The
Pierre De Ropfaca2892016-01-31 23:27:05 +0000474 * dependency manager will look for a method of this name with the following signatures,
475 * in this order:
476 * <ol>
477 * <li>method(Component component)</li>
478 * <li>method()</li>
479 * </ol>
480 *
481 * @param callback the callback name
482 * @return this builder.
483 */
484 B stop(String callback);
485
486 /**
487 * Sets the name of the method used as the "destroy" callback. This method, when found, is
Pierre De Rop57ffa3f2016-02-19 12:54:30 +0000488 * invoked as part of the life cycle management of the component implementation. <p>The
Pierre De Ropfaca2892016-01-31 23:27:05 +0000489 * dependency manager will look for a method of this name with the following signatures,
490 * in this order:
491 * <ol>
492 * <li>method(Component component)</li>
493 * <li>method()</li>
494 * </ol>
495 *
496 * @param callback the callback name
497 * @return this builder.
498 */
499 B destroy(String callback);
Pierre De Rop11527502016-02-18 21:07:16 +0000500
Pierre De Ropfaca2892016-01-31 23:27:05 +0000501 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000502 * Sets a reference to a component implementation class "init" callback method.
503 * This method does not take any arguments and is
504 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000505 * This method is useful because when it is invoked, all required dependencies defines in the Activator
506 * are already injected, and you can then add more extra dependencies from the init() method.
507 * 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 +0000508 *
Pierre De Rop11527502016-02-18 21:07:16 +0000509 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000510 * @param callback a method reference must point to method from the component implementation class(es).
Pierre De Ropfaca2892016-01-31 23:27:05 +0000511 * @return this builder
512 */
Pierre De Rop11527502016-02-18 21:07:16 +0000513 <T> B init(Cb<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000514
515 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000516 * Sets a reference to a component implementation class "start" callback method.
517 * This method does not take any arguments and is
518 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000519 *
Pierre De Rop11527502016-02-18 21:07:16 +0000520 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000521 * @param callback a method reference must point to method from one of the component implementation classes.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000522 * @return this builder.
523 */
Pierre De Rop11527502016-02-18 21:07:16 +0000524 <T> B start(Cb<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000525
526 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000527 * Sets a reference to a component implementation class "stop" callback method.
528 * This method does not take any arguments and is
529 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000530 *
Pierre De Rop11527502016-02-18 21:07:16 +0000531 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000532 * @param callback a method reference must point to method from one of the component implementation classes.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000533 * @return this builder.
534 */
Pierre De Rop11527502016-02-18 21:07:16 +0000535 <T> B stop(Cb<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000536
537 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000538 * Sets a reference to a component implementation class "destroy" callback method.
539 * This method does not take any arguments and is
540 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000541 *
Pierre De Rop11527502016-02-18 21:07:16 +0000542 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000543 * @param callback a method reference must point to method from one of the component implementation classes.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000544 * @return this builder.
545 */
Pierre De Rop11527502016-02-18 21:07:16 +0000546 <T> B destroy(Cb<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000547
548 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000549 * Sets a reference to a component implementation class "init" callback method.
550 * This method takes a Component argument and is
551 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000552 * This method is useful because when it is invoked, all required dependencies defines in the Activator
553 * are already injected, and you can then add more extra dependencies from the init() method.
554 * 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 +0000555 *
Pierre De Rop11527502016-02-18 21:07:16 +0000556 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000557 * @param callback a method reference must point to method from one of the component implementation classes. The method takes as argument a Component parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000558 * @return this builder
559 */
Pierre De Rop11527502016-02-18 21:07:16 +0000560 <T> B init(CbComponent<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000561
562 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000563 * Sets a reference to a component implementation class "start" callback method.
564 * This method takes a Component argument and is
565 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000566 *
Pierre De Rop11527502016-02-18 21:07:16 +0000567 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000568 * @param callback a method reference must point to method from one of the component implementation classes. The method takes as argument a Component parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000569 * @return this builder.
570 */
Pierre De Rop11527502016-02-18 21:07:16 +0000571 <T> B start(CbComponent<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000572
573 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000574 * Sets a reference to a component implementation class "stop" callback method.
575 * This method takes a Component argument and is
576 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000577 *
Pierre De Rop11527502016-02-18 21:07:16 +0000578 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000579 * @param callback a method reference must point to method from one of the component implementation classes. The method takes as argument a Component parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000580 * @return this builder.
581 */
Pierre De Rop11527502016-02-18 21:07:16 +0000582 <T> B stop(CbComponent<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000583
584 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000585 * Sets a reference to a component implementation class "destroy" callback method.
586 * This method takes a Component argument and is
587 * invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000588 *
Pierre De Rop11527502016-02-18 21:07:16 +0000589 * @param <T> the type of the component class on which the callback is invoked on.
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000590 * @param callback a method reference must point to method from one of the component implementation classes. The method takes as argument a Component parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000591 * @return this builder.
592 */
Pierre De Rop11527502016-02-18 21:07:16 +0000593 <T> B destroy(CbComponent<T> callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000594
595 /**
596 * Sets an Object instance method reference used as the "init" callback. It is invoked as part of the life cycle management of the component
597 * implementation.
598 * This method is useful because when it is invoked, all required dependencies defines in the Activator
599 * are already injected, and you can then add more extra dependencies from the init() method.
600 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
601 * The method does not take any parameters.
602 *
603 * @param callback an Object instance method reference. The method does not take any parameters.
604 * @return this builder
605 */
Pierre De Rop11527502016-02-18 21:07:16 +0000606 B initInstance(InstanceCb callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000607
608 /**
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000609 * Sets an Object instance method reference used as the "start" callback.
610 * This method is invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000611 * The method does not take any parameters.
612 *
613 * @param callback an Object instance method reference. The method does not take any parameters.
614 * @return this builder.
615 */
Pierre De Rop11527502016-02-18 21:07:16 +0000616 B startInstance(InstanceCb callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000617
618 /**
619 * Sets an Object instance method reference used as the "stop" callback. It is invoked as part of the life cycle management of the component
620 * implementation.
621 * This method is useful because when it is invoked, all required dependencies defines in the Activator
622 * are already injected, and you can then add more extra dependencies from the init() method.
623 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
624 * The method does not take any parameters.
625 *
626 * @param callback an Object instance method reference. The method does not take any parameters.
627 * @return this builder
628 */
Pierre De Rop11527502016-02-18 21:07:16 +0000629 B stopInstance(InstanceCb callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000630
631 /**
632 * Sets an Object instance method reference used as the "destroy" callback. It is invoked as part of the life cycle management of the component
633 * implementation.
634 * This method is useful because when it is invoked, all required dependencies defines in the Activator
635 * are already injected, and you can then add more extra dependencies from the init() method.
636 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
637 * The method does not take any parameters.
638 *
639 * @param callback an Object instance method reference. The method does not take any parameters.
640 * @return this builder
641 */
Pierre De Rop11527502016-02-18 21:07:16 +0000642 B destroyInstance(InstanceCb callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000643
644 /**
645 * Sets an Object instance method reference used as the "init" callback. It is invoked as part of the life cycle management of the component
646 * implementation.
647 * This method is useful because when it is invoked, all required dependencies defines in the Activator
648 * are already injected, and you can then add more extra dependencies from the init() method.
649 * And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
650 * The method takes as argument a Component parameter.
651 *
Pierre De Rop11527502016-02-18 21:07:16 +0000652 * @param callback an Object instance method reference. The method takes as argument a Component parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000653 * @return this builder
654 */
Pierre De Rop11527502016-02-18 21:07:16 +0000655 B initInstance(InstanceCbComponent callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000656
657 /**
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000658 * Sets an Object instance method reference used as the "start" callback.
659 * This method is invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000660 * The method takes as argument a Component parameter.
661 *
662 * @param callback an Object instance method reference. The method takes as argument a Component parameter.
663 * @return this builder.
664 */
Pierre De Rop11527502016-02-18 21:07:16 +0000665 B startInstance(InstanceCbComponent callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000666
667 /**
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000668 * Sets an Object instance method reference used as the "stop" callback.
669 * This method is invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000670 * The method takes as argument a Component parameter.
671 *
672 * @param callback an Object instance method reference. The method takes as argument a Component parameter.
673 * @return this builder.
674 */
Pierre De Rop11527502016-02-18 21:07:16 +0000675 B stopInstance(InstanceCbComponent callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000676
677 /**
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000678 * Sets an Object instance method reference used as the "destroy" callback.
679 * This method is invoked as part of the life cycle management of the component implementation.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000680 * The method takes as argument a Component parameter.
681 *
682 * @param callback an Object instance method reference. The method takes as argument a Component parameter.
683 * @return this builder.
684 */
Pierre De Rop11527502016-02-18 21:07:16 +0000685 B destroyInstance(InstanceCbComponent callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000686
687 /**
688 * Configures OSGi object (BundleContext, Component, etc ...) that will be injected in any field having the same OSGi object type.
689 * @param clazz the OSGi object type (BundleContext, Component, DependencyManager).
690 * @param autoConfig true if the OSGi object has to be injected, false if not
691 * @return this builder
692 */
693 B autoConfig(Class<?> clazz, boolean autoConfig);
694
695 /**
696 * Configures OSGi object (BundleContext, Component, etc ...) that will be injected in a given field.
697 * @param clazz the OSGi object type (BundleContext, Component, DependencyManager).
698 * @param field the field that will be injected with the OSGI object
699 * @return this builder
700 */
701 B autoConfig(Class<?> clazz, String field);
702
703 /**
704 * Activates debug mode
705 * @param label the debug label
706 * @return this builder
707 */
708 B debug(String label);
709
710 /**
711 * Automatically adds this component to its DependencyManager object. When a lambda builds a Component using this builder, by default
712 * the built component is auto added to its DependencyManager object, unless you invoke autoAdd(false).
713 *
714 * @param autoAdd true for automatically adding this component to the DependencyManager object, false if not
715 * @return this builder
716 */
717 B autoAdd(boolean autoAdd);
718
719 /**
720 * Sets the method to invoke on the service implementation to get back all
721 * instances that are part of a composition and need dependencies injected.
Pierre De Rop11527502016-02-18 21:07:16 +0000722 * All of them will be searched to inject any of the dependencies. The method that
Pierre De Ropfaca2892016-01-31 23:27:05 +0000723 * is invoked must return an <code>Object[]</code>.
724 *
725 * @param getCompositionMethod the method to invoke
726 * @return this builder
727 */
728 B composition(String getCompositionMethod);
729
730 /**
731 * Sets the instance and method to invoke to get back all instances that
732 * are part of a composition and need dependencies injected. All of them
Pierre De Rop11527502016-02-18 21:07:16 +0000733 * will be searched to inject any of the dependencies. The method that is
Pierre De Ropfaca2892016-01-31 23:27:05 +0000734 * invoked must return an <code>Object[]</code>.
735 *
736 * @param instance the instance that has the method
737 * @param getCompositionMethod the method to invoke
738 * @return this builder
739 */
740 B composition(Object instance, String getCompositionMethod);
741
742 /**
743 * Sets a java8 method reference to a Supplier that returns all instances that are part of a composition and need dependencies injected.
744 * All of them will be searched for any of the dependencies. The method that
745 * is invoked must return an <code>Object[]</code>.
746 *
747 * @param getCompositionMethod the method to invoke
748 * @return this builder
749 */
750 B composition(Supplier<Object[]> getCompositionMethod);
Pierre De Rop6e8f9212016-02-20 21:44:59 +0000751
Pierre De Ropfaca2892016-01-31 23:27:05 +0000752 /**
753 * Builds the real DependencyManager Component.
754 * @return the real DependencyManager Component.
755 */
756 Component build();
757}