public MessageBusInputChannel( BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent, EndpointAddress localAddress, IBus bus) : base(bufferManager, encoder, parent) { _localAddress = localAddress; _bus = bus; _aLock = new object(); _tryReceiveDelegate = (TimeSpan timeout, out Message message) => { message = null; try { var requestMessage = _bus.Receive(true, null); if (requestMessage != null) { message = GetWcfMessageFromString(requestMessage.Content); OnAfterTryReceive(requestMessage); } } catch (Exception ex) { throw new CommunicationException(ex.Message, ex); } return true; }; _receiveDelegate = (TimeSpan timeout) => { var requestMessage = _bus.Receive(false, ChannelID); return GetWcfMessageFromString(requestMessage.Content); }; }
public virtual IAsyncResult BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state) { if (CurrentAsyncResult != null) { throw new InvalidOperationException("Another async TryReceiveRequest operation is in progress"); } if (try_recv_delegate == null) { try_recv_delegate = new TryReceiveDelegate(delegate(TimeSpan tout, out RequestContext ctx) { lock (async_result_lock) { if (CurrentAsyncResult != null) { CurrentAsyncThread = Thread.CurrentThread; } } try { return(TryReceiveRequest(tout, out ctx)); } finally { lock (async_result_lock) { CurrentAsyncResult = null; CurrentAsyncThread = null; } } }); } RequestContext dummy; IAsyncResult result; lock (async_result_lock) { result = CurrentAsyncResult = try_recv_delegate.BeginInvoke(timeout, out dummy, callback, state); } // Note that at this point CurrentAsyncResult can be null here if delegate has run to completion return(result); }
public virtual IAsyncResult BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state) { if (CurrentAsyncResult != null) { throw new InvalidOperationException("Another async TryReceiveRequest operation is in progress"); } if (try_recv_delegate == null) { try_recv_delegate = new TryReceiveDelegate(delegate(TimeSpan tout, out RequestContext ctx) { if (CurrentAsyncResult != null) { CurrentAsyncThread = Thread.CurrentThread; } try { return(TryReceiveRequest(tout, out ctx)); } finally { CurrentAsyncResult = null; CurrentAsyncThread = null; } }); } RequestContext dummy; CurrentAsyncResult = try_recv_delegate.BeginInvoke(timeout, out dummy, callback, state); return(CurrentAsyncResult); }
public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state) { if (try_receive_delegate == null) { try_receive_delegate = new TryReceiveDelegate(TryReceive); } Message dummy; return(try_receive_delegate.BeginInvoke(timeout, out dummy, callback, state)); }
protected RabbitMQTaskQueueDuplexChannelBase(BindingContext context, ChannelManagerBase channelManager, RabbitMQTaskQueueBinding binding, EndpointAddress remoteAddress, EndpointAddress localAddress) : base(context, channelManager, binding, localAddress) { MethodInvocationTrace.Write(); _tryReceiveMethod = TryReceive; _receiveFunc = Receive; _waitForMsgFunc = WaitForMessage; _sendFunc = Send; _remoteAddress = remoteAddress; _closeOutputSessionFunc = CloseOutputSession; _remoteUri = (remoteAddress.Uri == EndpointAddress.AnonymousUri) ? null : new RabbitMQTaskQueueUri(remoteAddress.Uri.ToString()); }
public virtual IAsyncResult BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state) { if (CurrentAsyncResult != null) { throw new InvalidOperationException("Another async TryReceiveRequest operation is in progress"); } if (try_recv_delegate == null) { try_recv_delegate = new TryReceiveDelegate(delegate(TimeSpan tout, out RequestContext ctx) { lock (async_result_lock) { if (CurrentAsyncResult != null) { CurrentAsyncThread = Thread.CurrentThread; } } try { return(TryReceiveRequest(tout, out ctx)); } catch (XmlException ex) { Console.WriteLine("Xml Exception (Dropped Connection?):" + ex.Message); //on dropped connection, //whatever you do don't crash //the whole app. Ignore for now } catch (SocketException ex) { Console.WriteLine("Socket Exception (Dropped Connection?):" + ex.Message); //on dropped connection, //whatever you do don't crash //the whole app. Ignore for now } catch (IOException ex) { Console.WriteLine("I/O Exception (Dropped Connection?):" + ex.Message); //on dropped connection, //whatever you do don't crash //the whole app. Ignore for now } finally { lock (async_result_lock) { CurrentAsyncResult = null; CurrentAsyncThread = null; } } ctx = null; return(false); }); } RequestContext dummy; IAsyncResult result; lock (async_result_lock) { result = CurrentAsyncResult = try_recv_delegate.BeginInvoke(timeout, out dummy, callback, state); } // Note that at this point CurrentAsyncResult can be null here if delegate has run to completion return(result); }
public virtual IAsyncResult BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state) { IAsyncResult result = null; if (try_recv_delegate == null) { try_recv_delegate = new TryReceiveDelegate(delegate(TimeSpan tout, out RequestContext ctx) { lock (async_result_lock) { if (currentAsyncResults.Contains(result)) { currentAsyncThreads.Add(Thread.CurrentThread); } } try { return(TryReceiveRequest(tout, out ctx)); } catch (System.Xml.XmlException ex) { Console.WriteLine("Xml Exception (Dropped Connection?):" + ex.Message); } catch (System.Net.Sockets.SocketException ex) { Console.WriteLine("Socket Exception (Dropped Connection?):" + ex.Message); } catch (System.IO.IOException ex) { Console.WriteLine("I/O Exception (Dropped Connection?):" + ex.Message); } finally { lock (async_result_lock) { currentAsyncResults.Remove(result); currentAsyncThreads.Remove(Thread.CurrentThread); } } ctx = null; return(false); }); } RequestContext dummy; lock (async_result_lock) { result = try_recv_delegate.BeginInvoke(timeout, out dummy, callback, state); currentAsyncResults.Add(result); } return(result); }
public virtual IAsyncResult BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state) { IAsyncResult result = null; if (try_recv_delegate == null) { try_recv_delegate = new TryReceiveDelegate(delegate(TimeSpan tout, out RequestContext ctx) { lock (async_result_lock) { if (currentAsyncResults.Contains(result)) { currentAsyncThreads.Add(Thread.CurrentThread); } } try { return(TryReceiveRequest(tout, out ctx)); } catch (XmlException ex) { Console.WriteLine("Xml Exception (Dropped Connection?):" + ex.Message); //on dropped connection, //whatever you do don't crash //the whole app. Ignore for now } catch (SocketException ex) { Console.WriteLine("Socket Exception (Dropped Connection?):" + ex.Message); //on dropped connection, //whatever you do don't crash //the whole app. Ignore for now } catch (IOException ex) { Console.WriteLine("I/O Exception (Dropped Connection?):" + ex.Message); //on dropped connection, //whatever you do don't crash //the whole app. Ignore for now } finally { lock (async_result_lock) { currentAsyncResults.Remove(result); currentAsyncThreads.Remove(Thread.CurrentThread); } } ctx = null; return(false); }); } RequestContext dummy; lock (async_result_lock) { result = try_recv_delegate.BeginInvoke(timeout, out dummy, callback, state); currentAsyncResults.Add(result); } // Note that at this point result can be missing from currentAsyncResults here if delegate has run to completion return(result); }
public MessageBusDuplexChannel( BufferManager bufferManager, MessageEncoderFactory encoder, EndpointAddress remoteAddress, ChannelManagerBase parent, Uri via, IBus bus, bool isClient) : base(bufferManager, encoder, parent) { _serverAddress = remoteAddress; _via = via; _bus = bus; _isClient = isClient; _replyTos = new ConcurrentDictionary<UniqueId, string>(); _tryReceiveDelegate = (TimeSpan timeout, out Message message) => { message = null; try { // listen the message bus based on the sticky mode: // channel: only receive the message that reply to this channel's id // scaling gourp: receive the message the reply to this channel's id and the scaling group id of this channel var requestMessage = _bus.Receive(!_isClient, ChannelID); if (requestMessage != null) { message = GetWcfMessageFromString(requestMessage.Content); if (message.Headers.MessageId != null) { _replyTos.AddOrUpdate(message.Headers.MessageId, requestMessage.From, (key, value) => requestMessage.From); } OnAfterTryReceive(requestMessage); } } catch (Exception ex) { throw new CommunicationException(ex.Message, ex); } return true; }; }
public IAsyncResult BeginTryReceive (TimeSpan timeout, AsyncCallback callback, object state) { if (try_receive_delegate == null) try_receive_delegate = new TryReceiveDelegate (TryReceive); Message dummy; return try_receive_delegate.BeginInvoke (timeout, out dummy, callback, state); }