Hi,

Small patch that adds some comments and allows dynamic initialisation
of MessagingProviders by specifying the MONO_MESSAGING_PROVIDER
environment variable.

Please review.

Regards,
Michael Barker.
Index: Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/ChangeLog
===================================================================
--- Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/ChangeLog	(revision 134381)
+++ Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/ChangeLog	(working copy)
@@ -54,3 +54,8 @@
 
 	* BasicMessagingTest.cs: New
 	* RabbitMQMessagingProviderTest.cs: New
+	
+2009-05-19  Michael Barker  <m...@middlesoft.co.uk>
+
+	* RabbitMQMessagingProviderTest.cs: Added test for dynamic create of 
+	MessagingProvider
Index: Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/RabbitMQMessagingProviderTest.cs
===================================================================
--- Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/RabbitMQMessagingProviderTest.cs	(revision 134381)
+++ Mono.Messaging.RabbitMQ/Test/Mono.Messaging.RabbitMQ/RabbitMQMessagingProviderTest.cs	(working copy)
@@ -56,5 +56,12 @@
 			Assert.IsNotNull (q);   
 		}
 		
+		[Test]
+		public void GetProvider ()
+		{
+			IMessagingProvider p = MessagingProviderLocator.GetProvider ();
+			Assert.IsNotNull (p);
+		}
+		
 	}
 }
Index: Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/RabbitMQMessageQueue.cs
===================================================================
--- Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/RabbitMQMessageQueue.cs	(revision 134381)
+++ Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/RabbitMQMessageQueue.cs	(working copy)
@@ -43,6 +43,11 @@
 
 namespace Mono.Messaging.RabbitMQ {
 
+	/// <summary>
+	/// RabbitMQ Implementation of a message queue.  Currrently this implementation
+	/// attempts to be as stateless as possible.  Connection the AMQP server
+	/// are only created as needed.
+	/// </summary>
 	public class RabbitMQMessageQueue : MessageQueueBase, IMessageQueue {
 		
 		private bool authenticate = false;
Index: Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/ChangeLog
===================================================================
--- Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/ChangeLog	(revision 134381)
+++ Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/ChangeLog	(working copy)
@@ -43,4 +43,8 @@
 2008-09-29  Michael Barker  <m...@middlesoft.co.uk>
 
 	* RabbitMQMessageQueue.cs: New
-	* RabbitMQMessagingProvider.cs: New
\ No newline at end of file
+	* RabbitMQMessagingProvider.cs: New
+	
+2009-05-19  Michael Barker  <m...@middlesoft.co.uk>
+
+	* RabbitMQMessageQueue.cs: Added comments.
\ No newline at end of file
Index: Mono.Messaging.RabbitMQ/ChangeLog
===================================================================
--- Mono.Messaging.RabbitMQ/ChangeLog	(revision 134381)
+++ Mono.Messaging.RabbitMQ/ChangeLog	(working copy)
@@ -7,3 +7,7 @@
 2008-09-29  Michael Barker  <m...@middlesoft.co.uk>
 
 	* AssemblyInfo.cs: New
+
+2009-05-19  Michael Barker  <m...@middlesoft.co.uk>
+
+	* Makefile:  Added environment variable for the RabbitMQMessagingProvider
\ No newline at end of file
Index: Mono.Messaging.RabbitMQ/Makefile
===================================================================
--- Mono.Messaging.RabbitMQ/Makefile	(revision 134381)
+++ Mono.Messaging.RabbitMQ/Makefile	(working copy)
@@ -12,3 +12,5 @@
 	/r:nunit.mocks.dll
 
 include ../../build/library.make
+
+export MONO_MESSAGING_PROVIDER=Mono.Messaging.RabbitMQ.RabbitMQMessagingProvider,Mono.Messaging.RabbitMQ
\ No newline at end of file
Index: Mono.Messaging/Test/Mono.Messaging/MessageBaseTest.cs
===================================================================
--- Mono.Messaging/Test/Mono.Messaging/MessageBaseTest.cs	(revision 134381)
+++ Mono.Messaging/Test/Mono.Messaging/MessageBaseTest.cs	(working copy)
@@ -30,6 +30,8 @@
 
 using System;
 using System.Messaging;
+using System.Reflection;
+using Mono.Messaging;
 
 using NUnit.Framework;
 
@@ -41,7 +43,19 @@
 		[Test]
 		public void CheckDefaultValues ()
 		{
-			Message m = new Message ();
+            Type[] types = { 
+                typeof (IMessage), typeof (object), typeof (IMessageFormatter)
+            };
+                
+            ConstructorInfo ci = typeof (Message).GetConstructor (
+                BindingFlags.NonPublic | BindingFlags.Instance, 
+                Type.DefaultBinder, types, new ParameterModifier[0]);
+                
+            if (ci == null)
+                throw new Exception ("ConstructorInfo is null");
+            
+            Message m = (Message) ci.Invoke (new object[] { new MessageBase (), null, null });
+			
 			Assert.IsNull (m.Body, "Body default should be Null");
 			Assert.IsNull (m.Formatter, "Formatter default should null");
 			
@@ -75,7 +89,7 @@
 			Assert.AreEqual ("", m.Label, "Label should default to \"\"");
 			Assert.AreEqual (false, m.IsFirstInTransaction, "IsFirstInTransaction should default to false");
 			Assert.AreEqual (false, m.IsLastInTransaction, "IsLastInTransaction should default to false");
-			Assert.AreEqual (MessagePriority.Normal, m.Priority,
+			Assert.AreEqual (System.Messaging.MessagePriority.Normal, m.Priority,
 					"Priority should default to Normal");
 			Assert.AreEqual (false, m.Recoverable, "Recoverable should default to false");
 			Assert.AreEqual (null, m.ResponseQueue, "ResponseQueue should default to null");
@@ -95,6 +109,5 @@
 					"UseJournalQueue should default to false");
 			Assert.AreEqual (false, m.UseTracing, "UseTracing should default to false");
 		}
-		
 	}
 }
