blob: 89aba9052e9bfb9e27ceb693668cb8eb3f5c3fcf [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 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 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 CbService<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 service the callback argument.
Pierre De Ropfaca2892016-01-31 23:27:05 +000017 */
Pierre De Rop11527502016-02-18 21:07:16 +000018 void accept(T instance, S service);
Pierre De Ropfaca2892016-01-31 23:27:05 +000019
Pierre De Rop11527502016-02-18 21:07:16 +000020 default CbFuture<T, S> andThen(CbFuture<? super T, S> after) {
Pierre De Ropfaca2892016-01-31 23:27:05 +000021 Objects.requireNonNull(after);
Pierre De Rop11527502016-02-18 21:07:16 +000022 return (T instance, S service) -> {
23 accept(instance, service);
24 after.accept(instance, service);
Pierre De Ropfaca2892016-01-31 23:27:05 +000025 };
26 }
27}