diff --git a/src/CoCoL.Network/NetworkClientConnector.cs b/src/CoCoL.Network/NetworkClientConnector.cs index 1ecc29c..3d282df 100644 --- a/src/CoCoL.Network/NetworkClientConnector.cs +++ b/src/CoCoL.Network/NetworkClientConnector.cs @@ -247,7 +247,7 @@ await nwc.WriteAsync(new PendingNetworkRequest( case NetworkMessageType.RetiredResponse: lock (m_lock) m_pendingRequests[req.ChannelID].Remove(req.RequestID); - TrySetException(prq.Task, new RetiredException()); + TrySetException(prq.Task, new RetiredException(req.AssociatedChannel?.Name)); break; case NetworkMessageType.TimeoutResponse: lock (m_lock) diff --git a/src/CoCoL/Channel.cs b/src/CoCoL/Channel.cs index 230ff98..d08aa14 100644 --- a/src/CoCoL/Channel.cs +++ b/src/CoCoL/Channel.cs @@ -420,7 +420,7 @@ public async Task ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null) { if (m_isRetired) { - ThreadPool.QueueItem(() => rd.Source.SetException(new RetiredException())); + ThreadPool.QueueItem(() => rd.Source.SetException(new RetiredException(this.Name))); return await rd.Source.Task; } @@ -446,7 +446,7 @@ public async Task ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null) { var exp = m_readerQueue[0].Source; m_readerQueue.RemoveAt(0); - ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); + ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name))); } break; @@ -454,7 +454,7 @@ public async Task ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null) { var exp = m_readerQueue[m_readerQueue.Count - 2].Source; m_readerQueue.RemoveAt(m_readerQueue.Count - 2); - ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); + ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name))); } break; @@ -463,7 +463,7 @@ public async Task ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null) { var exp = m_readerQueue[m_readerQueue.Count - 1].Source; m_readerQueue.RemoveAt(m_readerQueue.Count - 1); - ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); + ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name))); await rd.Source.Task; } @@ -498,7 +498,7 @@ public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer = n { if (m_isRetired) { - ThreadPool.QueueItem(() => wr.Source.SetException(new RetiredException())); + ThreadPool.QueueItem(() => wr.Source.SetException(new RetiredException(this.Name))); await wr.Source.Task; return; } @@ -544,7 +544,7 @@ public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer = n var exp = m_writerQueue[m_bufferSize].Source; m_writerQueue.RemoveAt(m_bufferSize); if (exp != null) - ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); + ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name))); } break; @@ -553,7 +553,7 @@ public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer = n var exp = m_writerQueue[m_writerQueue.Count - 2].Source; m_writerQueue.RemoveAt(m_writerQueue.Count - 2); if (exp != null) - ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); + ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name))); } break; @@ -563,7 +563,7 @@ public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer = n var exp = m_writerQueue[m_writerQueue.Count - 1].Source; m_writerQueue.RemoveAt(m_writerQueue.Count - 1); if (exp != null) - ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); + ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name))); await wr.Source.Task; } @@ -692,7 +692,7 @@ private async Task RetireAsync(bool immediate, bool isLocked) while (m_retireCount > 1) { if (m_writerQueue[0].Source != null) - m_writerQueue[0].Source.TrySetException(new RetiredException()); + m_writerQueue[0].Source.TrySetException(new RetiredException(this.Name)); m_writerQueue.RemoveAt(0); m_retireCount--; } @@ -712,7 +712,7 @@ public virtual async Task JoinAsync(bool asReader) { // Do not allow anyone to join after we retire the channel if (m_isRetired) - throw new RetiredException(); + throw new RetiredException(this.Name); if (asReader) m_joinedReaderCount++; @@ -780,12 +780,12 @@ private async Task EmptyQueueIfRetiredAsync(bool isLocked) { if (readers != null) foreach (var r in readers) - ThreadPool.QueueItem(() => r.Source.TrySetException(new RetiredException())); + ThreadPool.QueueItem(() => r.Source.TrySetException(new RetiredException(this.Name))); if (writers != null) foreach (var w in writers) if (w.Source != null) - ThreadPool.QueueItem(() => w.Source.TrySetException(new RetiredException())); + ThreadPool.QueueItem(() => w.Source.TrySetException(new RetiredException(this.Name))); } } diff --git a/src/CoCoL/Exceptions.cs b/src/CoCoL/Exceptions.cs index 8ea853d..0b1ebab 100644 --- a/src/CoCoL/Exceptions.cs +++ b/src/CoCoL/Exceptions.cs @@ -13,23 +13,31 @@ namespace CoCoL #endif public class RetiredException : Exception { + /// + /// The name of the channel that is retired + /// + public readonly string ChannelName; + /// /// Initializes a new instance of the class. /// - public RetiredException() : base("The channel is retired") {} + /// The name of the channel + public RetiredException(string channelname) : base($"The channel \"{channelname}\" is retired") { ChannelName = channelname; } /// /// Initializes a new instance of the class. /// /// The error message. - public RetiredException(string message) : base(message) {} + /// The name of the channel + public RetiredException(string channelname, string message) : base(message) { ChannelName = channelname; } /// /// Initializes a new instance of the class. /// /// The error message. /// The inner exception. - public RetiredException(string message, Exception ex) : base(message, ex) {} + /// The name of the channel + public RetiredException(string channelname, string message, Exception ex) : base(message, ex) { ChannelName = channelname; } #if !DISABLE_SERIALIZATION /// /// Initializes a new instance of the class. @@ -48,23 +56,31 @@ public RetiredException(SerializationInfo info, StreamingContext context) : base #endif public class ChannelOverflowException : Exception { + /// + /// The name of the channel that is overflown + /// + public readonly string ChannelName; + /// /// Initializes a new instance of the class. /// - public ChannelOverflowException() : base("The channel has too many pending operations") {} + /// The name of the channel + public ChannelOverflowException(string channelname) : base($"The channel \"{channelname}\" has too many pending operations") { ChannelName = channelname; } /// /// Initializes a new instance of the class. /// /// The error message. - public ChannelOverflowException(string message) : base(message) {} + /// The name of the channel + public ChannelOverflowException(string message, string channelname) : base(message) { ChannelName = channelname; } /// /// Initializes a new instance of the class. /// /// The error message. /// The inner exception. - public ChannelOverflowException(string message, Exception ex) : base(message, ex) {} + /// The name of the channel + public ChannelOverflowException(string channelname, string message, Exception ex) : base(message, ex) { ChannelName = channelname; } #if !DISABLE_SERIALIZATION /// /// Initializes a new instance of the class.