Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 1 | package org.apache.felix.dm.lambda.callbacks; |
| 2 | |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 3 | import java.util.Dictionary; |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 4 | import java.util.Objects; |
| 5 | |
| 6 | import org.apache.felix.dm.Component; |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 7 | import org.apache.felix.dm.lambda.ConfigurationDependencyBuilder; |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 8 | |
| 9 | /** |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 10 | * Represents a callback(Configuration, Component) invoked on an Object instance. |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 11 | * |
| 12 | * <p> The T generic parameter represents the type of the configuration class passed to the callback argument. |
| 13 | * |
Pierre De Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 14 | * <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 Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 18 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 19 | */ |
| 20 | @FunctionalInterface |
| 21 | public 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 Rop | 57ffa3f | 2016-02-19 12:54:30 +0000 | [diff] [blame^] | 27 | void accept(T configType, Component component); |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 28 | |
| 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 | } |