org.exolab.jms.messagemgr
Class MessageQueue

java.lang.Object
  |
  +--org.exolab.jms.messagemgr.MessageQueue

public class MessageQueue
extends java.lang.Object

The message queue stored messages based on a comparator. The implementation is based on a synchronized linked list.

We can easily improve on this implementation and this implementation is not synchronized.

Version:
$Revision: 1.32.2.1 $ $Date: 2004/05/01 12:01:15 $
Author:
Jim Alateras, Tim Anderson

Constructor Summary
MessageQueue(java.util.Comparator comparator)
          Instantiate an instance of this class with the specified comparator the comparator is used to order the elements in the queue.
 
Method Summary
 void add(java.lang.Object object)
          Add this element to the queue in the required order.
 void clear()
          Remove all the elements from the queue
 boolean contains(java.lang.Object object)
          Check if the specified object exists
 java.lang.Object first()
          Returns the first element in the queue.
 boolean isEmpty()
          Check if the queue is empty
 java.util.Iterator iterator()
          Return an iterator to the list
 java.lang.Object last()
          Returns the last element in the queue.
 boolean remove(java.lang.Object object)
          Remove the object from the queue
 java.lang.Object removeFirst()
          Removes and returns the first element on the queue.
 java.lang.Object removeLast()
          Removes and returns the last element in the queue
 int size()
          Return the number elements in the queue
 java.lang.Object[] toArray()
          Return all elements in the collection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageQueue

public MessageQueue(java.util.Comparator comparator)
Instantiate an instance of this class with the specified comparator the comparator is used to order the elements in the queue. Elements with the same order value are placed after each other.
Parameters:
comparator - used for ordering
Method Detail

add

public void add(java.lang.Object object)
Add this element to the queue in the required order. It uses a binary search to locate the correct position
Parameters:
object - object to add

contains

public boolean contains(java.lang.Object object)
Check if the specified object exists
Parameters:
object - - object to check
Returns:
boolean - true if it is contained

isEmpty

public boolean isEmpty()
Check if the queue is empty
Returns:
boolean - true if the queue is empty

toArray

public java.lang.Object[] toArray()
Return all elements in the collection
Returns:
Object[] array of elements to return

iterator

public java.util.Iterator iterator()
Return an iterator to the list
Returns:
Iterator

remove

public boolean remove(java.lang.Object object)
Remove the object from the queue
Parameters:
object - object to remove

clear

public void clear()
Remove all the elements from the queue

size

public int size()
Return the number elements in the queue
Returns:
int size of the queue

first

public java.lang.Object first()
Returns the first element in the queue.
Returns:
the first element in the queue, or null, if the queue is empty

last

public java.lang.Object last()
Returns the last element in the queue.
Returns:
the last element in the queue, or null, if the queue is empty

removeFirst

public java.lang.Object removeFirst()
Removes and returns the first element on the queue.
Returns:
the first element in the queue, or null, if the queue is empty

removeLast

public java.lang.Object removeLast()
Removes and returns the last element in the queue
Returns:
the last element in the queue, or null, if the queue is empty


Copyright © 1999-2004 The OpenJMS Group. All Rights Reserved.