Author: jstrachan
Date: Tue Apr 25 07:05:03 2006
New Revision: 396891
URL: http://svn.apache.org/viewcvs?rev=396891&view=rev
Log:
added helper classes for comparing messages
Added:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageComparatorSupport.java
(with props)
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageDestinationComparator.java
(with props)
Added:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageComparatorSupport.java
URL:
http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageComparatorSupport.java?rev=396891&view=auto
==============================================================================
---
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageComparatorSupport.java
(added)
+++
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageComparatorSupport.java
Tue Apr 25 07:05:03 2006
@@ -0,0 +1,48 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.util;
+
+import javax.jms.Message;
+
+import java.util.Comparator;
+
+/**
+ * A base class for comparators which works on JMS [EMAIL PROTECTED] Message}
objects
+ *
+ * @version $Revision$
+ */
+public abstract class MessageComparatorSupport implements Comparator {
+
+ public int compare(Object object1, Object object2) {
+ Message command1 = (Message) object1;
+ Message command2 = (Message) object2;
+ return compareMessages(command1, command2);
+ }
+
+ protected abstract int compareMessages(Message message1, Message message2);
+
+ protected int compareComparators(Comparable comparable, Comparable
comparable2) {
+ if (comparable != null) {
+ return comparable.compareTo(comparable2);
+ }
+ else if (comparable2 != null) {
+ return comparable2.compareTo(comparable) * -1;
+ }
+ return 0;
+ }
+
+}
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageComparatorSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageComparatorSupport.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageComparatorSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageDestinationComparator.java
URL:
http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageDestinationComparator.java?rev=396891&view=auto
==============================================================================
---
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageDestinationComparator.java
(added)
+++
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageDestinationComparator.java
Tue Apr 25 07:05:03 2006
@@ -0,0 +1,56 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.util;
+
+import org.apache.activemq.command.ActiveMQMessage;
+
+import javax.jms.*;
+
+/**
+ * A comparator which works on SendCommand objects to compare the destinations
+ *
+ * @version $Revision$
+ */
+public class MessageDestinationComparator extends MessageComparatorSupport {
+
+ protected int compareMessages(Message message1, Message message2) {
+ return compareComparators(getComparable(getDestination(message1)),
getComparable(getDestination(message2)));
+ }
+
+ protected Destination getDestination(Message message) {
+ if (message instanceof ActiveMQMessage) {
+ ActiveMQMessage amqMessage = (ActiveMQMessage) message;
+ return amqMessage.getDestination();
+ }
+ try {
+ return message.getJMSDestination();
+ }
+ catch (JMSException e) {
+ return null;
+ }
+ }
+
+ protected Comparable getComparable(Destination destination) {
+ if (destination != null) {
+ return destination.toString();
+ }
+ return null;
+ }
+
+
+
+}
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageDestinationComparator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageDestinationComparator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MessageDestinationComparator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain