Author: robbie Date: Wed Apr 4 13:49:40 2012 New Revision: 1309383 URL: http://svn.apache.org/viewvc?rev=1309383&view=rev Log: QPID-3927: ensure that priority is properly accounted for when comparing messages on different QueueEntryLists contained within the encompassing PriorityQueue
merged from trunk r1309050 Added: qpid/branches/0.16/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/PriorityQueueListTest.java - copied unchanged from r1309050, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/PriorityQueueListTest.java Modified: qpid/branches/0.16/qpid/java/ (props changed) qpid/branches/0.16/qpid/java/broker/ (props changed) qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ (props changed) qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java Propchange: qpid/branches/0.16/qpid/java/ ------------------------------------------------------------------------------ Merged /qpid/trunk/qpid/java:r1309050 Propchange: qpid/branches/0.16/qpid/java/broker/ ------------------------------------------------------------------------------ Merged /qpid/trunk/qpid/java/broker:r1309050 Propchange: qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/ ------------------------------------------------------------------------------ Merged /qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue:r1309050 Modified: qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java URL: http://svn.apache.org/viewvc/qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java?rev=1309383&r1=1309382&r2=1309383&view=diff ============================================================================== --- qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java (original) +++ qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/PriorityQueueList.java Wed Apr 4 13:49:40 2012 @@ -25,19 +25,19 @@ import org.apache.qpid.server.message.Se public class PriorityQueueList implements QueueEntryList<SimpleQueueEntryImpl> { private final AMQQueue _queue; - private final SimpleQueueEntryList[] _priorityLists; + private final PriorityQueueEntrySubList[] _priorityLists; private final int _priorities; private final int _priorityOffset; public PriorityQueueList(AMQQueue queue, int priorities) { _queue = queue; - _priorityLists = new SimpleQueueEntryList[priorities]; + _priorityLists = new PriorityQueueEntrySubList[priorities]; _priorities = priorities; _priorityOffset = 5-((priorities + 1)/2); for(int i = 0; i < priorities; i++) { - _priorityLists[i] = new SimpleQueueEntryList(queue); + _priorityLists[i] = new PriorityQueueEntrySubList(queue); } } @@ -161,4 +161,48 @@ public class PriorityQueueList implement return new PriorityQueueList(queue, _priorities); } } + + private static class PriorityQueueEntrySubList extends SimpleQueueEntryList + { + public PriorityQueueEntrySubList(AMQQueue queue) + { + super(queue); + } + + @Override + protected PriorityQueueEntryImpl createQueueEntry(ServerMessage<?> message) + { + return new PriorityQueueEntryImpl(this, message); + } + } + + private static class PriorityQueueEntryImpl extends SimpleQueueEntryImpl + { + public PriorityQueueEntryImpl(PriorityQueueEntrySubList queueEntryList, ServerMessage<?> message) + { + super(queueEntryList, message); + } + + @Override + public int compareTo(final QueueEntry o) + { + byte thisPriority = getMessageHeader().getPriority(); + byte otherPriority = o.getMessageHeader().getPriority(); + + if(thisPriority != otherPriority) + { + /* + * Different priorities, so answer can only be greater than or less than + * + * A message with higher priority (e.g. 5) is conceptually 'earlier' in the + * priority queue than one with a lower priority (e.g. 4). + */ + return thisPriority > otherPriority ? -1 : 1; + } + else + { + return super.compareTo(o); + } + } + } } Modified: qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java URL: http://svn.apache.org/viewvc/qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java?rev=1309383&r1=1309382&r2=1309383&view=diff ============================================================================== --- qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java (original) +++ qpid/branches/0.16/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java Wed Apr 4 13:49:40 2012 @@ -104,7 +104,7 @@ public class SimpleQueueEntryList implem } } - protected SimpleQueueEntryImpl createQueueEntry(ServerMessage message) + protected SimpleQueueEntryImpl createQueueEntry(ServerMessage<?> message) { return new SimpleQueueEntryImpl(this, message); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org