ie.omk.smpp.event
Class SimpleEventDispatcher

java.lang.Object
  extended by ie.omk.smpp.event.SimpleEventDispatcher
All Implemented Interfaces:
EventDispatcher

public class SimpleEventDispatcher
extends Object
implements EventDispatcher

A simple implementation of the event dispatcher interface. This implementation simply iterates over the set of registered observers and notifies each of the event in turn. This means that whatever thread the Connection object uses to call into this object will be blocked, from the Connection's point of view, until every observer has successfully processed the event.

Adding and removing observers from an instance of this class is protected against multi-threaded access. However, event and packet notification is not. If an event notification is currently in progress and another thread modifies the set of registered observers, then it is possible for the new observer to receive events before the call to addObserver is complete.

Version:
$Id: SimpleEventDispatcher.java 293 2006-03-14 13:54:28Z orank $
Author:
Oran Kelly
See Also:
EventDispatcher

Field Summary
static int INCREMENT
          Size of array increments.
 
Constructor Summary
SimpleEventDispatcher()
          Create a new SimpleEventDispatcher.
SimpleEventDispatcher(ConnectionObserver ob)
          Create a new SimpleEventDispatcher and register one observer on it.
 
Method Summary
 void addObserver(ConnectionObserver ob)
          Add a connection observer to receive SMPP events.
 int capacity()
           
 boolean contains(ConnectionObserver ob)
          Determine if this dispatcher has a particular observer registered for events.
 void destroy()
          Event dispatcher clean up.
 void init()
          Initialise the event dispatcher.
 void notifyObservers(Connection conn, SMPPEvent event)
          Notify registered observers of an SMPP event.
 void notifyObservers(Connection conn, SMPPPacket packet)
          Notify registered observers of an incoming SMPP packet.
 Iterator observerIterator()
          Get an iterator to iterate over the set of observers registered with this event dispatcher.
 void removeObserver(ConnectionObserver ob)
          Remove a connection observer.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCREMENT

public static final int INCREMENT
Size of array increments.

See Also:
Constant Field Values
Constructor Detail

SimpleEventDispatcher

public SimpleEventDispatcher()
Create a new SimpleEventDispatcher.


SimpleEventDispatcher

public SimpleEventDispatcher(ConnectionObserver ob)
Create a new SimpleEventDispatcher and register one observer on it.

Method Detail

init

public void init()
Description copied from interface: EventDispatcher
Initialise the event dispatcher. The init method will be called by the Connection before it makes any attempt to add any observers or deliver any events via the dispatcher.

Specified by:
init in interface EventDispatcher

destroy

public void destroy()
Description copied from interface: EventDispatcher
Event dispatcher clean up. The destroy method will be called by the Connection when it is finished delivering events to it and the receiver daemon thread is exiting. Any initialising done in the init method can be cleaned up here.

The destroy method must not interfere with the delivery of any events notified to the event dispatcher before the call to this method.

Specified by:
destroy in interface EventDispatcher

addObserver

public void addObserver(ConnectionObserver ob)
Add a connection observer to receive SMPP events. An observer cannot be added twice. Attempting to do so has no effect.

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

removeObserver

public void removeObserver(ConnectionObserver ob)
Remove a connection observer. If the observer was not previously added, the method has no effect.

Specified by:
removeObserver in interface EventDispatcher
Parameters:
ob - The ConnectionObserver object to remove.

observerIterator

public Iterator observerIterator()
Get an iterator to iterate over the set of observers registered with this event dispatcher.

Specified by:
observerIterator in interface EventDispatcher
Returns:
an iterator which iterates the observers registered with this event dispatcher.

contains

public boolean contains(ConnectionObserver ob)
Determine if this dispatcher has a particular observer registered for events.

Parameters:
ob - The ConnectionObserver to check the presence of.
Returns:
true if the observer is registered with this dispatcher, false otherwise.

notifyObservers

public void notifyObservers(Connection conn,
                            SMPPEvent event)
Notify registered observers of an SMPP event.

Specified by:
notifyObservers in interface EventDispatcher
Parameters:
conn - the Connection with which the event is associated.
event - the SMPP event to notify observers of.

notifyObservers

public void notifyObservers(Connection conn,
                            SMPPPacket packet)
Notify registered observers of an incoming SMPP packet.

Specified by:
notifyObservers in interface EventDispatcher
Parameters:
conn - the Connection which the packet was received on.
packet - the received packet to notify observers of.

capacity

public int capacity()

size

public int size()


Copyright © 2011 smppapi at Sourceforge. All Rights Reserved.