You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2008/08/06 21:03:53 UTC

svn commit: r683375 - in /activemq/activemq-dotnet: Apache.NMS.ActiveMQ/trunk/src/main/csharp/ Apache.NMS/trunk/src/main/csharp/ Apache.NMS/trunk/src/main/csharp/Util/

Author: jgomes
Date: Wed Aug  6 12:03:52 2008
New Revision: 683375

URL: http://svn.apache.org/viewvc?rev=683375&view=rev
Log:
Added requestTimeout to MessageProducer to  allow customization and direct control over broker timeouts.
Added new SessionUtils.cs for supporting embedded destination type specifiers.

Added:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs
Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IMessageProducer.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs?rev=683375&r1=683374&r2=683375&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs Wed Aug  6 12:03:52 2008
@@ -14,9 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-using Apache.NMS.ActiveMQ.Commands;
-using Apache.NMS;
+
 using System;
+using System.Threading;
+using Apache.NMS.ActiveMQ.Commands;
 
 namespace Apache.NMS.ActiveMQ
 {
@@ -32,6 +33,8 @@
 
 		private bool msgPersistent = NMSConstants.defaultPersistence;
 		private TimeSpan msgTimeToLive;
+		private TimeSpan requestTimeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
+		private bool specifiedRequestTimeout = false;
 		private readonly bool defaultSpecifiedTimeToLive = false;
 		private byte msgPriority = NMSConstants.defaultPriority;
 		private bool disableMessageID = false;
@@ -138,7 +141,7 @@
 			CheckClosed();
 			ActiveMQMessage activeMessage = (ActiveMQMessage) message;
 
-			if (!disableMessageID)
+			if(!disableMessageID)
 			{
 				MessageId id = new MessageId();
 				id.ProducerId = info.ProducerId;
@@ -155,13 +158,13 @@
 			activeMessage.NMSPersistent = persistent;
 			activeMessage.NMSPriority = priority;
 
-			if (session.Transacted)
+			if(session.Transacted)
 			{
 				session.DoStartTransaction();
 				activeMessage.TransactionId = session.TransactionContext.TransactionId;
 			}
 
-			if (!disableMessageTimestamp)
+			if(!disableMessageTimestamp)
 			{
 				activeMessage.NMSTimestamp = DateTime.UtcNow;
 			}
@@ -171,7 +174,18 @@
 				activeMessage.NMSTimeToLive = timeToLive;
 			}
 
-			session.DoSend(activeMessage);
+			TimeSpan timeout;
+
+			if(specifiedRequestTimeout)
+			{
+				timeout = this.requestTimeout;
+			}
+			else
+			{
+				timeout = session.Connection.ITransport.RequestTimeout;
+			}
+
+			session.DoSend(activeMessage, timeout);
 		}
 
 		public bool Persistent
@@ -186,6 +200,12 @@
 			set { this.msgTimeToLive = value; }
 		}
 
+		public TimeSpan RequestTimeout
+		{
+			get { return requestTimeout; }
+			set { this.requestTimeout = value; specifiedRequestTimeout = true; }
+		}
+
 		public byte Priority
 		{
 			get { return msgPriority; }

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs?rev=683375&r1=683374&r2=683375&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs Wed Aug  6 12:03:52 2008
@@ -440,7 +440,7 @@
 			Connection.SyncRequest(command);
 		}
 
-		public void DoSend(ActiveMQMessage message)
+		public void DoSend(ActiveMQMessage message, TimeSpan requestTimeout)
 		{
 			if(AsyncSend)
 			{
@@ -448,7 +448,7 @@
 			}
 			else
 			{
-				Connection.SyncRequest(message);
+				Connection.SyncRequest(message, requestTimeout);
 			}
 		}
 

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IMessageProducer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IMessageProducer.cs?rev=683375&r1=683374&r2=683375&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IMessageProducer.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IMessageProducer.cs Wed Aug  6 12:03:52 2008
@@ -47,6 +47,8 @@
 
 		TimeSpan TimeToLive { get; set; }
 
+		TimeSpan RequestTimeout { get; set; }
+
 		byte Priority { get; set; }
 
 		bool DisableMessageID { get; set; }

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs?rev=683375&r1=683374&r2=683375&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs Wed Aug  6 12:03:52 2008
@@ -86,6 +86,13 @@
 		void DeleteDurableConsumer(string name);
 
 		/// <summary>
