blob: fcf737cc1ca7463b8c0924e98bcbb445c666357a [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001package org.apache.felix.dm.lambda.callbacks;
2
3import java.util.Map;
4import java.util.Objects;
5
6/**
Pierre De Rop11527502016-02-18 21:07:16 +00007 * Represents a callback(Service, Map) that is invoked on a Component implementation class.
8 * The type of the class on which the callback is invoked on is represented by the T generic parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +00009 *
10 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
11 */
12@FunctionalInterface
Pierre De Rop11527502016-02-18 21:07:16 +000013public interface CbServiceMap<T, S> extends SerializableLambda {
Pierre De Ropfaca2892016-01-31 23:27:05 +000014 /**
15 * Handles the given arguments.
Pierre De Rop11527502016-02-18 21:07:16 +000016 * @param instance the Component implementation instance on which the callback is invoked on.
17 * @param service first callback arg
18 * @param properties second callback arg
Pierre De Ropfaca2892016-01-31 23:27:05 +000019 */
Pierre De Rop11527502016-02-18 21:07:16 +000020 void accept(T instance, S service, Map<String, Object> properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +000021
Pierre De Rop11527502016-02-18 21:07:16 +000022 default CbServiceMap<T, S> andThen(CbServiceMap<? super T, S> after) {
Pierre De Ropfaca2892016-01-31 23:27:05 +000023 Objects.requireNonNull(after);
Pierre De Rop11527502016-02-18 21:07:16 +000024 return (T instance, S service, Map<String, Object> properties) -> {
25 accept(instance, service, properties);
26 after.accept(instance, service, properties);
Pierre De Ropfaca2892016-01-31 23:27:05 +000027 };
28 }
29}