/** * Start a call to a single callback instance, dealing with common generic type * concerns and exceptions. * @param callbackType the callback type (a {@link FunctionalInterface functional * interface}) * @param callbackInstance the callback instance (may be a lambda) * @param argument the primary argument passed to the callback * @param additionalArguments any additional arguments passed to the callback * @param <C> the callback type * @param <A> the primary argument type * @return a {@link Callback} instance that can be invoked. */ public static <C, A> Callback<C, A> callback(Class<C> callbackType, C callbackInstance, A argument, Object... additionalArguments) { Assert.notNull(callbackType, "CallbackType must not be null"); Assert.notNull(callbackInstance, "CallbackInstance must not be null"); return new Callback<>(callbackType, callbackInstance, argument, additionalArguments); }
/** * Invoke the callback instance where the callback method returns void. * @param invoker the invoker used to invoke the callback */ public void invoke(Consumer<C> invoker) { invoke(this.callbackInstance, () -> { invoker.accept(this.callbackInstance); return null; }); }
@SuppressWarnings("unchecked") private boolean isFilterMatch(EndpointFilter<E> filter, E endpoint) { return LambdaSafe.callback(EndpointFilter.class, filter, endpoint) .withLogger(EndpointDiscoverer.class).invokeAnd((f) -> f.match(endpoint)) .get(); }
/** * Invoke the callback instance where the callback method returns a result. * @param invoker the invoker used to invoke the callback * @param <R> the result type * @return the result of the invocation (may be {@link InvocationResult#noResult} * if the callback was not invoked) */ public <R> InvocationResult<R> invokeAnd(Function<C, R> invoker) { return invoke(this.callbackInstance, () -> invoker.apply(this.callbackInstance)); }