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.osgi.framework.ServiceReference; |
| 6 | |
| 7 | /** |
| 8 | * Represents a callback(Service, ServiceReference) on an Object instance. |
| 9 | * |
| 10 | * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter. |
| 11 | * |
| 12 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 13 | */ |
| 14 | @FunctionalInterface |
| 15 | public interface InstanceCbServiceRef<S> { |
| 16 | /** |
| 17 | * Handles the given arguments. |
| 18 | * @param ref a Service Reference |
| 19 | * @param service a Service |
| 20 | */ |
| 21 | void accept(S service, ServiceReference<S> ref); |
| 22 | |
| 23 | default InstanceCbServiceRef<S> andThen(InstanceCbServiceRef<S> after) { |
| 24 | Objects.requireNonNull(after); |
| 25 | return (S service, ServiceReference<S> ref) -> { |
| 26 | accept(service, ref); |
| 27 | after.accept(service, ref); |
| 28 | }; |
| 29 | } |
| 30 | } |