blob: 98df3ff852c5e3dec85eaeda72ebd2966b9964d8 [file] [log] [blame]
Pierre De Rop11527502016-02-18 21:07:16 +00001package org.apache.felix.dm.lambda.callbacks;
2
Pierre De Rop57ffa3f2016-02-19 12:54:30 +00003import java.util.Dictionary;
Pierre De Rop11527502016-02-18 21:07:16 +00004import java.util.Objects;
5
6import org.apache.felix.dm.Component;
Pierre De Rop57ffa3f2016-02-19 12:54:30 +00007import org.apache.felix.dm.lambda.ConfigurationDependencyBuilder;
Pierre De Rop11527502016-02-18 21:07:16 +00008
9/**
10 * Represents a callback(Configuration, Component) which accepts a configuration type for wrapping properties
Pierre De Rop57ffa3f2016-02-19 12:54:30 +000011 * behind a dynamic proxy interface.
Pierre De Rop11527502016-02-18 21:07:16 +000012 *
13 * <p> The T generic parameter represents the type of the class on which the callback is invoked on.
14 * <p> The U generic parameter represents the type of the configuration class passed to the callback argument.
15 *
Pierre De Rop57ffa3f2016-02-19 12:54:30 +000016 * <p> Using such callback provides a way for creating type-safe configurations from the actual {@link Dictionary} that is
17 * normally injected by Dependency Manager.
18 * For more information about configuration types, please refer to {@link ConfigurationDependencyBuilder}.
19 *
Pierre De Rop11527502016-02-18 21:07:16 +000020 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
21 */
22@FunctionalInterface
23public interface CbConfigurationComponent<T, U> extends SerializableLambda {
24 /**
25 * Handles the given arguments
26 * @param instance the Component implementation instance on which the callback is invoked on.
27 * @param configuration the configuration proxy
28 * @param component the callback Component
29 */
30 void accept(T instance, U configuration, Component component);
31
32 default CbConfigurationComponent<T, U> andThen(CbConfigurationComponent<T, U> after) {
33 Objects.requireNonNull(after);
34 return (T instance, U configuration, Component component) -> {
35 accept(instance, configuration, component);
36 after.accept(instance, configuration, component);
37 };
38 }
39}