Created
May 31, 2013 18:25
-
-
Save chirino/5686915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| commit 402ebb0ebc9c89b7c42febe282e05473b9a2482e | |
| Author: Hiram Chirino <hiram@hiramchirino.com> | |
| Date: Fri May 31 14:24:41 2013 -0400 | |
| Additional fix for AMQ-4563: Support storing the externally generated message id of a message in the MessageID class so that Selectors can operate against that external message id. | |
| diff --git a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java | |
| index 97a620a..a718a97 100644 | |
| --- a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java | |
| +++ b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java | |
| @@ -512,9 +512,10 @@ class AmqpProtocolConverter { | |
| message.setJMSDestination(destination); | |
| } | |
| message.setProducerId(producerId); | |
| - if (message.getMessageId() == null) { | |
| - message.setMessageId(new MessageId(producerId, messageIdGenerator.getNextSequenceId())); | |
| - } | |
| + | |
| + MessageId messageId = message.getMessageId(); | |
| + messageId.setProducerId(producerId); | |
| + messageId.setProducerSequenceId(messageIdGenerator.getNextSequenceId()); | |
| if (LOG.isTraceEnabled()) { | |
| LOG.trace("Inbound Message:{} from Producer:{}", message.getMessageId(), producerId); | |
| diff --git a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java | |
| index 151faac..e673d96 100755 | |
| --- a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java | |
| +++ b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java | |
| @@ -141,7 +141,7 @@ public class ActiveMQMessage extends Message implements org.apache.activemq.Mess | |
| // so lets set the IDs to be 1 | |
| MessageId id = new MessageId(); | |
| id.setTextView(value); | |
| - this.setMessageId(messageId); | |
| + this.setMessageId(id); | |
| } | |
| } else { | |
| this.setMessageId(null); | |
| diff --git a/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java b/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java | |
| index f1c7cbc..815211b 100755 | |
| --- a/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java | |
| +++ b/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java | |
| @@ -26,6 +26,7 @@ public class MessageId implements DataStructure, Comparable<MessageId> { | |
| public static final byte DATA_STRUCTURE_TYPE = CommandTypes.MESSAGE_ID; | |
| + protected String textView; | |
| protected ProducerId producerId; | |
| protected long producerSequenceId; | |
| protected long brokerSequenceId; | |
| @@ -69,6 +70,8 @@ public class MessageId implements DataStructure, Comparable<MessageId> { | |
| if (p >= 0) { | |
| producerSequenceId = Long.parseLong(messageKey.substring(p + 1)); | |
| messageKey = messageKey.substring(0, p); | |
| + } else { | |
| + throw new NumberFormatException(); | |
| } | |
| producerId = new ProducerId(messageKey); | |
| } | |
| @@ -79,9 +82,18 @@ public class MessageId implements DataStructure, Comparable<MessageId> { | |
| * accommodate foreign JMS message IDs | |
| */ | |
| public void setTextView(String key) { | |
| + this.textView = key; | |
| this.key = key; | |
| } | |
| + /** | |
| + * @openwire:property version=10 | |
| + * @return | |
| + */ | |
| + public String getTextView() { | |
| + return textView; | |
| + } | |
| + | |
| public byte getDataStructureType() { | |
| return DATA_STRUCTURE_TYPE; | |
| } | |
| @@ -111,7 +123,11 @@ public class MessageId implements DataStructure, Comparable<MessageId> { | |
| public String toString() { | |
| if (key == null) { | |
| - key = producerId.toString() + ":" + producerSequenceId; | |
| + if( textView!=null ) { | |
| + key = textView; | |
| + } else { | |
| + key = producerId.toString() + ":" + producerSequenceId; | |
| + } | |
| } | |
| return key; | |
| } | |
| diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/MessageIdMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/MessageIdMarshaller.java | |
| index ef5b685..cfa22c5 100644 | |
| --- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/MessageIdMarshaller.java | |
| +++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/MessageIdMarshaller.java | |
| @@ -66,6 +66,7 @@ public class MessageIdMarshaller extends BaseDataStreamMarshaller { | |
| super.tightUnmarshal(wireFormat, o, dataIn, bs); | |
| MessageId info = (MessageId)o; | |
| + info.setTextView(tightUnmarshalString(dataIn, bs)); | |
| info.setProducerId((org.apache.activemq.command.ProducerId) tightUnmarsalCachedObject(wireFormat, dataIn, bs)); | |
| info.setProducerSequenceId(tightUnmarshalLong(wireFormat, dataIn, bs)); | |
| info.setBrokerSequenceId(tightUnmarshalLong(wireFormat, dataIn, bs)); | |
| @@ -81,6 +82,7 @@ public class MessageIdMarshaller extends BaseDataStreamMarshaller { | |
| MessageId info = (MessageId)o; | |
| int rc = super.tightMarshal1(wireFormat, o, bs); | |
| + rc += tightMarshalString1(info.getTextView(), bs); | |
| rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getProducerId(), bs); | |
| rc+=tightMarshalLong1(wireFormat, info.getProducerSequenceId(), bs); | |
| rc+=tightMarshalLong1(wireFormat, info.getBrokerSequenceId(), bs); | |
| @@ -99,6 +101,7 @@ public class MessageIdMarshaller extends BaseDataStreamMarshaller { | |
| super.tightMarshal2(wireFormat, o, dataOut, bs); | |
| MessageId info = (MessageId)o; | |
| + tightMarshalString2(info.getTextView(), dataOut, bs); | |
| tightMarshalCachedObject2(wireFormat, (DataStructure)info.getProducerId(), dataOut, bs); | |
| tightMarshalLong2(wireFormat, info.getProducerSequenceId(), dataOut, bs); | |
| tightMarshalLong2(wireFormat, info.getBrokerSequenceId(), dataOut, bs); | |
| @@ -116,6 +119,7 @@ public class MessageIdMarshaller extends BaseDataStreamMarshaller { | |
| super.looseUnmarshal(wireFormat, o, dataIn); | |
| MessageId info = (MessageId)o; | |
| + info.setTextView(looseUnmarshalString(dataIn)); | |
| info.setProducerId((org.apache.activemq.command.ProducerId) looseUnmarsalCachedObject(wireFormat, dataIn)); | |
| info.setProducerSequenceId(looseUnmarshalLong(wireFormat, dataIn)); | |
| info.setBrokerSequenceId(looseUnmarshalLong(wireFormat, dataIn)); | |
| @@ -131,6 +135,7 @@ public class MessageIdMarshaller extends BaseDataStreamMarshaller { | |
| MessageId info = (MessageId)o; | |
| super.looseMarshal(wireFormat, o, dataOut); | |
| + looseMarshalString(info.getTextView(), dataOut); | |
| looseMarshalCachedObject(wireFormat, (DataStructure)info.getProducerId(), dataOut); | |
| looseMarshalLong(wireFormat, info.getProducerSequenceId(), dataOut); | |
| looseMarshalLong(wireFormat, info.getBrokerSequenceId(), dataOut); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment