- java.lang.Object
-
- com.aoapps.concurrent.ConcurrentListenerManager<L>
-
- All Implemented Interfaces:
AutoCloseable
public class ConcurrentListenerManager<L> extends Object implements AutoCloseable
Provides per-listener event queues, and fires off events concurrently across listeners, but in-order per listener.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceConcurrentListenerManager.Event<L>The event callback.
-
Constructor Summary
Constructors Constructor Description ConcurrentListenerManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(L listener, boolean synchronous)Adds a listener.voidclose()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.booleanremoveListener(L listener)Removes a listener.
-
-
-
Method Detail
-
close
public void close()
When no longer needed, close should be called to free resources.- Specified by:
closein interfaceAutoCloseable
-
addListener
public void addListener(L listener, boolean synchronous) throws IllegalStateException
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
public boolean removeListener(L listener)
Removes a listener.- Returns:
- true if the listener was found
-
enqueueEvent
public Future<?> enqueueEvent(ConcurrentListenerManager.Event<? super L> event)
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.
-
-