|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread de.fhg.igd.event.AsyncListener
public class AsyncListener
Listens on notifier objects. The received events are sent to the listener specified in the constructors. This listener is trusted with respect to thread blocking. This class defines methods for pushing objects in a queue which is read by this thread. If the target listener engages in an infinite loop, it may only harm itself but delivery of notification to other listeners is unaffected.
In other words, calls to notifiedOf
return immediately. The target of instances of this class
are notified by the listener thread.
A maximum queue length can be specified by means of a highwater mark. If the highwater mark is reached then older events are discarded in favour of newer ones.
There are two ways to stop the asynchronous listener
null
event.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
Thread.State, Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
private int |
highwater_
The maximum number of events being buffered before events are silently discarded. |
private Listener |
listener_
The actual listener which is notified of events in the standard implementation. |
private LinkedList |
queue_
The FIFO buffer used to queue events. |
private boolean |
running_
A flag that signals whether this listener is already running. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
AsyncListener(Listener o)
Creates a notifier slave. |
|
AsyncListener(Listener o,
int highwater)
Creates a notifier slave with the highwater mark given as argument. |
|
AsyncListener(String name,
Listener o)
Creates a listener with the given name and target. |
|
AsyncListener(ThreadGroup parent,
Listener o)
Creates a AsyncListener in the given thread group and given target listener. |
|
AsyncListener(ThreadGroup parent,
String name,
Listener o)
Creates a AsyncListener in the given thread group with the given name and given target listener. |
Method Summary | |
---|---|
boolean |
isEmpty()
Checks whether the event queue is empty. |
boolean |
isRunning()
This method returns true iff the
trusted listener is running. |
void |
notifiedOf(Object o)
This method pushes the received object into the queue. |
protected Object |
pull()
Pulls an object from the queue and returns it. |
protected void |
push(Object o)
Pushes an object into the event queue and notifies any thread waiting on a change of the queue. |
void |
run()
Runs the notifier thread which handles asynchronous notification of the listeners. |
void |
setHighwater(int highwater)
Sets the highwater mark. |
void |
trim(int size)
Trims the event queue down to the given size. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private volatile boolean running_
private LinkedList queue_
private int highwater_
private Listener listener_
Constructor Detail |
---|
public AsyncListener(ThreadGroup parent, Listener o)
parent
- The thread group in which this thread
shall be placed.o
- The listener which is notified of updates.
NullPointerException
- iff the given
listener is null
.public AsyncListener(ThreadGroup parent, String name, Listener o)
parent
- The thread group in which this thread
shall be placed.name
- The name of the thread.o
- The listener which is notified of updates.
NullPointerException
- iff the given
listener is null
.public AsyncListener(Listener o)
o
- The listener to notify of updates.
NullPointerException
- iff the given
listener is null
.public AsyncListener(String name, Listener o)
o
- The listener to notify of updates.
NullPointerException
- iff the given
listener is null
.public AsyncListener(Listener o, int highwater)
highwater
- The highwatermark. If it is zero
then no upper limit exists on the size of the event queue.o
- The listener to notify of updates
NullPointerException
- iff the given
listener is null
.
IllegalArgumentException
- if the given highwater
mark is negative.Method Detail |
---|
public final void setHighwater(int highwater) throws IllegalArgumentException
highwater
- The highwater mark.
IllegalArgumentException
- if the given highwater
mark is negative.public final void trim(int size)
size
- The size to which the queue is trimmed.protected void push(Object o)
event
- The object to be inserted.protected Object pull() throws InterruptedException
NoSuchElementException
- if no object is enqueued
and the wait
was interrupted.
InterruptedException
public final boolean isEmpty()
true
iff the queue is empty.public final void run()
null
is received from the
queue or the thread is interrupted.
run
in interface Runnable
run
in class Thread
public void notifiedOf(Object o)
null
object terminates
the listener thread.
notifiedOf
in interface Listener
sender
- The origin of the update message.o
- The object which is sent.public boolean isRunning()
true
iff the
trusted listener is running.
true
if running,
false
if not.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |