java.lang.Object
com.aoapps.concurrent.ConcurrentListenerManager<L>
- All Implemented Interfaces:
AutoCloseable
Provides per-listener event queues, and fires off events concurrently across
listeners, but in-order per listener.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
The event callback. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(L listener, boolean synchronous) Adds a listener.void
close()
When no longer needed, close should be called to free resources.Future
<?> enqueueEvent
(ConcurrentListenerManager.Event<? super L> event) Enqueues a new event to all listener event queues.boolean
removeListener
(L listener) Removes a listener.
-
Constructor Details
-
ConcurrentListenerManager
public ConcurrentListenerManager()
-
-
Method Details
-
close
public void close()When no longer needed, close should be called to free resources.- Specified by:
close
in interfaceAutoCloseable
-
addListener
Adds a listener.- Parameters:
synchronous
- When true, listener will be called synchronously by the I/O thread; when false, listener will be called asynchronously by a separate thread.- Throws:
IllegalStateException
- If the listener has already been added
-
removeListener
Removes a listener.- Returns:
- true if the listener was found
-
enqueueEvent
Enqueues a new event to all listener event queues. If the caller needs to wait until the event has been handled by each of the listeners, then call .get() on the returned Future.
-