Class InvocationTee


  • public class InvocationTee
    extends java.lang.Object
    Simple utility for multiplying invocations across multiple instances of a given interface.
    Since:
    4.3.0
    • Constructor Summary

      Constructors 
      Constructor Description
      InvocationTee()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InvocationTee

        public InvocationTee()
    • Method Detail

      • tee

        public 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. Any invocation to the returned instance (proxy), will be multiple to all provided instances. If provided arguments are mutable, and an instance mutates that argument, future invoked instances may see that modification. It is not deterministic which order the instances will be invoked in.

        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.

        Type Parameters:
        T - Type representing interface to multiple invocations of
        Parameters:
        teeInterface - Interface class for which the returned instance must implement
        instances - Instances of said interface which invocations should be multiplied to
        Returns:
        A returned interface which will map all invocations to all provided interfaces
      • teeWithExceptionThrowing

        public static <T> T teeWithExceptionThrowing​(java.lang.Class<? super T> teeInterface,
                                                     T... instances)
        This implementation is variation from 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.

        Type Parameters:
        T - Type representing interface to multiple invocations of
        Parameters:
        teeInterface - Interface class for which the returned instance must implement
        instances - Instances of said interface which invocations should be multiplied to
        Returns:
        A returned interface which will map all invocations to all provided interfaces
      • teeWithExecutor

        public 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.

        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.

        Type Parameters:
        T - Type representing interface to multiple invocations of
        Parameters:
        executor - Executor that instances will be invoked on to
        teeInterface - Interface class for which the returned instance must implement
        instances - Instances of said interface which invocations should be multiplied to
        Returns:
        A returned interface which will map all invocations to all provided interfaces