public virtual int GetPendingConfirmsCount(IPublisherCallbackChannel.IListener listener) { lock (_lock) { if (!_pendingConfirms.TryGetValue(listener, out var pendingConfirmsForListener)) { return(0); } else { return(pendingConfirmsForListener.Count); } } }
public virtual void AddPendingConfirm(IPublisherCallbackChannel.IListener listener, ulong sequence, PendingConfirm pendingConfirm) { lock (_lock) { if (!_pendingConfirms.TryGetValue(listener, out var pendingConfirmsForListener)) { throw new ArgumentException(nameof(listener)); } pendingConfirmsForListener[sequence] = pendingConfirm; _listenerForSeq[sequence] = listener; if (pendingConfirm.CorrelationInfo != null) { var returnCorrelation = pendingConfirm.CorrelationInfo.Id; if (!string.IsNullOrEmpty(returnCorrelation)) { _pendingReturns[returnCorrelation] = pendingConfirm; } } } }
public virtual IList <PendingConfirm> Expire(IPublisherCallbackChannel.IListener listener, long cutoffTime) { lock (_lock) { if (!_pendingConfirms.TryGetValue(listener, out var pendingConfirmsForListener)) { return(_emptyConfirms); } else { var expired = new List <PendingConfirm>(); var toRemove = new List <ulong>(); foreach (var kvp in pendingConfirmsForListener) { var pendingConfirm = kvp.Value; if (pendingConfirm.Timestamp < cutoffTime) { expired.Add(pendingConfirm); toRemove.Add(kvp.Key); var correlationData = pendingConfirm.CorrelationInfo; if (correlationData != null && !string.IsNullOrEmpty(correlationData.Id)) { _pendingReturns.Remove(correlationData.Id, out var _); // NOSONAR never null } } else { break; } } foreach (var key in toRemove) { pendingConfirmsForListener.Remove(key); } return(expired); } } }