Merged revision(s) 1689971 from activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.7.x: Fix exception being thrown when attempting to parse an ID that does not have an embedded ProducerSequenceId. Fixes [AMQNET-492]. (See https://issues.apache.org/jira/browse/AMQNET-492)
Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/commit/7c891b7e Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/tree/7c891b7e Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/diff/7c891b7e Branch: refs/heads/master Commit: 7c891b7e237d9ab7eb24f2016466dc20690d6663 Parents: 1081666 Author: Jim Gomes <jgo...@apache.org> Authored: Wed Jul 8 22:06:54 2015 +0000 Committer: Jim Gomes <jgo...@apache.org> Committed: Wed Jul 8 22:06:54 2015 +0000 ---------------------------------------------------------------------- src/main/csharp/Commands/MessageId.cs | 73 ++++++++++++++---------------- 1 file changed, 35 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/7c891b7e/src/main/csharp/Commands/MessageId.cs ---------------------------------------------------------------------- diff --git a/src/main/csharp/Commands/MessageId.cs b/src/main/csharp/Commands/MessageId.cs index b559bc3..dd7e202 100644 --- a/src/main/csharp/Commands/MessageId.cs +++ b/src/main/csharp/Commands/MessageId.cs @@ -21,20 +21,19 @@ namespace Apache.NMS.Stomp.Commands { public class MessageId : BaseDataStructure { - ProducerId producerId; - long producerSequenceId; - long brokerSequenceId; - + private ProducerId producerId; + private long producerSequenceId; + private long brokerSequenceId; private string key = null; public MessageId() : base() { } - public MessageId(ProducerId producerId, long producerSequenceId) : base() + public MessageId(ProducerId prodId, long producerSeqId) : base() { - this.producerId = producerId; - this.producerSequenceId = producerSequenceId; + this.producerId = prodId; + this.producerSequenceId = producerSeqId; } public MessageId(string value) : base() @@ -61,12 +60,12 @@ namespace Apache.NMS.Stomp.Commands /// public override string ToString() { - if( key == null ) + if(null == this.key) { - key = producerId.ToString() + ":" + producerSequenceId; + this.key = string.Format("{0}:{1}", this.producerId.ToString(), this.producerSequenceId); } - return key; + return this.key; } /// <summary> @@ -74,33 +73,42 @@ namespace Apache.NMS.Stomp.Commands /// </summary> public void SetValue(string messageKey) { - this.key = messageKey; + string mkey = messageKey; + + this.key = mkey; // Parse off the sequenceId - int p = messageKey.LastIndexOf(":"); + int p = mkey.LastIndexOf(":"); if(p >= 0) { - producerSequenceId = Int64.Parse(messageKey.Substring(p + 1)); - messageKey = messageKey.Substring(0, p); + if(Int64.TryParse(mkey.Substring(p + 1), out this.producerSequenceId)) + { + mkey = mkey.Substring(0, p); + } + else + { + this.producerSequenceId = 0; + } } - producerId = new ProducerId(messageKey); + + producerId = new ProducerId(mkey); } public ProducerId ProducerId { - get { return producerId; } + get { return this.producerId; } set { this.producerId = value; } } public long ProducerSequenceId { - get { return producerSequenceId; } + get { return this.producerSequenceId; } set { this.producerSequenceId = value; } } public long BrokerSequenceId { - get { return brokerSequenceId; } + get { return this.brokerSequenceId; } set { this.brokerSequenceId = value; } } @@ -108,9 +116,9 @@ namespace Apache.NMS.Stomp.Commands { int answer = 0; - answer = (answer * 37) + HashCode(ProducerId); - answer = (answer * 37) + HashCode(ProducerSequenceId); - answer = (answer * 37) + HashCode(BrokerSequenceId); + answer = (answer * 37) + HashCode(this.ProducerId); + answer = (answer * 37) + HashCode(this.ProducerSequenceId); + answer = (answer * 37) + HashCode(this.BrokerSequenceId); return answer; } @@ -121,26 +129,15 @@ namespace Apache.NMS.Stomp.Commands { return Equals((MessageId) that); } + return false; } public virtual bool Equals(MessageId that) { - if(!Equals(this.ProducerId, that.ProducerId)) - { - return false; - } - if(!Equals(this.ProducerSequenceId, that.ProducerSequenceId)) - { - return false; - } - if(!Equals(this.BrokerSequenceId, that.BrokerSequenceId)) - { - return false; - } - - return true; + return (Equals(this.ProducerId, that.ProducerId) + && Equals(this.ProducerSequenceId, that.ProducerSequenceId) + && Equals(this.BrokerSequenceId, that.BrokerSequenceId)); } - }; -} - + } +} \ No newline at end of file