blob: 91d2ab0f1dd578587bb356bd88377b970333c623 [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001package org.apache.felix.dm.lambda.callbacks;
2
3import java.util.Objects;
4
5/**
Pierre De Rop11527502016-02-18 21:07:16 +00006 * Represents a swap callback(Service, 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 Ropfaca2892016-01-31 23:27:05 +00008 *
9 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
10 */
11@FunctionalInterface
Pierre De Rop11527502016-02-18 21:07:16 +000012public interface CbServiceService<T, S> extends SerializableLambda {
Pierre De Ropfaca2892016-01-31 23:27:05 +000013 /**
Pierre De Rop11527502016-02-18 21:07:16 +000014 * Handles the given arguments.
15 * @param instance the Component implementation instance on which the callback is invoked on.
16 * @param old first callback arg
17 * @param replace second callback arg
Pierre De Ropfaca2892016-01-31 23:27:05 +000018 */
Pierre De Rop11527502016-02-18 21:07:16 +000019 void accept(T instance, S old, S replace);
Pierre De Ropfaca2892016-01-31 23:27:05 +000020
Pierre De Rop11527502016-02-18 21:07:16 +000021 default CbServiceService<T, S> andThen(CbServiceService<? super T, S> after) {
Pierre De Ropfaca2892016-01-31 23:27:05 +000022 Objects.requireNonNull(after);
Pierre De Rop11527502016-02-18 21:07:16 +000023 return (T instance, S old, S replace) -> {
24 accept(instance, old, replace);
25 after.accept(instance, old, replace);
Pierre De Ropfaca2892016-01-31 23:27:05 +000026 };
27 }
28}