Index: Mono.Messaging/Test/Mono.Messaging/ChangeLog
===================================================================
--- Mono.Messaging/Test/Mono.Messaging/ChangeLog	(revision 134381)
+++ Mono.Messaging/Test/Mono.Messaging/ChangeLog	(working copy)
@@ -2,3 +2,7 @@
 
 	* MessageBaseTest.cs: New
 	* QueueReferenceTest.cs: New
+
+2009-05-19  Michael Barker  <m...@middlesoft.co.uk>
+
+	* MessageBaseTest.cs: Used reflection to create Message Object
\ No newline at end of file
Index: Mono.Messaging/Mono.Messaging/MessagingProviderLocator.cs
===================================================================
--- Mono.Messaging/Mono.Messaging/MessagingProviderLocator.cs	(revision 134381)
+++ Mono.Messaging/Mono.Messaging/MessagingProviderLocator.cs	(working copy)
@@ -29,37 +29,55 @@
 //
 using System;
 using System.Reflection;
+using System.Collections;
 
 namespace Mono.Messaging 
 {
+	/// <summary>
+	/// The main entry point for System.Messaging to get a handle on the 
+	/// messaging implementation.  It will maintain a single instance of the 
+	/// IMessagingProvider (i.e. a singleton) that will be shared between
+	/// threads, therefore any implementation of the IMessagingProvider must
+	/// be thread safe.
+	/// </summary>
 	public class MessagingProviderLocator 
 	{
-		private static IMessagingProvider provider = null;
-		private static readonly object syncObj = new object();
 		public static readonly TimeSpan InfiniteTimeout = TimeSpan.MaxValue;
-	
+		
+		private static MessagingProviderLocator instance = new MessagingProviderLocator();		
+		private readonly object syncObj = new object();
+		private IMessagingProvider provider = null;
+		
+		private MessagingProviderLocator () {
+			string providerName = System.Environment.GetEnvironmentVariable("MONO_MESSAGING_PROVIDER");
+			if (providerName == null || providerName == "")
+				throw new Exception("Environment Variable MONO_MESSAGING_PROVIDER not defined");
+			provider = CreateProvider (providerName);
+		}
+		
+		public static MessagingProviderLocator Instance { get { return instance; } }
+		
 		public static IMessagingProvider GetProvider ()
 		{
-			//Assembly a = Assembly.Load("Mono.Messaging.RabbitMQ.dll");
-			//Type[] ts = a.GetTypes ();
+			return Instance.provider;
+		}
+		
+		private IMessagingProvider CreateProvider (string className)
+		{
+			Type t = Type.GetType (className);
+			if (t == null)
+				throw new Exception ("Can't find class: " + className);
 			
-			//foreach (type in ts)
-			//	Console.WriteLine (type.GetName ());
-			lock (syncObj) {
-				if (provider == null) {
-					Type t = Type.GetType ("Mono.Messaging.RabbitMQ.RabbitMQMessagingProvider, Mono.Messaging.RabbitMQ");
-					if (t == null)
-						throw new Exception ("Can't find class");
-					ConstructorInfo ci = t.GetConstructor (
-						BindingFlags.Public | BindingFlags.Instance, 
-								Type.DefaultBinder, new Type[0],
-								new ParameterModifier[0]);
-					if (ci == null)
-						throw new Exception ("Can't find constructor");
-					provider = (IMessagingProvider) ci.Invoke (new object[0]);
-				}
-			}
-			return provider;
+			ConstructorInfo ci = t.GetConstructor (BindingFlags.Public | 
+			                                       BindingFlags.Instance,
+			                                       Type.DefaultBinder,
+			                                       new Type[0],
+			                                       new ParameterModifier[0]);
+			if (ci == null)
+				throw new Exception ("Can't find constructor");
+			
+			return (IMessagingProvider) ci.Invoke (new object[0]);
 		}
+		
 	}
 }
