public void DispatchChannelAvailabilityChecked(IDispatchChannel <TKey> channel, DispatcherAvailability availability) { string message = string.Format(MonitorMessages.ChannelAvailabilityChecked, DateTime.Now.ToLongTimeString(), channel.DeliveryType, availability); Trace.WriteLine(message); }
/// <summary> /// Find DispatchChannel matching a signal. /// </summary> /// <param name="signal"></param> /// <returns></returns> public virtual IDispatchChannel <TKey> Match(SignalDispatch <TKey> signal) { IDispatchChannel <TKey> channel = _channels.FirstOrDefault( p => p.DeliveryType == signal.DeliveryType); if (channel == null) { _logger.LogError(SenderInternalMessages.Common_NoServiceWithKeyFound, typeof(IDispatchChannel <TKey>), nameof(IDispatchChannel <TKey> .DeliveryType), signal.DeliveryType); } if (!channel.IsActive || channel.AvailableLimitCapacity == 0) { _logger.LogError(SenderInternalMessages.DispatchChannelRegistry_InactiveChannelRequested, signal.DeliveryType, channel.AvailableLimitCapacity); return(null); } return(channel); }
//methods public virtual bool Execute(SignalWrapper <SignalDispatch <TKey> > item) { //find Dispatcher by deliveryType IDispatchChannel <TKey> channel = _channelRegistry.Match(item.Signal); if (channel == null) { _dispatchQueue.ApplyResult(item, ProcessingResult.NoHandlerFound); return(false); } //send with dispatcher ProcessingResult sendResult = ProcessingResult.Fail; Stopwatch sendTimer = Stopwatch.StartNew(); try { sendResult = channel.Send(item.Signal); } catch (Exception ex) { _logger.LogError(ex, null); } sendTimer.Stop(); //check dispatcher availability DispatcherAvailability availability = CheckAvailability(channel, sendResult); if (sendResult == ProcessingResult.Fail && availability == DispatcherAvailability.NotAvailable) { sendResult = ProcessingResult.Repeat; } _monitor.DispatchSent(item.Signal, sendResult, sendTimer.Elapsed); channel.CountSendAttempt(item.Signal, sendResult, availability); _dispatchQueue.ApplyResult(item, sendResult); return(sendResult == ProcessingResult.Success); }
protected virtual DispatcherAvailability CheckAvailability(IDispatchChannel <TKey> channel, ProcessingResult sendResult) { if (sendResult != ProcessingResult.Fail) { return(DispatcherAvailability.NotChecked); } DispatcherAvailability availability; try { availability = channel.CheckAvailability(); } catch (Exception ex) { availability = DispatcherAvailability.NotAvailable; _logger.LogError(ex, null); } channel.CountAvailabilityCheck(availability); _monitor.DispatchChannelAvailabilityChecked(channel, availability); return(availability); }
public void DispatchChannelAvailabilityChecked(IDispatchChannel <TKey> channel, DispatcherAvailability availability) { Console.WriteLine(MonitorMessages.ChannelAvailabilityChecked, DateTime.Now.ToLongTimeString(), channel.DeliveryType, availability); }