Skip to content

Commit

Permalink
https://issues.apache.org/activemq/browse/AMQNET-248
Browse files Browse the repository at this point in the history
Fix issue with MessageID not getting converted to a String correctly.
  • Loading branch information
Timothy A. Bish committed May 4, 2010
1 parent 91717f2 commit f9ebf0a
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 189 deletions.
2 changes: 2 additions & 0 deletions src/main/csharp/Commands/BaseDataStructure.cs
Expand Up @@ -16,6 +16,7 @@
*/

using System;
using System.Text;
using Apache.NMS.Stomp.Protocol;

namespace Apache.NMS.Stomp.Commands
Expand Down Expand Up @@ -82,5 +83,6 @@ public virtual Object Clone()
// if we had any.
return this.MemberwiseClone();
}

}
}
51 changes: 50 additions & 1 deletion src/main/csharp/Commands/ConsumerId.cs
Expand Up @@ -24,6 +24,8 @@ public class ConsumerId : BaseDataStructure
{
public const byte ID_CONSUMERID = 122;

private string key;

private SessionId parentId = null;

string connectionId;
Expand All @@ -34,6 +36,43 @@ public ConsumerId()
{
}

public ConsumerId( string consumerKey )
{
this.key = consumerKey;

// We give the Connection ID the key for now so there's at least some
// data stored into the Id.
this.ConnectionId = consumerKey;

int idx = consumerKey.LastIndexOf(':');
if( idx >= 0 )
{
try
{
this.Value = Int32.Parse(consumerKey.Substring(idx + 1));
consumerKey = consumerKey.Substring(0, idx);
idx = consumerKey.LastIndexOf(':');
if (idx >= 0)
{
try
{
this.SessionId = Int32.Parse(consumerKey.Substring(idx + 1));
consumerKey = consumerKey.Substring(0, idx);
}
catch(Exception ex)
{
Tracer.Debug(ex.Message);
}
}
this.ConnectionId = consumerKey;
}
catch(Exception ex)
{
Tracer.Debug(ex.Message);
}
}
}

public ConsumerId( SessionId sessionId, long consumerId )
{
this.connectionId = sessionId.ConnectionId;
Expand All @@ -60,7 +99,12 @@ public override byte GetDataStructureType()
///
public override string ToString()
{
return ConnectionId + ":" + SessionId + ":" + Value;
if( key == null )
{
this.key = ConnectionId + ":" + SessionId + ":" + Value;
}

return key;
}

public SessionId ParentId
Expand Down Expand Up @@ -114,6 +158,11 @@ public override bool Equals(object that)

public virtual bool Equals(ConsumerId that)
{
if(this.key != null && that.key != null)
{
return this.key.Equals(that.key);
}

if(!Equals(this.ConnectionId, that.ConnectionId))
{
return false;
Expand Down
4 changes: 1 addition & 3 deletions src/main/csharp/Commands/Message.cs
Expand Up @@ -208,9 +208,7 @@ public string NMSMessageId
{
if(null != MessageId)
{
return MessageId.ProducerId.ConnectionId + ":" +
MessageId.ProducerId.SessionId + ":" +
MessageId.ProducerId.Value;
return MessageId.ToString();
}

return String.Empty;
Expand Down
2 changes: 1 addition & 1 deletion src/main/csharp/Commands/MessageId.cs
Expand Up @@ -62,7 +62,7 @@ public override byte GetDataStructureType()
///
public override string ToString()
{
if(key == null)
if( key == null )
{
key = producerId.ToString() + ":" + producerSequenceId;
}
Expand Down
36 changes: 30 additions & 6 deletions src/main/csharp/Commands/ProducerId.cs
Expand Up @@ -24,6 +24,8 @@ public class ProducerId : BaseDataStructure
{
private SessionId parentId;

private string key = null;

string connectionId;
long value;
long sessionId;
Expand All @@ -41,13 +43,30 @@ public ProducerId(SessionId sessionId, long consumerId)

public ProducerId(string producerKey)
{
// Parse off the producerId
int p = producerKey.LastIndexOf(":");
if(p >= 0)
// Store the original.
this.key = producerKey;

// Try and get back the AMQ version of the data.
int idx = producerKey.LastIndexOf(':');
if(idx >= 0)
{
value = Int64.Parse(producerKey.Substring(p + 1));
producerKey = producerKey.Substring(0, p);
try
{
this.Value = Int32.Parse(producerKey.Substring(idx + 1));
producerKey = producerKey.Substring(0, idx);
idx = producerKey.LastIndexOf(':');
if(idx >= 0)
{
this.SessionId = Int32.Parse(producerKey.Substring(idx + 1));
producerKey = producerKey.Substring(0, idx);
}
}
catch(Exception ex)
{
Tracer.Debug(ex.Message);
}
}
this.ConnectionId = producerKey;
}

///
Expand All @@ -69,7 +88,12 @@ public override byte GetDataStructureType()
///
public override string ToString()
{
return ConnectionId + ":" + SessionId + ":" + Value;
if( this.key == null )
{
this.key = ConnectionId + ":" + SessionId + ":" + Value;
}

return this.key;
}

public SessionId ParentId
Expand Down
153 changes: 0 additions & 153 deletions src/main/csharp/Protocol/StompHelper.cs
Expand Up @@ -26,30 +26,6 @@ namespace Apache.NMS.Stomp.Protocol
/// </summary>
public class StompHelper
{
private static int ParseInt(string text)
{
StringBuilder sbtext = new StringBuilder();

for(int idx = 0; idx < text.Length; idx++)
{
if(char.IsNumber(text, idx) || text[idx] == '-')
{
sbtext.Append(text[idx]);
}
else
{
break;
}
}

if(sbtext.Length > 0)
{
return Int32.Parse(sbtext.ToString());
}

return 0;
}

public static Destination ToDestination(string text)
{
if(text == null)
Expand Down Expand Up @@ -134,135 +110,6 @@ public static string ToStomp(AcknowledgementMode ackMode)
return "client";
}
}

public static string ToStomp(ConsumerId id)
{
return id.ConnectionId + ":" + id.SessionId + ":" + id.Value;
}

public static ConsumerId ToConsumerId(string text)
{
if(text == null)
{
return null;
}

ConsumerId answer = new ConsumerId();
int idx = text.LastIndexOf(':');
if (idx >= 0)
{
try
{
answer.Value = ParseInt(text.Substring(idx + 1));
text = text.Substring(0, idx);
idx = text.LastIndexOf(':');
if (idx >= 0)
{
try
{
answer.SessionId = ParseInt(text.Substring(idx + 1));
text = text.Substring(0, idx);
}
catch(Exception ex)
{
Tracer.Debug(ex.Message);
}
}
}
catch(Exception ex)
{
Tracer.Debug(ex.Message);
}
}
answer.ConnectionId = text;
return answer;
}

public static string ToStomp(ProducerId id)
{
StringBuilder producerBuilder = new StringBuilder();

producerBuilder.Append(id.ConnectionId);
producerBuilder.Append(":");
producerBuilder.Append(id.SessionId);
producerBuilder.Append(":");
producerBuilder.Append(id.Value);

return producerBuilder.ToString();
}

public static ProducerId ToProducerId(string text)
{
if(text == null)
{
return null;
}

ProducerId answer = new ProducerId();
int idx = text.LastIndexOf(':');
if(idx >= 0)
{
try
{
answer.Value = ParseInt(text.Substring(idx + 1));
text = text.Substring(0, idx);
idx = text.LastIndexOf(':');
if(idx >= 0)
{
answer.SessionId = ParseInt(text.Substring(idx + 1));
text = text.Substring(0, idx);
}
}
catch(Exception ex)
{
Tracer.Debug(ex.Message);
}
}
answer.ConnectionId = text;
return answer;
}

public static string ToStomp(MessageId id)
{
StringBuilder messageBuilder = new StringBuilder();

messageBuilder.Append(ToStomp(id.ProducerId));
messageBuilder.Append(":");
messageBuilder.Append(id.ProducerSequenceId);

return messageBuilder.ToString();
}

public static MessageId ToMessageId(string text)
{
if(text == null)
{
return null;
}

MessageId answer = new MessageId();
int idx = text.LastIndexOf(':');
if (idx >= 0)
{
try
{
answer.ProducerSequenceId = ParseInt(text.Substring(idx + 1));
text = text.Substring(0, idx);
}
catch(Exception ex)
{
Tracer.Debug(ex.Message);
}
}
answer.ProducerId = ToProducerId(text);

return answer;
}

public static string ToStomp(TransactionId id)
{
return id.ConnectionId.Value + ":" + id.Value;
}

public static bool ToBool(string text, bool defaultValue)
{
Expand Down

0 comments on commit f9ebf0a

Please sign in to comment.