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:
}
}
- private IMessage Run (IMessageQueueTransaction transaction,
- TxReceiver.DoReceive r)
+ private IMessage Run (IMessageQueueTransaction transaction,
+ RecieveDelegate r)
{
TxReceiver txr = new TxReceiver (this, r);
RabbitMQMessageQueueTransaction tx =
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)) {
}
}
- 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)
{
}
}
- 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;
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);
}
}
- 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);