+		/// Deletes a durable consumer created with CreateDurableConsumer().
+		/// </summary>
+		/// <param name="name">Name of the durable consumer</param>
+		/// <param name="requestTimeout">Timeout to wait for response from broker.</param>
+		void DeleteDurableConsumer(string name, TimeSpan requestTimeout);
+
+		/// <summary>
 		/// Returns the queue for the given name
 		/// </summary>
 		IQueue GetQueue(string name);

Added: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs?rev=683375&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs Wed Aug  6 12:03:52 2008
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+using System;
+
+namespace Apache.NMS.Util
+{
+	/// <summary>
+	/// Class to provide support for working with Session objects.
+	/// </summary>
+	public class SessionUtil
+	{
+		private static string QueuePrefix = "queue:";
+		private static string TopicPrefix = "topic:";
+		private static string TempQueuePrefix = "temp-queue:";
+		private static string TempTopicPrefix = "temp-topic:";
+
+		/// <summary>
+		/// Get the destination by parsing the embedded type prefix.  Default is Queue if no prefix is
+		/// embedded in the destinationName.
+		/// </summary>
+		/// <param name="session">Session object to use to get the destination.</param>
+		/// <param name="destinationName">Name of destination with embedded prefix.  The embedded prefix can be one of the following:
+		///		<list type="bullet">
+		///			<item>queue:</item>
+		///			<item>topic:</item>
+		///			<item>temp-queue:</item>
+		///			<item>temp-topic:</item>
+		///		</list>
+		///	</param>
+		/// <returns></returns>
+		public static IDestination GetDestinationByType(ISession session, string destinationName)
+		{
+			return SessionUtil.GetDestinationByType(session, destinationName, DestinationType.Queue);
+		}
+
+		/// <summary>
+		/// Get the destination by parsing the embedded type prefix.
+		/// </summary>
+		/// <param name="session">Session object to use to get the destination.</param>
+		/// <param name="destinationName">Name of destination with embedded prefix.  The embedded prefix can be one of the following:
+		///		<list type="bullet">
+		///			<item>queue:</item>
+		///			<item>topic:</item>
+		///			<item>temp-queue:</item>
+		///			<item>temp-topic:</item>
+		///		</list>
+		///	</param>
+		/// <param name="defaultType">Default type if no embedded prefix is specified.</param>
+		/// <returns></returns>
+		public static IDestination GetDestinationByType(ISession session, string destinationName, DestinationType defaultType)
+		{
+			IDestination destination = null;
+			DestinationType destinationType = defaultType;
+
+			if(destinationName.StartsWith(QueuePrefix, StringComparison.CurrentCultureIgnoreCase))
+			{
+				destinationType = DestinationType.Queue;
+				destinationName = destinationName.Substring(QueuePrefix.Length);
+			}
+			else if(destinationName.StartsWith(TopicPrefix, StringComparison.CurrentCultureIgnoreCase))
+			{
+				destinationType = DestinationType.Topic;
+				destinationName = destinationName.Substring(TopicPrefix.Length);
+			}
+			else if(destinationName.StartsWith(TempQueuePrefix, StringComparison.CurrentCultureIgnoreCase))
+			{
+				destinationType = DestinationType.TemporaryQueue;
+				destinationName = destinationName.Substring(TempQueuePrefix.Length);
+			}
+			else if(destinationName.StartsWith(TempTopicPrefix, StringComparison.CurrentCultureIgnoreCase))
+			{
+				destinationType = DestinationType.TemporaryTopic;
+				destinationName = destinationName.Substring(TempTopicPrefix.Length);
+			}
+
+			switch(destinationType)
+			{
+			case DestinationType.Queue:
+				destination = session.GetQueue(destinationName);
+			break;
+
+			case DestinationType.Topic:
+				destination = session.GetTopic(destinationName);
+			break;
+
+			case DestinationType.TemporaryQueue:
+				destination = session.CreateTemporaryQueue();
+			break;
+
+			case DestinationType.TemporaryTopic:
+				destination = session.CreateTemporaryTopic();
+			break;
+			}
+
+			return destination;
+		}
+
+		public static IQueue GetQueue(ISession session, string queueName)
+		{
+			return GetDestinationByType(session, queueName, DestinationType.Queue) as IQueue;
+		}
+
+		public static ITopic GetTopic(ISession session, string topicName)
+		{
+			return GetDestinationByType(session, topicName, DestinationType.Topic) as ITopic;
+		}
+	}
+}
+

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs?rev=683375&r1=683374&r2=683375&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs Wed Aug  6 12:03:52 2008
@@ -17,7 +17,6 @@
 using System;
 using System.Collections.Specialized;
 using System.Globalization;
-using System.Text;
 using System.Reflection;
 
 namespace Apache.NMS.Util