01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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 edu.iu.uis.eden.messaging.threadpool;
17:
18: import java.util.Comparator;
19:
20: import edu.emory.mathcs.backport.java.util.concurrent.PriorityBlockingQueue;
21: import edu.iu.uis.eden.messaging.MessageServiceInvoker;
22: import edu.iu.uis.eden.messaging.PersistedMessage;
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 (kuali-rice@googlegroups.com)
30: *
31: */
32: public class PriorityBlockingQueuePersistedMessageComparator implements
33: Comparator {
34:
35: public int compare(Object arg0, Object arg1) {
36: if (!(arg0 instanceof MessageServiceInvoker)
37: || !(arg1 instanceof MessageServiceInvoker)) {
38: return 0;
39: }
40: PersistedMessage message0 = ((MessageServiceInvoker) arg0)
41: .getMessage();
42: PersistedMessage message1 = ((MessageServiceInvoker) arg1)
43: .getMessage();
44:
45: if (message0.getQueuePriority() < message1.getQueuePriority()) {
46: return -1;
47: } else if (message0.getQueuePriority() > message1
48: .getQueuePriority()) {
49: return 1;
50: }
51:
52: if (message0.getQueueDate().before(message1.getQueueDate())) {
53: return -1;
54: } else if (message0.getQueueDate().after(
55: message1.getQueueDate())) {
56: return 1;
57: }
58:
59: return 0;
60: }
61:
62: }
|