public class InvocationTee
extends java.lang.Object
Constructor and Description |
---|
InvocationTee() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
tee(java.lang.Class<? super T> teeInterface,
T... instances)
This creates a tee proxy for a given class with a set of instances of said interface.
|
static <T> T |
teeWithExceptionThrowing(java.lang.Class<? super T> teeInterface,
T... instances)
This implementation is variation from
tee(Class, Object...) , read that documentation
first. |
static <T> T |
teeWithExecutor(java.util.concurrent.Executor executor,
java.lang.Class<? super T> teeInterface,
T... instances)
This implementation is variation from
tee(Class, Object...) , read that documentation
first. |
public static <T> T tee(java.lang.Class<? super T> teeInterface, T... instances)
If any listeners throw an exception it will be delegated to
ExceptionUtils.handleException(Throwable)
. So a listener throwing
an exception will NOT interrupt other listeners from being invoked. If you want you can
handle thrown exceptions by setting an ExceptionHandler
into
ExceptionUtils
. Make sure the handler is set it in a way that makes
sense based off what thread will be invoking the returned interface.
Under the hood this depends on ListenerHelper
, and thus has the same limitations.
Most specifically the provided teeInterface
must in fact be an interface, and not a
an abstract class, or other non-interface types. In addition any invocations called to this
must be a void
return type.
T
- Type representing interface to multiple invocations ofteeInterface
- Interface class for which the returned instance must implementinstances
- Instances of said interface which invocations should be multiplied topublic static <T> T teeWithExceptionThrowing(java.lang.Class<? super T> teeInterface, T... instances)
tee(Class, Object...)
, read that documentation
first.
The behavior modifies from that implementation is in how exceptions are handled. Rather than handling them and ensuring that all instances are invoked, this will throw the exception. More specifically when an instance throws an exception it will prevent further instances from bring invoked, and that exception will bubble up to the original interface invoker.
T
- Type representing interface to multiple invocations ofteeInterface
- Interface class for which the returned instance must implementinstances
- Instances of said interface which invocations should be multiplied topublic static <T> T teeWithExecutor(java.util.concurrent.Executor executor, java.lang.Class<? super T> teeInterface, T... instances)
tee(Class, Object...)
, read that documentation
first.
The behavior modifies from that implementation is that all instances will be called by a executor. This means that invocations into the returned instance will return immediately, but instance invocation will happen async. It is guaranteed that any single instance will NOT be invoked in parallel. Thus meaning that if you invoke into the proxy two times before a give instance finishes processing the first invocation, the second invocation will queue and only be invoked after the first finishes.
Under the hood DefaultExecutorListenerHelper
is used to provide this behavior.
T
- Type representing interface to multiple invocations ofexecutor
- Executor that instances will be invoked on toteeInterface
- Interface class for which the returned instance must implementinstances
- Instances of said interface which invocations should be multiplied to