blob: 634f892d88941caabcd81f565595aa7ee699242c [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/**
Pierre De Rop57ffa3f2016-02-19 12:54:30 +000010 * Represents a callback(Configuration, Component) invoked on an Object instance.
Pierre De Rop11527502016-02-18 21:07:16 +000011 *
12 * <p> The T generic parameter represents the type of the configuration class passed to the callback argument.
13 *
Pierre De Rop57ffa3f2016-02-19 12:54:30 +000014 * <p> Using such callback provides a way for creating type-safe configurations from the actual {@link Dictionary} that is
15 * normally injected by Dependency Manager.
16 * For more information about configuration types, please refer to {@link ConfigurationDependencyBuilder}.
17 *
Pierre De Rop11527502016-02-18 21:07:16 +000018 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
19 */
20@FunctionalInterface
21public interface InstanceCbConfigurationComponent<T> extends SerializableLambda {
22 /**
23 * Handles the given arguments
24 * @param instance the Component implementation instance on which the callback is invoked on.
25 * @param component the callback Component
26 */
Pierre De Rop57ffa3f2016-02-19 12:54:30 +000027 void accept(T configType, Component component);
Pierre De Rop11527502016-02-18 21:07:16 +000028
29 default InstanceCbConfigurationComponent<T> andThen(InstanceCbConfigurationComponent<T> after) {
30 Objects.requireNonNull(after);
31 return (T instance, Component component) -> {
32 accept(instance, component);
33 after.accept(instance, component);
34 };
35 }
36}