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 swap callback(ServiceReference, Service, ServiceReference, Service) on an Object instance. |
| 9 | * |
| 10 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 11 | */ |
| 12 | @FunctionalInterface |
| 13 | public interface InstanceCbRefServiceRefService<S> { |
| 14 | /** |
| 15 | * Handles the given arguments |
| 16 | * @param oldRef the old service reference |
| 17 | * @param old the old service |
| 18 | * @param replaceRef the replace service reference |
| 19 | * @param replace the replace service |
| 20 | */ |
| 21 | void accept(ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace); |
| 22 | |
| 23 | default InstanceCbRefServiceRefService<S> andThen(InstanceCbRefServiceRefService<S> after) { |
| 24 | Objects.requireNonNull(after); |
| 25 | return (ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> { |
| 26 | accept(oldRef, old, replaceRef, replace); |
| 27 | after.accept(oldRef, old, replaceRef, replace); |
| 28 | }; |
| 29 | } |
| 30 | } |