|
JSR-043: JTAPI-1.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.telephony.media.provider.Dispatcher
Provides a framework for managing Listeners, and building event queues and dispatch threads.
Dispatcher delivers an DispatchableEvent to a all Listeners. The DispatchableEvent decides which method to invoke on which Listeners.
The Dispatcher handles any Exceptions generated by Event dispatching or by the Listeners.
This Dispatcher is very generic, the actual knowledge of which Listener class and which method to invoke is encapsulated in the Events that implement DispatchableEvent.
This class can be extended by implementing: getNextEvent() and providing whatever constructor or initializers are necessary.
An event can be dispatched from any thread that calls notiftyListeners(). The supplied Thread.run() method calls notifyListeners, but this class must be specialized to supply a getNextEvent() method.
Inner Class Summary | |
static interface |
Dispatcher.DispatchableEvent
Supplies a method to dispatch an object to its Listener. |
static interface |
Dispatcher.ExceptionHandler
Supplies a method to handle Exceptions generated while dispatching. |
Constructor Summary | |
Dispatcher()
|
Method Summary | |
void |
addListener(java.util.EventListener listener)
Add the given listener to the list. |
void |
close()
stop Dispatcher, return to initial state. |
boolean |
isRunning()
|
void |
notifyListeners(Dispatcher.DispatchableEvent event)
Causes the given DispatchableEvent to be delivered to the Listeners that are expecting it. |
static java.lang.String |
objName(java.lang.Object obj)
A utility routine to get short name for an object. |
static void |
printDispatcherException(java.lang.String label,
Dispatcher disp,
java.lang.Exception ex,
java.util.EventListener listener,
Dispatcher.DispatchableEvent event)
Print the Exception and other information |
void |
removeListener(java.util.EventListener listener)
Remove the given listener from the list. |
void |
run()
get a DispatchableEvent and dispatch it to all EventListeners until stop(). |
void |
setExceptionHandler(Dispatcher.ExceptionHandler handler)
Set a Handler for Exception handling. |
void |
start()
|
void |
start(java.lang.Object obj)
|
void |
start(java.lang.String name)
start a Thread for this Dispatcher. |
void |
stop()
Stop the Thread for this Dispatcher. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Dispatcher()
Method Detail |
public void setExceptionHandler(Dispatcher.ExceptionHandler handler)
Therefore, there are two ways to override what happens when there is an Exception during dispatch:
handler
- a Dispatcher.ExceptionHandler or null
to revert to the default behavior: print and stop.public static void printDispatcherException(java.lang.String label, Dispatcher disp, java.lang.Exception ex, java.util.EventListener listener, Dispatcher.DispatchableEvent event)
public void addListener(java.util.EventListener listener)
listener
- an EventListener object.public void removeListener(java.util.EventListener listener)
listener
- an EventListener object.public void notifyListeners(Dispatcher.DispatchableEvent event)
All Listeners are considered, those that implement the Listener interface used by the event are invoked.
This method can be called directly, or if events are being queued, then the Dispatcher Thread's run() method will call then when an event is available from getNextEvent().
public java.lang.String toString()
toString
in class java.lang.Object
public void run()
run
in interface java.lang.Runnable
public boolean isRunning()
public static java.lang.String objName(java.lang.Object obj)
public void start()
public void start(java.lang.Object obj)
public void start(java.lang.String name)
public void stop()
If you need access to the Thread, specialize the class.
public void close()
|
JSR-043: JTAPI-1.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |