2009-07-14 Michael Barker <mike@middlesoft.co.uk>
authorMichael Barker <mike@middlesoft.co.uk>
Tue, 14 Jul 2009 20:31:07 +0000 (20:31 -0000)
committerMichael Barker <mike@middlesoft.co.uk>
Tue, 14 Jul 2009 20:31:07 +0000 (20:31 -0000)
* RabbitMQMessageQueue.cs: Refactored, removed dead code and renamed methods.

svn path=/trunk/mcs/; revision=137897

mcs/class/Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/ChangeLog
mcs/class/Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/RabbitMQMessageQueue.cs

index e9c111dd57c85a594d34b6f3c5c6b19938c79a0e..c55a640041a0b9b4e5863006d7a5a2df894ece7f 100644 (file)
@@ -1,3 +1,7 @@
+2009-07-14  Michael Barker  <mike@middlesoft.co.uk>
+
+       * RabbitMQMessageQueue.cs: Refactored, removed dead code and renamed methods.
+
 2009-07-11  Michael Barker  <mike@middlesoft.co.uk>
 
        * MessageFactory.cs: Switched to DateTime.UtcNow.
index 03069f252ad13439387c841a38f1d57c6566ad6a..b2d1f2fc9b0ab2b5ea2b35870bbfc35e8fdaa480 100644 (file)
@@ -448,8 +448,11 @@ namespace Mono.Messaging.RabbitMQ {
                        return new RabbitMQMessageEnumerator (helper, QRef);
                }
                
