// ASSUMPTION: caller holds ThisLock private void RemoveFromTimedOutRequestList(ICorrelatorKey request) { Fx.Assert(request != null, "request cannot be null"); if (_timedOutRequests != null) { _timedOutRequests.Remove(request); } }
// This method is used to remove the request from the correlator table when the // reply is lost. This will avoid leaking the correlator table in cases where the // channel faults or aborts while there are pending requests. internal void RemoveRequest(ICorrelatorKey request) { Fx.Assert(request != null, "request cannot be null"); if (request.RequestCorrelatorKey != null) { lock (_states) { _states.Remove(request.RequestCorrelatorKey); } } }
void IRequestReplyCorrelator.Add <T>(Message request, T state) { UniqueId messageId = request.Headers.MessageId; Type stateType = typeof(T); Key key = new Key(messageId, stateType); // add the correlator key to the request, this will be needed for cleaning up the correlator table in case of // channel aborting or faulting while there are pending requests ICorrelatorKey value = state as ICorrelatorKey; if (value != null) { value.RequestCorrelatorKey = key; } lock (_states) { _states.Add(key, state); } }
void AbortRequests() { IDuplexRequest[] array = null; lock (ThisLock) { if (requests != null) { array = requests.ToArray(); foreach (IDuplexRequest request in array) { request.Abort(); } } requests = null; requestAborted = true; } // Remove requests from the correlator since the channel might be either faulting or aborting, // We are not going to get a reply for these requests. If they are not removed from the correlator, this will cause a leak. // This operation does not have to be under the lock if (array != null && array.Length > 0) { RequestReplyCorrelator requestReplyCorrelator = correlator as RequestReplyCorrelator; if (requestReplyCorrelator != null) { foreach (IDuplexRequest request in array) { ICorrelatorKey keyedRequest = request as ICorrelatorKey; if (keyedRequest != null) { requestReplyCorrelator.RemoveRequest(keyedRequest); } } } } //if there are any timed out requests, delete it from the correlator table DeleteTimedoutRequestsFromCorrelator(); }
// ASSUMPTION: caller holds ThisLock private void AddToTimedOutRequestList(ICorrelatorKey request) { Fx.Assert(request != null, "request cannot be null"); TimedOutRequests.Add(request); }