ie.omk.smpp.event
Class ThreadedEventDispatcher

java.lang.Object
  extended by ie.omk.smpp.event.ThreadedEventDispatcher
All Implemented Interfaces:
EventDispatcher, Runnable

public class ThreadedEventDispatcher
extends Object
implements EventDispatcher, Runnable

An event dispatcher that does not block the receiver daemon thread.

This class is highly experimental .

This dispatcher class has a pool of dispatcher threads. When an event is delivered to this dispatcher by the receiver thread, it is added to a queue and the method returns immediately. One dispatcher thread is then selected and that thread is responsible for delivering the event to all registered observers. The receiver daemon is then free to continue adding new events to the event queue, which will be processed by a thread in the thread pool.

Version:
$Id: ThreadedEventDispatcher.java 267 2006-03-09 16:37:31Z orank $
Author:
Oran Kelly

Constructor Summary
ThreadedEventDispatcher()
          Create a new threaded event dispatcher object.
 
Method Summary
 void addObserver(ConnectionObserver observer)
          Add an observer to this event dispatcher.
 boolean contains(ConnectionObserver observer)
           
 void destroy()
          Shut down all threads in the thread pool.
 void init()
          Initialise this event dispatcher.
 void notifyObservers(Connection conn, SMPPEvent e)
          Notify all registered observers of an SMPP event.
 void notifyObservers(Connection conn, SMPPPacket pak)
          Notify all registered observers of a received SMPP packet.
 Iterator observerIterator()
          Get an iterator over the currently registered observers.
 void removeObserver(ConnectionObserver observer)
          Remove an observer from this event dispatcher.
 void run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadedEventDispatcher

public ThreadedEventDispatcher()
Create a new threaded event dispatcher object.

Method Detail

init

public void init()
Initialise this event dispatcher. This method will retrieve the size of the thread pool and FIFO queue from the API configuration and initialise both. See APIConfigclass documentation for the appropriate configuration properties to use. If the properties are not found in the configuration, the current defaults are a thread pool size of 3 and a FIFO queue size of 100.

Specified by:
init in interface EventDispatcher

destroy

public void destroy()
Shut down all threads in the thread pool. This method will block until all threads have terminated properly. Applications should be careful not to use one of the thread pool's own threads to call this method as this will cause a runtime exception. How can this method wait for all the pool's threads to die if one of the pool's threads is executing this method?

Specified by:
destroy in interface EventDispatcher

addObserver

public void addObserver(ConnectionObserver observer)
Description copied from interface: EventDispatcher
Add an observer to this event dispatcher.

Specified by:
addObserver in interface EventDispatcher
Parameters:
observer - the observer object to add.

removeObserver

public void removeObserver(ConnectionObserver observer)
Description copied from interface: EventDispatcher
Remove an observer from this event dispatcher.

Specified by:
removeObserver in interface EventDispatcher
Parameters:
observer - the observer object to remove from the registered observers.

observerIterator

public Iterator observerIterator()
Description copied from interface: EventDispatcher
Get an iterator over the currently registered observers.

Specified by:
observerIterator in interface EventDispatcher
Returns:
an iterator object which iterates over all registered observers.

contains

public boolean contains(ConnectionObserver observer)

notifyObservers

public void notifyObservers(Connection conn,
                            SMPPEvent e)
Description copied from interface: EventDispatcher
Notify all registered observers of an SMPP event.

Specified by:
notifyObservers in interface EventDispatcher
e - the SMPP event to notify observers of.

notifyObservers

public void notifyObservers(Connection conn,
                            SMPPPacket pak)
Description copied from interface: EventDispatcher
Notify all registered observers of a received SMPP packet.

Specified by:
notifyObservers in interface EventDispatcher
pak - the SMPP packet to notify observers of.

run

public void run()
Specified by:
run in interface Runnable


Copyright © 2011 smppapi at Sourceforge. All Rights Reserved.