This class changes the behavior of how listeners are called from the parent class
ListenerHelper. In this implementation when listeners are invoked with the
#call() function, the invocation of all the listeners will occur on the
Executor that was provided at construction. If the listener was added without a
provided executor it will then run on the provided executor (in the thread doing the
#call() invocation, AKA it will run that listener before executing other listeners).
If the listener was added with a provided executor, that listener will still execute on the
provided executor (so not necessarily the executor provided at construction time).
If it is desired that all listeners are executed asynchronously from each other, you should
actually use the normal
ListenerHelper, and instead just ensure that an executor is
provided when each listener is added. If you want listeners to execute concurrently from each
other, but not concurrently for any single listener,
DefaultExecutorListenerHelper is
likely a better choice. This class is only designed to ensure that
#call() invocations
will never block.
To better clarify when this implementation makes sense compared to
ListenerHelper and
DefaultExecutorListenerHelper. If you have a LOT of quick running listeners, this is
the right class for you. If you have few listeners that execute quickly, then the normal
ListenerHelper is likely a better choice. If you have long running/complex listeners,
DefaultExecutorListenerHelper is possibly the better choice. Alternative for the last
condition you could use the normal
ListenerHelper, and just ensure that an executor is
provided for every listener (but if you want to ensure a given listener is not executed
concurrently the
DefaultExecutorListenerHelper will handle this for you).
It is important to note that this class does not ensure ordering of how listeners are called.
For example if you provided a multi-threaded executor, and are calling the listeners twice,
those listeners call order is non-deterministic. If this is important to you, you must ensure
that the Executor provided is single threaded (ie by using the
org.threadly.concurrent.wrapper.KeyDistributedExecutor to get an executor from a single
key, or by using the
org.threadly.concurrent.wrapper.limiter.ExecutorLimiter with a
limit of one, or an instance of the
org.threadly.concurrent.SingleThreadScheduler).