You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/03/30 10:27:28 UTC
svn commit: r523988 - in
/incubator/servicemix/trunk/core/servicemix-core/src:
main/java/org/apache/servicemix/jbi/messaging/MessageExchangeImpl.java
test/java/org/apache/servicemix/jbi/messaging/MessageExchangeImplTest.java
Author: gnodet
Date: Fri Mar 30 01:27:27 2007
New Revision: 523988
URL: http://svn.apache.org/viewvc?view=rev&rev=523988
Log:
SM-884: New exchanges should have a lesser priority compared to older exchanges
This commit is the first one, jsut to add a comparator. It is not used yet.
Modified:
incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/MessageExchangeImpl.java
incubator/servicemix/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/MessageExchangeImplTest.java
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/MessageExchangeImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/MessageExchangeImpl.java?view=diff&rev=523988&r1=523987&r2=523988
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/MessageExchangeImpl.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/MessageExchangeImpl.java Fri Mar 30 01:27:27 2007
@@ -40,6 +40,7 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.net.URI;
+import java.util.Comparator;
import java.util.Set;
/**
@@ -757,4 +758,25 @@
}
return key;
}
-}
\ No newline at end of file
+
+ /**
+ * Comparator that can be used to sort exchanges according to their
+ * "age" in their processing: i.e.: a newly created exchange will be
+ * more than a DONE exchange ...
+ * If the arguments are not instances of MessageExchangeImpl,
+ * returns 0.
+ */
+ public static class AgeComparator implements Comparator<MessageExchangeImpl> {
+ public int compare(MessageExchangeImpl m0, MessageExchangeImpl m1) {
+ int i0 = (m0.state * 4) / (m0.states.length - 1);
+ int i1 = (m1.state * 4) / (m1.states.length - 1);
+ if (i0 < i1) {
+ return +1;
+ } else if (i0 == i1) {
+ return 0;
+ } else {
+ return -1;
+ }
+ }
+ }
+}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/MessageExchangeImplTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/MessageExchangeImplTest.java?view=diff&rev=523988&r1=523987&r2=523988
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/MessageExchangeImplTest.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/test/java/org/apache/servicemix/jbi/messaging/MessageExchangeImplTest.java Fri Mar 30 01:27:27 2007
@@ -16,28 +16,29 @@
*/
package org.apache.servicemix.jbi.messaging;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.jbi.jaxp.BytesSource;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.apache.servicemix.jbi.jaxp.StringSource;
-import org.apache.servicemix.jbi.messaging.InOnlyImpl;
-import org.apache.servicemix.jbi.util.StreamDataSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.concurrent.PriorityBlockingQueue;
import javax.activation.DataHandler;
+import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
import junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.jaxp.BytesSource;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.util.StreamDataSource;
+
public class MessageExchangeImplTest extends TestCase {
private static final Log log = LogFactory.getLog(MessageExchangeImplTest.class);
@@ -103,6 +104,26 @@
public void testSerializeDeserializeWithSaxSource() throws Exception {
Source src = new SourceTransformer().toSAXSource(new StringSource("<hello>world</hello>"));
testSerializeDeserialize(src);
+ }
+
+ public void testAgeComparator() throws Exception {
+ PriorityBlockingQueue<MessageExchangeImpl> queue = new PriorityBlockingQueue<MessageExchangeImpl>(11, new MessageExchangeImpl.AgeComparator());
+ MessageExchangeImpl me1 = new InOnlyImpl("me1");
+ MessageExchangeImpl me2 = new InOnlyImpl("me2");
+ me2.handleSend(false);
+ me2.packet.setStatus(ExchangeStatus.DONE);
+ me2.handleAccept();
+ MessageExchangeImpl me3 = new InOutImpl("me3");
+ me3.handleSend(false);
+ me3.handleAccept();
+
+ queue.put(me1);
+ queue.put(me2);
+ queue.put(me3);
+
+ assertEquals(me2, queue.take());
+ assertEquals(me3, queue.take());
+ assertEquals(me1, queue.take());
}
}