public class Notifier<T> extends Object
The semantic is similar as new CountDownLatch(1) but it allows listeners to be added. The listeners can be
any class and they are invoked when the method fireListener() is invoked. Threads invoking await(long, TimeUnit) will be unblocked too.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Notifier.Invoker<T1> |
| Constructor and Description |
|---|
Notifier(Notifier.Invoker<T> invoker)
Constructs a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(T listener)
Adds a listener.
|
boolean |
await(long time,
TimeUnit unit)
Makes the thread waiting until
fireListener() is invoked or the specified waiting time elapses. |
void |
fireListener()
Unblocks all the waiting threads and notifies the listeners.
|
public Notifier(Notifier.Invoker<T> invoker)
invoker - the Notifier.Invoker is invoked with the listener to be
notified.NullPointerException - if invoker is null.public void add(T listener)
If the method fireListener() was already invoked, the listener could be invoked by the invocation thread.
The listener is invoked only once.
listener - the listener to invoke.NullPointerException - if the listener is null.public boolean await(long time,
TimeUnit unit)
throws InterruptedException
fireListener() is invoked or the specified waiting time elapses.time - the maximum time to waitunit - the time unit of the timetrue if another thread invoked fireListener(), false otherwise.InterruptedException - if the current thread is interrupted while waitingNullPointerException - if unit is null.public void fireListener()
Copyright © 2015 JBoss, a division of Red Hat. All rights reserved.