activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r759401 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
Date Sat, 28 Mar 2009 00:06:15 GMT
Author: jgomes
Date: Sat Mar 28 00:06:15 2009
New Revision: 759401

URL: http://svn.apache.org/viewvc?rev=759401&view=rev
Log:
Fix TimeToLive calculation.  When the timestamp of the message is changed, then the TimeToLive
offset is used to recalculate the Expiration time.
Added null checking for getting the NMSMessageId.

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs?rev=759401&r1=759400&r2=759401&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
Sat Mar 28 00:06:15 2009
@@ -41,6 +41,11 @@
 		// TODO generate Equals method
 		// TODO generate GetHashCode method
 
+		public ActiveMQMessage()
+				: base()
+		{
+			Timestamp = DateUtils.ToJavaTimeUtc(DateTime.UtcNow);
+		}
 
 		public override byte GetDataStructureType()
 		{
@@ -98,27 +103,23 @@
 			get { return Destination; }
 		}
 
-		private long expirationBaseTime = 0;
+		private TimeSpan timeToLive = TimeSpan.FromMilliseconds(0);
 		/// <summary>
 		/// The time in milliseconds that this message should expire in
 		/// </summary>
 		public TimeSpan NMSTimeToLive
 		{
-			get
-			{
-				return TimeSpan.FromMilliseconds(Expiration - expirationBaseTime);
-			}
+			get { return timeToLive; }
 
 			set
 			{
-				if(0 != value.TotalMilliseconds)
+				timeToLive = value;
+				if(timeToLive.TotalMilliseconds > 0)
 				{
-					expirationBaseTime = DateUtils.ToJavaTimeUtc(DateTime.UtcNow);
-					Expiration = expirationBaseTime + (long) Math.Abs(value.TotalMilliseconds);
+					Expiration = Timestamp + (long) timeToLive.TotalMilliseconds;
 				}
 				else
 				{
-					expirationBaseTime = 0;
 					Expiration = 0;
 				}
 			}
@@ -129,7 +130,15 @@
 		/// </summary>
 		public string NMSMessageId
 		{
-			get { return BaseDataStreamMarshaller.ToString(MessageId); }
+			get
+			{
+				if(null != MessageId)
+				{
+					return BaseDataStreamMarshaller.ToString(MessageId);
+				}
+
+				return String.Empty;
+			}
 		}
 
 		/// <summary>
@@ -173,7 +182,14 @@
 		public DateTime NMSTimestamp
 		{
 			get { return DateUtils.ToDateTime(Timestamp); }
-			set { Timestamp = DateUtils.ToJavaTimeUtc(value); }
+			set
+			{
+				Timestamp = DateUtils.ToJavaTimeUtc(value);
+				if(timeToLive.TotalMilliseconds > 0)
+				{
+					Expiration = Timestamp + (long) timeToLive.TotalMilliseconds;
+				}
+			}
 		}
 
 		/// <summary>
@@ -232,7 +248,7 @@
 					return BaseDataStreamMarshaller.ToString(txnId);
 				}
 
-				return null;
+				return String.Empty;
 			}
 		}
 



Mime
View raw message