blob: 5282f2712053a4bd9d81fb852fde23892f123cd9 [file] [log] [blame]
Pierre De Rop11527502016-02-18 21:07:16 +00001package org.apache.felix.dm.lambda.callbacks;
2
3import java.util.Objects;
4
5import org.osgi.framework.ServiceReference;
6
7/**
8 * Represents a callback(Service, ServiceReference) 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
14public interface CbServiceRef<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 service first callback arg
19 * @param ref second callback arg
20 */
21 void accept(T instance, S service, ServiceReference<S> ref);
22
23 default CbServiceRef<T, S> andThen(CbServiceRef<? super T, S> after) {
24 Objects.requireNonNull(after);
25 return (T instance, S service, ServiceReference<S> ref) -> {
26 accept(instance, service, ref);
27 after.accept(instance, service, ref);
28 };
29 }
30}