1 package net.walend.somnifugi.juc; 2 3 import java.util.Comparator ; 4 5 import javax.jms.Message ; 6 import javax.jms.JMSException ; 7 8 import net.walend.somnifugi.SomniRuntimeException; 9 import net.walend.somnifugi.SomniMessage; 10 11 16 17 class MessageComparator 18 implements Comparator <Message > 19 { 20 MessageComparator() 21 {} 22 23 30 public int compare(Message message1,Message message2) 31 { 32 try 33 { 34 if(message1.getJMSPriority()>message2.getJMSPriority()) 36 { 37 return -1; 38 } 39 if(message1.getJMSPriority()<message2.getJMSPriority()) 40 { 41 return 1; 42 } 43 44 if(message1.getJMSTimestamp()<message2.getJMSTimestamp()) 46 { 47 return -1; 48 } 49 else if(message1.getJMSTimestamp()>message2.getJMSTimestamp()) 50 { 51 return 1; 52 } 53 else 54 { 55 if((message1 instanceof SomniMessage)&&(message2 instanceof SomniMessage)) 57 { 58 int message1ID = ((SomniMessage)message1).getSomniProducerCount(); 59 int message2ID = ((SomniMessage)message2).getSomniProducerCount(); 60 61 if(message1ID < message2ID) 62 { 63 return -1; 64 } 65 else if(message1ID > message2ID) 66 { 67 return 1; 68 } 69 } 70 if(message1.getJMSMessageID()!=null) 72 { 73 return message1.getJMSMessageID().compareTo(message2.getJMSMessageID()); 74 } 75 76 } 77 return 0; 79 } 80 catch(JMSException jmse) 81 { 82 throw new SomniRuntimeException("Trouble comparing time stamps.",jmse); 83 } 84 } 85 } 86 87 107 | Popular Tags |