Пример #1
0
 /**
  * Method removes a subscriber from a list of subscription. if there are no more subscribers to
  * the specified message, method removes it from the list as well.
  *
  * @param messageId - a legal message identifier. Can't be < 0.
  * @param subscriber - a subscriber that needs to be add to the list.
  * @throws {@link IllegalArgumentException} if messageId < 0 or subscriber == null
  * @return true on success, false otherwise.
  */
 boolean unsubscribe(int messageId, Subscriber subscriber) {
   if (messageId < 0 || subscriber == null) throw new IllegalArgumentException();
   return _subscribers.remove(messageId, subscriber);
 }
Пример #2
0
 /**
  * Notifies all subscribers about with specified message.
  *
  * @param message - message that is to notify subscribers.
  */
 void dispatch(SystemMessage message) {
   for (Subscriber s : _subscribers.get(message.ID)) {
     s.onNotify(message);
   }
 }
Пример #3
0
 /**
  * Method adds a subscriber and a message that it's subscribed to to a list of subscribers.
  *
  * @param messageId - a legal message identifier. Can't be < 0.
  * @param subscriber - a subscriber that needs to be add to the list.
  * @throws {@link IllegalArgumentException} if messageId < 0 or subscriber == null
  * @return true on success, false if the subscriber is already subscribed to the message.
  */
 void subscribe(int messageId, Subscriber subscriber) {
   if (messageId < 0 || subscriber == null) throw new IllegalArgumentException();
   _subscribers.put(messageId, subscriber);
 }