Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 1 | package org.apache.felix.dm.lambda.callbacks; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | |
| 5 | import org.apache.felix.dm.Component; |
| 6 | import org.osgi.framework.ServiceReference; |
| 7 | |
| 8 | /** |
| 9 | * Represents a callback(Service, Component, ServiceReference) that is invoked on a Component implementation class. |
| 10 | * The type of the class on which the callback is invoked on is represented by the T generic parameter. |
| 11 | * |
| 12 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 13 | */ |
| 14 | @FunctionalInterface |
| 15 | public interface CbServiceComponentRef<T, S> extends SerializableLambda { |
| 16 | /** |
| 17 | * Handles the given arguments. |
| 18 | * @param instance the Component implementation instance on which the callback is invoked on. |
| 19 | * @param service the first callback parameter |
| 20 | * @param c the second callback parameter |
| 21 | * @param ref the third callback parameter |
| 22 | */ |
| 23 | void accept(T instance, S service, Component c, ServiceReference<S> ref); |
| 24 | |
| 25 | default CbServiceComponentRef<T, S> andThen(CbServiceComponentRef<T, S> after) { |
| 26 | Objects.requireNonNull(after); |
| 27 | return (T instance, S service, Component c, ServiceReference<S> ref) -> { |
| 28 | accept(instance, service, c, ref); |
| 29 | after.accept(instance, service, c, ref); |
| 30 | }; |
| 31 | } |
| 32 | } |