/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/event/EventDispatcher.java

http://mobicents.googlecode.com/ · Java · 114 lines · 15 code · 13 blank · 86 comment · 0 complexity · 0532ba682175e39eb76e497a96bb61e6 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.smpp.event;
  23. import java.util.Collection;
  24. import java.util.Iterator;
  25. import org.mobicents.protocols.smpp.Session;
  26. import org.mobicents.protocols.smpp.message.SMPPPacket;
  27. /**
  28. * This interface defines the observable side of the observer pattern for
  29. * asynchronous SMPP event notification. Each {@link com.adenki.smpp.Session}
  30. * object will have an implementation of the <code>EventDispatcher</code>
  31. * interface which it uses to deliver events to interested listeners. By
  32. * removing the actual dispatching of events from the internals of the
  33. * Connection, applications may provide their own event dispatch implementations
  34. * for their <code>Connection</code> objects which better suit how those
  35. * applications work.
  36. *
  37. * @version $Id: EventDispatcher.java 457 2009-01-15 17:37:42Z orank $
  38. * @see com.adenki.smpp.event.SimpleEventDispatcher
  39. */
  40. public interface EventDispatcher {
  41. /**
  42. * Initialise the event dispatcher. The <code>init</code> method will be
  43. * called by the <code>Connection</code> before it makes any attempt to
  44. * add any observers or deliver any events via the dispatcher.
  45. */
  46. void init();
  47. /**
  48. * Event dispatcher clean up. The <code>destroy</code> method will be
  49. * called by the <code>Connection</code> when it is finished delivering
  50. * events to it and the receiver daemon thread is exiting. Any initialising
  51. * done in the <code>init</code> method can be cleaned up here.
  52. * <p>
  53. * The <code>destroy</code> method <b>must not </b> interfere with the
  54. * delivery of any events notified to the event dispatcher before the call
  55. * to this method.
  56. * </p>
  57. */
  58. void destroy();
  59. /**
  60. * Add an observer to this event dispatcher.
  61. *
  62. * @param observer
  63. * the observer object to add.
  64. */
  65. void addObserver(SessionObserver observer);
  66. /**
  67. * Remove an observer from this event dispatcher.
  68. *
  69. * @param observer
  70. * the observer object to remove from the registered observers.
  71. */
  72. void removeObserver(SessionObserver observer);
  73. /**
  74. * Get a read-only collection view of all the observers registered with
  75. * this event dispatcher. This is useful for copying all of the observers
  76. * registered on one EventDispatcher into another.
  77. * @return A read-only collection of all the observers registered with
  78. * this dispatcher.
  79. */
  80. Collection<SessionObserver> getObservers();
  81. /**
  82. * Get an iterator over the currently registered observers.
  83. *
  84. * @return an iterator object which iterates over all registered observers.
  85. */
  86. Iterator<SessionObserver> observerIterator();
  87. /**
  88. * Notify all registered observers of an SMPP event.
  89. *
  90. * @param event
  91. * the SMPP event to notify observers of.
  92. */
  93. void notifyObservers(Session conn, SMPPEvent event);
  94. /**
  95. * Notify all registered observers of a received SMPP packet.
  96. *
  97. * @param packet
  98. * the SMPP packet to notify observers of.
  99. */
  100. void notifyObservers(Session conn, SMPPPacket packet);
  101. }