1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.threadpool;
17
18 import org.kuali.rice.ksb.messaging.MessageServiceInvoker;
19 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
20
21 import java.util.Comparator;
22 import java.util.concurrent.PriorityBlockingQueue;
23
24
25
26
27
28
29
30
31
32 public class PriorityBlockingQueuePersistedMessageComparator implements Comparator {
33
34
35 public int compare(Object arg0, Object arg1) {
36 if (! (arg0 instanceof MessageServiceInvoker) || ! (arg1 instanceof MessageServiceInvoker) ) {
37 return 0;
38 }
39 PersistedMessageBO message0 = ((MessageServiceInvoker)arg0).getMessage();
40 PersistedMessageBO message1 = ((MessageServiceInvoker)arg1).getMessage();
41
42 if (message0.getQueuePriority() < message1.getQueuePriority()) {
43 return -1;
44 } else if (message0.getQueuePriority() > message1.getQueuePriority()) {
45 return 1;
46 }
47
48 if (message0.getQueueDate().before(message1.getQueueDate())) {
49 return -1;
50 } else if (message0.getQueueDate().after(message1.getQueueDate())) {
51 return 1;
52 }
53
54 return 0;
55 }
56
57 }