Index: Mono.Messaging/Mono.Messaging/ChangeLog
===================================================================
--- Mono.Messaging/Mono.Messaging/ChangeLog	(revision 134381)
+++ Mono.Messaging/Mono.Messaging/ChangeLog	(working copy)
@@ -68,3 +68,10 @@
 	* MessagingProviderLocator.cs: New
 	* MonoMessagingException.cs: New
 	* QueueReference.cs: New
+
+2009-05-19  Michael Barker  <m...@middlesoft.co.uk>
+
+	* IMessage.cs: Added additional comments.
+	* IMessagingProvider.cs: Added additional comments.
+	* MessagingProviderLocator.cs: Added support for specifing messaging
+	implementation using an environment variable.
\ No newline at end of file
Index: Mono.Messaging/Mono.Messaging/IMessage.cs
===================================================================
--- Mono.Messaging/Mono.Messaging/IMessage.cs	(revision 134381)
+++ Mono.Messaging/Mono.Messaging/IMessage.cs	(working copy)
@@ -200,6 +200,11 @@
 			get; set;
 		}
 		
+		/// <summary>
+		/// Sets all of the information about a message after is has been
+		/// delivered.  Implementing classes should set the values of the
+		/// appropriate properties in this method call.
+		/// </summary>
 		void SetDeliveryInfo (Acknowledgment acknowledgment,
                               DateTime arrivedTime,
                               IMessageQueue destinationQueue,
Index: Mono.Messaging/Mono.Messaging/IMessagingProvider.cs
===================================================================
--- Mono.Messaging/Mono.Messaging/IMessagingProvider.cs	(revision 134381)
+++ Mono.Messaging/Mono.Messaging/IMessagingProvider.cs	(working copy)
@@ -30,6 +30,11 @@
 
 namespace Mono.Messaging {
 
+	/// <summary>
+	/// Provides access to the core implementation classes.  A single instance of
+	/// this class will be maintained by the MessagingProviderLocator, therefore
+	/// any implementations of this class must be thread safe.
+	/// </summary>
 	public interface IMessagingProvider {
 		
 		bool Exists (QueueReference qRef);
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to