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 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 6 | * Represents a callback(Service) that is invoked on a Component implementation class. |
| 7 | * The type of the class on which the callback is invoked on is represented by the T generic parameter. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 8 | * |
| 9 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 10 | */ |
| 11 | @FunctionalInterface |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 12 | public interface CbService<T, S> extends SerializableLambda { |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 13 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 14 | * Handles the given arguments. |
| 15 | * @param instance the Component implementation instance on which the callback is invoked on. |
| 16 | * @param service the callback argument. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 17 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 18 | void accept(T instance, S service); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 19 | |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 20 | default CbFuture<T, S> andThen(CbFuture<? super T, S> after) { |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 21 | Objects.requireNonNull(after); |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 22 | return (T instance, S service) -> { |
| 23 | accept(instance, service); |
| 24 | after.accept(instance, service); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 25 | }; |
| 26 | } |
| 27 | } |