diff options
| author | Robert Gemmell <robbie@apache.org> | 2009-07-21 09:05:21 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2009-07-21 09:05:21 +0000 |
| commit | 270c4f63c40417af21c7fb72ef1b027d9dfc5987 (patch) | |
| tree | d9e92258b01c5f223e3dc88cc2532dacaa7ef03e /qpid/java/broker/src/main | |
| parent | aa39f625f7686b801922876e60f3ee9b505a6228 (diff) | |
| download | qpid-python-270c4f63c40417af21c7fb72ef1b027d9dfc5987.tar.gz | |
QPID-1961: expand viewMessages() queue operation to support long parameters, deprecate previous int version.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@796196 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/main')
3 files changed, 74 insertions, 6 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java index 014b348822..4643326df3 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java @@ -112,6 +112,17 @@ public interface AMQQueue extends Managable, Comparable<AMQQueue> List<Long> getMessagesOnTheQueue(int num, int offest); QueueEntry getMessageOnTheQueue(long messageId); + + /** + * Returns a list of QueEntries from a given range of queue positions, eg messages 5 to 10 on the queue. + * + * The 'queue position' index starts from 1. Using 0 in 'from' will be ignored and continue from 1. + * Using 0 in the 'to' field will return an empty list regardless of the 'from' value. + * @param fromPosition + * @param toPosition + * @return + */ + public List<QueueEntry> getMessagesRangeOnTheQueue(final long fromPosition, final long toPosition); void moveMessagesToAnotherQueue(long fromMessageId, long toMessageId, String queueName, diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java index 785b668687..77c45d6d16 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java @@ -380,25 +380,45 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que /** * Returns the header contents of the messages stored in this queue in tabular form. + * Deprecated as of Qpid JMX API 1.3 */ + @Deprecated public TabularData viewMessages(int beginIndex, int endIndex) throws JMException { - if ((beginIndex > endIndex) || (beginIndex < 1)) + return viewMessages((long)beginIndex,(long)endIndex); + } + + + /** + * Returns the header contents of the messages stored in this queue in tabular form. + * @param startPosition The queue position of the first message to be viewed + * @param endPosition The queue position of the last message to be viewed + */ + public TabularData viewMessages(long startPosition, long endPosition) throws JMException + { + if ((startPosition > endPosition) || (startPosition < 1)) { - throw new OperationsException("From Index = " + beginIndex + ", To Index = " + endIndex + throw new OperationsException("From Index = " + startPosition + ", To Index = " + endPosition + "\n\"From Index\" should be greater than 0 and less than \"To Index\""); } + + if ((endPosition - startPosition) > Integer.MAX_VALUE) + { + throw new OperationsException("Specified MessageID interval is too large. Intervals must be less than 2^31 in size"); + } - List<QueueEntry> list = _queue.getMessagesOnTheQueue(); + List<QueueEntry> list = _queue.getMessagesRangeOnTheQueue(startPosition,endPosition); TabularDataSupport _messageList = new TabularDataSupport(_messagelistDataType); try { // Create the tabular list of message header contents - for (int i = beginIndex; (i <= endIndex) && (i <= list.size()); i++) + int size = list.size(); + + for (int i = 0; i < size ; i++) { - long position = i; - AMQMessage msg = list.get(i - 1).getMessage(); + long position = startPosition + i; + AMQMessage msg = list.get(i).getMessage(); ContentHeaderBody headerBody = msg.getContentHeaderBody(); // Create header attributes list String[] headerAttributes = getMessageHeaderProperties(headerBody); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java index 08daf715ef..e994967dc5 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java @@ -813,6 +813,43 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener return entryList; } + + /** + * Returns a list of QueEntries from a given range of queue positions, eg messages 5 to 10 on the queue. + * + * The 'queue position' index starts from 1. Using 0 in 'from' will be ignored and continue from 1. + * Using 0 in the 'to' field will return an empty list regardless of the 'from' value. + * @param fromPosition + * @param toPosition + * @return + */ + public List<QueueEntry> getMessagesRangeOnTheQueue(final long fromPosition, final long toPosition) + { + List<QueueEntry> queueEntries = new ArrayList<QueueEntry>(); + + QueueEntryIterator it = _entries.iterator(); + + long index = 1; + for ( ; index < fromPosition && !it.atTail(); index++) + { + it.advance(); + } + + if(index < fromPosition) + { + //The queue does not contain enough entries to reach our range. + //return the empty list. + return queueEntries; + } + + for ( ; index <= toPosition && !it.atTail(); index++) + { + it.advance(); + queueEntries.add(it.getNode()); + } + + return queueEntries; + } public void moveMessagesToAnotherQueue(final long fromMessageId, final long toMessageId, |
