INT-1287 priority is just an Integer now, no longer a need for MessageHeaders to depend on a custom enum
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.integration.util.UpperBound;
|
||||
|
||||
/**
|
||||
@@ -96,11 +95,11 @@ public class PriorityChannel extends QueueChannel {
|
||||
private static class MessagePriorityComparator implements Comparator<Message<?>> {
|
||||
|
||||
public int compare(Message<?> message1, Message<?> message2) {
|
||||
MessagePriority priority1 = message1.getHeaders().getPriority();
|
||||
MessagePriority priority2 = message2.getHeaders().getPriority();
|
||||
priority1 = priority1 != null ? priority1 : MessagePriority.NORMAL;
|
||||
priority2 = priority2 != null ? priority2 : MessagePriority.NORMAL;
|
||||
return priority1.compareTo(priority2);
|
||||
Integer priority1 = message1.getHeaders().getPriority();
|
||||
Integer priority2 = message2.getHeaders().getPriority();
|
||||
priority1 = priority1 != null ? priority1 : 0;
|
||||
priority2 = priority2 != null ? priority2 : 0;
|
||||
return priority2.compareTo(priority1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.w3c.dom.Element;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -40,7 +39,7 @@ public class StandardHeaderEnricherParser extends HeaderEnricherParserSupport {
|
||||
this.addElementToHeaderMapping("error-channel", MessageHeaders.ERROR_CHANNEL);
|
||||
this.addElementToHeaderMapping("correlation-id", MessageHeaders.CORRELATION_ID);
|
||||
this.addElementToHeaderMapping("expiration-date", MessageHeaders.EXPIRATION_DATE, Long.class);
|
||||
this.addElementToHeaderMapping("priority", MessageHeaders.PRIORITY, MessagePriority.class);
|
||||
this.addElementToHeaderMapping("priority", MessageHeaders.PRIORITY, Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -77,7 +77,6 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
|
||||
|
||||
public MessageHeaders(Map<String, Object> headers) {
|
||||
this.headers = (headers != null) ? new HashMap<String, Object>(headers) : new HashMap<String, Object>();
|
||||
//this.headers.put(ID, TimeBasedUUIDGenerator.generateId());
|
||||
this.headers.put(ID, UUID.randomUUID());
|
||||
this.headers.put(TIMESTAMP, new Long(System.currentTimeMillis()));
|
||||
if (this.headers.get(HISTORY) == null) {
|
||||
@@ -123,8 +122,8 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
|
||||
return (sequenceSize != null ? sequenceSize : 0);
|
||||
}
|
||||
|
||||
public MessagePriority getPriority() {
|
||||
return this.get(PRIORITY, MessagePriority.class);
|
||||
public Integer getPriority() {
|
||||
return this.get(PRIORITY, Integer.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* 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.springframework.integration.core;
|
||||
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
|
||||
/**
|
||||
* An enumeration of the possible values for a message's priority.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @see MessageHeaders#getPriority()
|
||||
* @see MessageBuilder#setPriority(MessagePriority)
|
||||
*/
|
||||
public enum MessagePriority {
|
||||
|
||||
HIGHEST,
|
||||
HIGH,
|
||||
NORMAL,
|
||||
LOW,
|
||||
LOWEST
|
||||
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import java.util.UUID;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -193,7 +192,7 @@ public final class MessageBuilder<T> {
|
||||
return this.setHeader(MessageHeaders.SEQUENCE_SIZE, sequenceSize);
|
||||
}
|
||||
|
||||
public MessageBuilder<T> setPriority(MessagePriority priority) {
|
||||
public MessageBuilder<T> setPriority(Integer priority) {
|
||||
return this.setHeader(MessageHeaders.PRIORITY, priority);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
@@ -55,21 +54,21 @@ public class PriorityChannelTests {
|
||||
@Test
|
||||
public void testDefaultComparator() {
|
||||
PriorityChannel channel = new PriorityChannel(5);
|
||||
Message<?> priority1 = createPriorityMessage(MessagePriority.HIGHEST);
|
||||
Message<?> priority2 = createPriorityMessage(MessagePriority.HIGH);
|
||||
Message<?> priority3 = createPriorityMessage(MessagePriority.NORMAL);
|
||||
Message<?> priority4 = createPriorityMessage(MessagePriority.LOW);
|
||||
Message<?> priority5 = createPriorityMessage(MessagePriority.LOWEST);
|
||||
Message<?> priority1 = createPriorityMessage(10);
|
||||
Message<?> priority2 = createPriorityMessage(7);
|
||||
Message<?> priority3 = createPriorityMessage(0);
|
||||
Message<?> priority4 = createPriorityMessage(-3);
|
||||
Message<?> priority5 = createPriorityMessage(-99);
|
||||
channel.send(priority4);
|
||||
channel.send(priority3);
|
||||
channel.send(priority5);
|
||||
channel.send(priority1);
|
||||
channel.send(priority2);
|
||||
assertEquals("test-HIGHEST", channel.receive(0).getPayload());
|
||||
assertEquals("test-HIGH", channel.receive(0).getPayload());
|
||||
assertEquals("test-NORMAL", channel.receive(0).getPayload());
|
||||
assertEquals("test-LOW", channel.receive(0).getPayload());
|
||||
assertEquals("test-LOWEST", channel.receive(0).getPayload());
|
||||
assertEquals("test:10", channel.receive(0).getPayload());
|
||||
assertEquals("test:7", channel.receive(0).getPayload());
|
||||
assertEquals("test:0", channel.receive(0).getPayload());
|
||||
assertEquals("test:-3", channel.receive(0).getPayload());
|
||||
assertEquals("test:-99", channel.receive(0).getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,29 +94,29 @@ public class PriorityChannelTests {
|
||||
@Test
|
||||
public void testNullPriorityIsConsideredNormal() {
|
||||
PriorityChannel channel = new PriorityChannel(5);
|
||||
Message<?> highPriority = createPriorityMessage(MessagePriority.HIGH);
|
||||
Message<?> lowPriority = createPriorityMessage(MessagePriority.LOW);
|
||||
Message<?> nullPriority = new StringMessage("test-NULL");
|
||||
Message<?> highPriority = createPriorityMessage(5);
|
||||
Message<?> lowPriority = createPriorityMessage(-5);
|
||||
Message<?> nullPriority = new StringMessage("test:NULL");
|
||||
channel.send(lowPriority);
|
||||
channel.send(highPriority);
|
||||
channel.send(nullPriority);
|
||||
assertEquals("test-HIGH", channel.receive(0).getPayload());
|
||||
assertEquals("test-NULL", channel.receive(0).getPayload());
|
||||
assertEquals("test-LOW", channel.receive(0).getPayload());
|
||||
assertEquals("test:5", channel.receive(0).getPayload());
|
||||
assertEquals("test:NULL", channel.receive(0).getPayload());
|
||||
assertEquals("test:-5", channel.receive(0).getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnboundedCapacity() {
|
||||
PriorityChannel channel = new PriorityChannel();
|
||||
Message<?> highPriority = createPriorityMessage(MessagePriority.HIGH);
|
||||
Message<?> lowPriority = createPriorityMessage(MessagePriority.LOW);
|
||||
Message<?> nullPriority = new StringMessage("test-NULL");
|
||||
Message<?> highPriority = createPriorityMessage(5);
|
||||
Message<?> lowPriority = createPriorityMessage(-5);
|
||||
Message<?> nullPriority = new StringMessage("test:NULL");
|
||||
channel.send(lowPriority);
|
||||
channel.send(highPriority);
|
||||
channel.send(nullPriority);
|
||||
assertEquals("test-HIGH", channel.receive(0).getPayload());
|
||||
assertEquals("test-NULL", channel.receive(0).getPayload());
|
||||
assertEquals("test-LOW", channel.receive(0).getPayload());
|
||||
assertEquals("test:5", channel.receive(0).getPayload());
|
||||
assertEquals("test:NULL", channel.receive(0).getPayload());
|
||||
assertEquals("test:-5", channel.receive(0).getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,8 +193,8 @@ public class PriorityChannelTests {
|
||||
}
|
||||
|
||||
|
||||
private static Message<String> createPriorityMessage(MessagePriority priority) {
|
||||
return MessageBuilder.withPayload("test-" + priority).setPriority(priority).build();
|
||||
private static Message<String> createPriorityMessage(int priority) {
|
||||
return MessageBuilder.withPayload("test:" + priority).setPriority(priority).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,6 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.TestChannelInterceptor;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy;
|
||||
import org.springframework.integration.dispatcher.UnicastingDispatcher;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
@@ -203,14 +202,11 @@ public class ChannelParserTests {
|
||||
|
||||
@Test
|
||||
public void testPriorityChannelWithDefaultComparator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("priorityChannelParserTests.xml", this
|
||||
.getClass());
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("priorityChannelParserTests.xml", this.getClass());
|
||||
PollableChannel channel = (PollableChannel) context.getBean("priorityChannelWithDefaultComparator");
|
||||
Message<String> lowPriorityMessage = MessageBuilder.withPayload("low").setPriority(MessagePriority.LOW).build();
|
||||
Message<String> midPriorityMessage = MessageBuilder.withPayload("mid").setPriority(MessagePriority.NORMAL)
|
||||
.build();
|
||||
Message<String> highPriorityMessage = MessageBuilder.withPayload("high").setPriority(MessagePriority.HIGH)
|
||||
.build();
|
||||
Message<String> lowPriorityMessage = MessageBuilder.withPayload("low").setPriority(-14).build();
|
||||
Message<String> midPriorityMessage = MessageBuilder.withPayload("mid").setPriority(0).build();
|
||||
Message<String> highPriorityMessage = MessageBuilder.withPayload("high").setPriority(99).build();
|
||||
channel.send(lowPriorityMessage);
|
||||
channel.send(highPriorityMessage);
|
||||
channel.send(midPriorityMessage);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<transformer input-channel="fail" expression="payload.thisWillCauseAnException"/>
|
||||
|
||||
@@ -56,11 +56,11 @@
|
||||
</channel>
|
||||
|
||||
<header-enricher input-channel="priorityExplicitOverwriteTrueInput" output-channel="echo">
|
||||
<priority value="HIGH" overwrite="true"/>
|
||||
<priority value="42" overwrite="true"/>
|
||||
</header-enricher>
|
||||
|
||||
<header-enricher input-channel="priorityExplicitOverwriteFalseInput" output-channel="echo">
|
||||
<priority value="LOW" overwrite="false"/>
|
||||
<priority value="9999" overwrite="false"/>
|
||||
</header-enricher>
|
||||
|
||||
<header-enricher input-channel="customExplicitOverwriteTrueInput" output-channel="echo">
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.integration.gateway.SimpleMessagingGateway;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -145,7 +144,7 @@ public class HeaderEnricherOverwriteTests {
|
||||
gateway.setRequestChannel(context.getBean("priorityExplicitOverwriteTrueInput", MessageChannel.class));
|
||||
Message<?> result = gateway.sendAndReceiveMessage("test");
|
||||
assertNotNull(result);
|
||||
assertEquals(MessagePriority.HIGH, result.getHeaders().getPriority());
|
||||
assertEquals(new Integer(42), result.getHeaders().getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,12 +153,12 @@ public class HeaderEnricherOverwriteTests {
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
Message<?> message = MessageBuilder.withPayload("test")
|
||||
.setReplyChannel(replyChannel)
|
||||
.setPriority(MessagePriority.HIGHEST)
|
||||
.setPriority(77)
|
||||
.build();
|
||||
input.send(message);
|
||||
Message<?> result = replyChannel.receive(0);
|
||||
assertNotNull(result);
|
||||
assertEquals(MessagePriority.HIGHEST, result.getHeaders().getPriority());
|
||||
assertEquals(new Integer(77), result.getHeaders().getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<header-enricher input-channel="replyChannelInput" output-channel="echoInput">
|
||||
<reply-channel ref="testReplyChannel"/>
|
||||
@@ -63,7 +63,7 @@
|
||||
</beans:bean>
|
||||
|
||||
<header-enricher input-channel="priorityInput">
|
||||
<priority value="HIGH"/>
|
||||
<priority value="42"/>
|
||||
</header-enricher>
|
||||
|
||||
<header-enricher input-channel="payloadExpressionInput">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,6 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.integration.gateway.SimpleMessagingGateway;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
@@ -127,7 +126,7 @@ public class HeaderEnricherTests {
|
||||
gateway.setRequestChannel(context.getBean("priorityInput", MessageChannel.class));
|
||||
Message<?> result = gateway.sendAndReceiveMessage("test");
|
||||
assertNotNull(result);
|
||||
assertEquals(MessagePriority.HIGH, result.getHeaders().getPriority());
|
||||
assertEquals(new Integer(42), result.getHeaders().getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -44,13 +43,13 @@ public class GatewayWithHeaderAnnotations {
|
||||
@Test // INT-1205
|
||||
public void priorityAsArgument() {
|
||||
TestService gateway = (TestService) applicationContext.getBean("gateway");
|
||||
String result = gateway.test("foo", MessagePriority.HIGH);
|
||||
assertEquals("fooHIGH", result);
|
||||
String result = gateway.test("foo", 99);
|
||||
assertEquals("foo99", result);
|
||||
}
|
||||
|
||||
|
||||
public static interface TestService {
|
||||
public String test(String str, @Header(MessageHeaders.PRIORITY) MessagePriority priority);
|
||||
public String test(String str, @Header(MessageHeaders.PRIORITY) int priority);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,6 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -120,18 +119,18 @@ public class MessageBuilderTests {
|
||||
@Test
|
||||
public void testPriority() {
|
||||
Message<Integer> importantMessage = MessageBuilder.withPayload(1)
|
||||
.setPriority(MessagePriority.HIGHEST).build();
|
||||
assertEquals(MessagePriority.HIGHEST, importantMessage.getHeaders().getPriority());
|
||||
.setPriority(123).build();
|
||||
assertEquals(new Integer(123), importantMessage.getHeaders().getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonDestructiveSet() {
|
||||
Message<Integer> message1 = MessageBuilder.withPayload(1)
|
||||
.setPriority(MessagePriority.HIGHEST).build();
|
||||
.setPriority(42).build();
|
||||
Message<Integer> message2 = MessageBuilder.fromMessage(message1)
|
||||
.setHeaderIfAbsent(MessageHeaders.PRIORITY, MessagePriority.LOW)
|
||||
.setHeaderIfAbsent(MessageHeaders.PRIORITY, 13)
|
||||
.build();
|
||||
assertEquals(MessagePriority.HIGHEST, message2.getHeaders().getPriority());
|
||||
assertEquals(new Integer(42), message2.getHeaders().getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user