Pierre De Rop | faca289 | 2016-01-31 23:27:05 +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(ServiceReference, Service, ServiceReference, Service) that is invoked on a Component implementation class. |
| 9 | * The type of the class on which the callback is invoked on is represented by the T generic parameter. |
| 10 | * |
| 11 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 12 | */ |
| 13 | @FunctionalInterface |
| 14 | public interface CbTypeRefServiceRefService<T, S> extends SerializableLambda { |
| 15 | /** |
| 16 | * Handles the given arguments. |
| 17 | * @param instance the Component implementation instance on which the callback is invoked on. |
| 18 | * @param oldRef first callback param |
| 19 | * @param old second callback param |
| 20 | * @param replaceRef third callback param |
| 21 | * @param replace fourth callback param |
| 22 | */ |
| 23 | void accept(T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace); |
| 24 | |
| 25 | default CbTypeRefServiceRefService<T, S> andThen(CbTypeRefServiceRefService<? super T, S> after) { |
| 26 | Objects.requireNonNull(after); |
| 27 | return (T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> { |
| 28 | accept(instance, oldRef, old, replaceRef, replace); |
| 29 | after.accept(instance, oldRef, old, replaceRef, replace); |
| 30 | }; |
| 31 | } |
| 32 | } |