Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PriorityBlockingQueuePersistedMessageComparator |
|
| 12.0;12 |
1 | /* | |
2 | * Copyright 2007-2008 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 java.util.Comparator; | |
19 | ||
20 | import org.kuali.rice.ksb.messaging.MessageServiceInvoker; | |
21 | import org.kuali.rice.ksb.messaging.PersistedMessage; | |
22 | ||
23 | import java.util.concurrent.PriorityBlockingQueue; | |
24 | ||
25 | /** | |
26 | * A comparator to put into the {@link PriorityBlockingQueue} used in the {@link KSBThreadPoolImpl}. | |
27 | * | |
28 | * Determines execution order by priority and create date. | |
29 | * | |
30 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
31 | * | |
32 | */ | |
33 | 0 | public class PriorityBlockingQueuePersistedMessageComparator implements Comparator { |
34 | ||
35 | ||
36 | public int compare(Object arg0, Object arg1) { | |
37 | 0 | if (! (arg0 instanceof MessageServiceInvoker) || ! (arg1 instanceof MessageServiceInvoker) ) { |
38 | 0 | return 0; |
39 | } | |
40 | 0 | PersistedMessage message0 = ((MessageServiceInvoker)arg0).getMessage(); |
41 | 0 | PersistedMessage message1 = ((MessageServiceInvoker)arg1).getMessage(); |
42 | ||
43 | 0 | if (message0.getQueuePriority() < message1.getQueuePriority()) { |
44 | 0 | return -1; |
45 | 0 | } else if (message0.getQueuePriority() > message1.getQueuePriority()) { |
46 | 0 | return 1; |
47 | } | |
48 | ||
49 | 0 | if (message0.getQueueDate().before(message1.getQueueDate())) { |
50 | 0 | return -1; |
51 | 0 | } else if (message0.getQueueDate().after(message1.getQueueDate())) { |
52 | 0 | return 1; |
53 | } | |
54 | ||
55 | 0 | return 0; |
56 | } | |
57 | ||
58 | } |