Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PriorityBlockingQueuePersistedMessageComparator |
|
| 12.0;12 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
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 | * A comparator to put into the {@link PriorityBlockingQueue} used in the {@link KSBThreadPoolImpl}. | |
26 | * | |
27 | * Determines execution order by priority and create date. | |
28 | * | |
29 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
30 | * | |
31 | */ | |
32 | 0 | public class PriorityBlockingQueuePersistedMessageComparator implements Comparator { |
33 | ||
34 | ||
35 | public int compare(Object arg0, Object arg1) { | |
36 | 0 | if (! (arg0 instanceof MessageServiceInvoker) || ! (arg1 instanceof MessageServiceInvoker) ) { |
37 | 0 | return 0; |
38 | } | |
39 | 0 | PersistedMessageBO message0 = ((MessageServiceInvoker)arg0).getMessage(); |
40 | 0 | PersistedMessageBO message1 = ((MessageServiceInvoker)arg1).getMessage(); |
41 | ||
42 | 0 | if (message0.getQueuePriority() < message1.getQueuePriority()) { |
43 | 0 | return -1; |
44 | 0 | } else if (message0.getQueuePriority() > message1.getQueuePriority()) { |
45 | 0 | return 1; |
46 | } | |
47 | ||
48 | 0 | if (message0.getQueueDate().before(message1.getQueueDate())) { |
49 | 0 | return -1; |
50 | 0 | } else if (message0.getQueueDate().after(message1.getQueueDate())) { |
51 | 0 | return 1; |
52 | } | |
53 | ||
54 | 0 | return 0; |
55 | } | |
56 | ||
57 | } |