Exemplo n.º 1
0
  /* (non-Javadoc)
   * @see flap.messaging.IMessageQueue#isEmpty()
   */
  @Override
  public final boolean isEmpty() {
    for (MessagePriority priority : MessagePriority.values())
      if (!messageQueues.get(priority).isEmpty()) return false;

    return true;
  }
Exemplo n.º 2
0
  /**
   * Provides the total amount of messages waiting to be processed, without any regard to the
   * priority of each message.
   *
   * @return the total number of not-yet-processed messages
   */
  public final int getQueueLength() {
    int sum = 0;

    for (MessagePriority priority : MessagePriority.values())
      sum += getQueueLengthByPriority(priority);

    return sum;
  }
Exemplo n.º 3
0
  /** Default constructor. Creates all the message queues. */
  public MessageQueue() {
    super();

    // init the message queue container
    messageQueues = new HashMap<MessagePriority, List<Message>>();

    // create all the message queues
    for (MessagePriority priority : MessagePriority.values())
      messageQueues.put(priority, new LinkedList<Message>());
  }
Exemplo n.º 4
0
  /**
   * Provides the next method to be processed. The method scans each priority queue in order to find
   * the first not-null message and removes it from the queue returning it. The side effect is that
   * the message is no more into the queue. If no message is found at any priority level, than null
   * is returned.
   *
   * @return the next message to process or null if none
   */
  public synchronized Message getNextMessage() {
    for (MessagePriority priority : MessagePriority.values()) {
      List<Message> currentQueue = messageQueues.get(priority);
      if (!currentQueue.isEmpty()) {
        // get the head and remove it from the list
        Message currentMessage = currentQueue.remove(0);
        // this is the next message to be processed
        return currentMessage;
      }
    }

    // if here no message has been found in any priority queue
    return null;
  }