+               private delegate IMessage RecieveDelegate (RabbitMQMessageQueue q,
+                                                          IModel model);
+               
                private IMessage Run (MessageQueueTransactionType transactionType,
-                                     TxReceiver.DoReceive r)
+                                     RecieveDelegate r)
                {
                        switch (transactionType) {
                        case MessageQueueTransactionType.Single:
@@ -474,8 +477,8 @@ namespace Mono.Messaging.RabbitMQ {
                        }
                }               
 
-               private IMessage Run (IMessageQueueTransaction transaction,
-                                     TxReceiver.DoReceive r)
+               private IMessage Run (IMessageQueueTransaction transaction, 
+                                     RecieveDelegate r)
                {
                        TxReceiver txr = new TxReceiver (this, r);
                        RabbitMQMessageQueueTransaction tx = 
@@ -483,7 +486,7 @@ namespace Mono.Messaging.RabbitMQ {
                        return tx.RunReceive (txr.ReceiveInContext);                    
                }
                
-               private IMessage Run (TxReceiver.DoReceive r)
+               private IMessage Run (RecieveDelegate r)
                {
                        ConnectionFactory cf = new ConnectionFactory ();
                        using (IConnection cn = cf.CreateConnection (QRef.Host)) {
@@ -493,39 +496,16 @@ namespace Mono.Messaging.RabbitMQ {
                        }
                }
                
-               private IMessage ReceiveInContext (ref string host, ref IConnection cn, 
-                                                  ref IModel model, string txId)
-               {
-                       if (host == null)
-                               host = QRef.Host;
-                       else if (host != QRef.Host)
-                               throw new MonoMessagingException ("Transactions can not span multiple hosts");
-                       
-                       if (cn == null) {
-                               ConnectionFactory cf = new ConnectionFactory ();
-                               cn = cf.CreateConnection (host);
-                       }
-                       
-                       if (model == null) {
-                               model = cn.CreateModel ();
-                               model.TxSelect ();
-                       }
-                       
-                       return Receive (model, -1, true);
-               }               
-
                private class TxReceiver
                {
-                       private readonly DoReceive doReceive;
+                       private readonly RecieveDelegate doReceive;
                        private readonly RabbitMQMessageQueue q;
                        
-                       public TxReceiver(RabbitMQMessageQueue q, DoReceive doReceive) {
+                       public TxReceiver(RabbitMQMessageQueue q, RecieveDelegate doReceive) {
                                this.q = q;
                                this.doReceive = doReceive;
                        }
-                       
-                       public delegate IMessage DoReceive (RabbitMQMessageQueue q, IModel model);
-                       
+                                               
                        public IMessage ReceiveInContext (ref string host, ref IConnection cn, 
                                                          ref IModel model, string txId)
                        {
@@ -548,18 +528,18 @@ namespace Mono.Messaging.RabbitMQ {
                        }
                }
                
-               private class DoReceiveWithTimeout
+               private class RecieveDelegateFactory
                {
                        private readonly int timeout;
                        private readonly IsMatch matcher;
                        private readonly bool ack;
                        
-                       public DoReceiveWithTimeout (int timeout, IsMatch matcher)
+                       public RecieveDelegateFactory (int timeout, IsMatch matcher)
                                : this (timeout, matcher, true)
                        {
                        }
                        
-                       public DoReceiveWithTimeout (int timeout, IsMatch matcher, bool ack)
+                       public RecieveDelegateFactory (int timeout, IsMatch matcher, bool ack)
                        {
                                if (matcher != null && timeout == -1)
                                        this.timeout = 500;
@@ -569,7 +549,7 @@ namespace Mono.Messaging.RabbitMQ {
                                this.ack = ack;
                        }
                        
-                       public IMessage DoReceive (RabbitMQMessageQueue q, IModel model)
+                       public IMessage RecieveDelegate (RabbitMQMessageQueue q, IModel model)
                        {
                                if (matcher == null)
                                        return q.Receive (model, timeout, ack);
@@ -578,49 +558,44 @@ namespace Mono.Messaging.RabbitMQ {
                        }
                }
                
-               private static TxReceiver.DoReceive Receiver (TimeSpan timeout,
-                                                             IsMatch matcher)
+               private static RecieveDelegate Receiver (TimeSpan timeout,
+                                                        IsMatch matcher)
                {
                        int to = MessageFactory.TimeSpanToInt32 (timeout);
-                       return new DoReceiveWithTimeout (to, matcher).DoReceive;
+                       return new RecieveDelegateFactory (to, matcher).RecieveDelegate;
                }
                
-               private static TxReceiver.DoReceive Receiver (IsMatch matcher)
+               private static RecieveDelegate Receiver (IsMatch matcher)
                {
-                       return new DoReceiveWithTimeout (-1, matcher).DoReceive;
+                       return new RecieveDelegateFactory (-1, matcher).RecieveDelegate;
                }
                
-               private static TxReceiver.DoReceive Receiver (TimeSpan timeout)
+               private static RecieveDelegate Receiver (TimeSpan timeout)
                {
                        int to = MessageFactory.TimeSpanToInt32 (timeout);
-                       return new DoReceiveWithTimeout (to, null).DoReceive;
+                       return new RecieveDelegateFactory (to, null).RecieveDelegate;
                }
 
-               private TxReceiver.DoReceive Receiver ()
-               {
-                       return new DoReceiveWithTimeout (-1, null).DoReceive;
-               }               
-               
-               private TxReceiver.DoReceive Peeker ()
+               private RecieveDelegate Receiver ()
                {
-                       return new DoReceiveWithTimeout (-1, null).DoReceive;
+                       return new RecieveDelegateFactory (-1, null).RecieveDelegate;
                }               
                
-               private TxReceiver.DoReceive Peeker (TimeSpan timeout)
+               private RecieveDelegate Peeker (TimeSpan timeout)
                {
                        int to = MessageFactory.TimeSpanToInt32 (timeout);
-                       return new DoReceiveWithTimeout (to, null, false).DoReceive;
+                       return new RecieveDelegateFactory (to, null, false).RecieveDelegate;
                }               
                
-               private TxReceiver.DoReceive Peeker (IsMatch matcher)
+               private RecieveDelegate Peeker (IsMatch matcher)
                {
-                       return new DoReceiveWithTimeout (-1, matcher, false).DoReceive;
+                       return new RecieveDelegateFactory (-1, matcher, false).RecieveDelegate;
                }               
                
-               private TxReceiver.DoReceive Peeker (TimeSpan timeout, IsMatch matcher)
+               private RecieveDelegate Peeker (TimeSpan timeout, IsMatch matcher)
                {
                        int to = MessageFactory.TimeSpanToInt32 (timeout);
-                       return new DoReceiveWithTimeout (to, matcher, false).DoReceive;
+                       return new RecieveDelegateFactory (to, matcher, false).RecieveDelegate;
                }
                
                delegate bool IsMatch (BasicDeliverEventArgs result);