public void DeleteMessage(MsmqReceiveContext receiveContext, TimeSpan timeout) { TimeoutHelper helper = new TimeoutHelper(timeout); long lookupId = receiveContext.LookupId; lock (this.internalStateLock) { if (!this.messageExpiryMap.ContainsKey(lookupId)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MessageValidityExpired", new object[] { lookupId }))); } MsmqReceiveContext item = this.messageExpiryMap[lookupId]; if (DateTime.UtcNow > item.ExpiryTime) { item.MarkContextExpired(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MessageValidityExpired", new object[] { lookupId }))); } ((ILockingQueue)this.queue).DeleteMessage(lookupId, helper.RemainingTime()); if (Transaction.Current != null) { List <MsmqReceiveContext> list; if (!this.transMessages.TryGetValue(Transaction.Current.TransactionInformation.DistributedIdentifier, out list)) { list = new List <MsmqReceiveContext>(); this.transMessages.Add(Transaction.Current.TransactionInformation.DistributedIdentifier, list); Transaction.Current.TransactionCompleted += this.transactionCompletedHandler; } list.Add(item); } else { this.messageExpiryMap.Remove(lookupId); } } }
public static IAsyncResult CreateAbandon(MsmqReceiveContext receiver, TimeSpan timeout, AsyncCallback callback, object state) { if (onAbandon == null) { onAbandon = new Action <object>(OnAbandon); } return(new ReceiveContextAsyncResult(receiver, timeout, callback, state, onAbandon)); }
public static IAsyncResult CreateComplete(MsmqReceiveContext receiver, TimeSpan timeout, AsyncCallback callback, object state) { if (onComplete == null) { onComplete = new Action <object>(MsmqReceiveContext.ReceiveContextAsyncResult.OnComplete); } return(new MsmqReceiveContext.ReceiveContextAsyncResult(receiver, timeout, callback, state, onComplete)); }
private ReceiveContextAsyncResult(MsmqReceiveContext receiver, TimeSpan timeout, AsyncCallback callback, object state, Action <object> target) : base(callback, state) { this.timeoutHelper = new TimeoutHelper(timeout); this.receiver = receiver; if (Transaction.Current != null) { this.associatedTransaction = Transaction.Current; } ActionItem.Schedule(target, this); }
public MsmqReceiveContext CreateMsmqReceiveContext(long lookupId) { DateTime expiryTime = TimeoutHelper.Add(DateTime.UtcNow, this.receiveContextSettings.ValidityDuration); MsmqReceiveContext context = new MsmqReceiveContext(lookupId, expiryTime, this); context.Faulted += new EventHandler(this.OnReceiveContextFaulted); lock (this.internalStateLock) { this.messageExpiryMap.Add(lookupId, context); } return context; }
public MsmqReceiveContext CreateMsmqReceiveContext(long lookupId) { DateTime expiryTime = TimeoutHelper.Add(DateTime.UtcNow, this.receiveContextSettings.ValidityDuration); MsmqReceiveContext context = new MsmqReceiveContext(lookupId, expiryTime, this); context.Faulted += new EventHandler(this.OnReceiveContextFaulted); lock (this.internalStateLock) { this.messageExpiryMap.Add(lookupId, context); } return(context); }
private void OnReceiveContextFaulted(object sender, EventArgs e) { try { MsmqReceiveContext receiveContext = (MsmqReceiveContext)sender; this.UnlockMessage(receiveContext, TimeSpan.Zero); } catch (MsmqException exception) { MsmqDiagnostics.ExpectedException(exception); } }
void OnReceiveContextFaulted(object sender, EventArgs e) { try { MsmqReceiveContext receiveContext = (MsmqReceiveContext)sender; UnlockMessage(receiveContext, TimeSpan.Zero); } catch (MsmqException ex) { // ReceiveContext is already faulted and best effort was made to cleanup the lock queue. MsmqDiagnostics.ExpectedException(ex); } }
public void UnlockMessage(MsmqReceiveContext receiveContext, TimeSpan timeout) { TimeoutHelper helper = new TimeoutHelper(timeout); long lookupId = receiveContext.LookupId; lock (this.internalStateLock) { if (this.ReceiveContextExists(receiveContext)) { ((ILockingQueue)this.queue).UnlockMessage(lookupId, helper.RemainingTime()); this.messageExpiryMap.Remove(lookupId); } } }
bool ReceiveContextExists(MsmqReceiveContext receiveContext) { Fx.Assert((receiveContext != null), "Receive context object cannot be null"); MsmqReceiveContext receiveContextFromMap = null; if (messageExpiryMap.TryGetValue(receiveContext.LookupId, out receiveContextFromMap)) { if (object.ReferenceEquals(receiveContext, receiveContextFromMap)) { return(true); } } return(false); }
// tx aborts can ---- with DeleteMessage but this ---- is harmless because // - internal state changes are protected via the internalStateLock // - we do not have an ordering requirement between DeleteMessage and a tx abort // // tx commits cannot ---- with DeleteMessage as the ReceiveContext state machine does not allow // DeleteMessage calls if the tx holding this lock committed public void DeleteMessage(MsmqReceiveContext receiveContext, TimeSpan timeout) { TimeoutHelper helper = new TimeoutHelper(timeout); long lookupId = receiveContext.LookupId; lock (this.internalStateLock) { // Expiry map is first checked before calling ReceiveContextExists as we need to throw // validity expired exception if the lookup id is not in the map. if (this.messageExpiryMap.ContainsKey(lookupId)) { Fx.Assert(ReceiveContextExists(receiveContext), "Mismatch between the receive context object stored in the map and the object passed to the method"); MsmqReceiveContext entry = this.messageExpiryMap[lookupId]; if (DateTime.UtcNow > entry.ExpiryTime) { entry.MarkContextExpired(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MessageValidityExpired, lookupId))); } else { ((ILockingQueue)this.queue).DeleteMessage(lookupId, helper.RemainingTime()); if (Transaction.Current != null) { List <MsmqReceiveContext> transMsgs; if (!this.transMessages.TryGetValue(Transaction.Current.TransactionInformation.DistributedIdentifier, out transMsgs)) { transMsgs = new List <MsmqReceiveContext>(); this.transMessages.Add(Transaction.Current.TransactionInformation.DistributedIdentifier, transMsgs); // only need to attach the tx complete handler once per transaction Transaction.Current.TransactionCompleted += this.transactionCompletedHandler; } transMsgs.Add(entry); } else { this.messageExpiryMap.Remove(lookupId); } } } else { // it was cleaned up by the expiry timer throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MessageValidityExpired, lookupId))); } } }
// tx aborts can ---- with DeleteMessage but this ---- is harmless because // - internal state changes are protected via the internalStateLock // - we do not have an ordering requirement between DeleteMessage and a tx abort // // tx commits cannot ---- with DeleteMessage as the ReceiveContext state machine does not allow // DeleteMessage calls if the tx holding this lock committed public void DeleteMessage(MsmqReceiveContext receiveContext, TimeSpan timeout) { TimeoutHelper helper = new TimeoutHelper(timeout); long lookupId = receiveContext.LookupId; lock (this.internalStateLock) { // Expiry map is first checked before calling ReceiveContextExists as we need to throw // validity expired exception if the lookup id is not in the map. if (this.messageExpiryMap.ContainsKey(lookupId)) { Fx.Assert(ReceiveContextExists(receiveContext), "Mismatch between the receive context object stored in the map and the object passed to the method"); MsmqReceiveContext entry = this.messageExpiryMap[lookupId]; if (DateTime.UtcNow > entry.ExpiryTime) { entry.MarkContextExpired(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MessageValidityExpired, lookupId))); } else { ((ILockingQueue)this.queue).DeleteMessage(lookupId, helper.RemainingTime()); if (Transaction.Current != null) { List<MsmqReceiveContext> transMsgs; if (!this.transMessages.TryGetValue(Transaction.Current.TransactionInformation.DistributedIdentifier, out transMsgs)) { transMsgs = new List<MsmqReceiveContext>(); this.transMessages.Add(Transaction.Current.TransactionInformation.DistributedIdentifier, transMsgs); // only need to attach the tx complete handler once per transaction Transaction.Current.TransactionCompleted += this.transactionCompletedHandler; } transMsgs.Add(entry); } else { this.messageExpiryMap.Remove(lookupId); } } } else { // it was cleaned up by the expiry timer throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MessageValidityExpired, lookupId))); } } }
private bool ReceiveContextExists(MsmqReceiveContext receiveContext) { MsmqReceiveContext context = null; return (this.messageExpiryMap.TryGetValue(receiveContext.LookupId, out context) && object.ReferenceEquals(receiveContext, context)); }
public static IAsyncResult CreateAbandon(MsmqReceiveContext receiver, TimeSpan timeout, AsyncCallback callback, object state) { if (onAbandon == null) { onAbandon = new Action<object>(OnAbandon); } return new ReceiveContextAsyncResult(receiver, timeout, callback, state, onAbandon); }
ReceiveContextAsyncResult(MsmqReceiveContext receiver, TimeSpan timeout, AsyncCallback callback, object state, Action<object> target) : base(callback, state) { this.timeoutHelper = new TimeoutHelper(timeout); this.receiver = receiver; if (Transaction.Current != null) { this.associatedTransaction = Transaction.Current; } ActionItem.Schedule(target, this); }
bool ReceiveContextExists(MsmqReceiveContext receiveContext) { Fx.Assert((receiveContext != null), "Receive context object cannot be null"); MsmqReceiveContext receiveContextFromMap = null; if (messageExpiryMap.TryGetValue(receiveContext.LookupId, out receiveContextFromMap)) { if (object.ReferenceEquals(receiveContext, receiveContextFromMap)) { return true; } } return false; }
// tx aborts can ---- with UnlockMessage but this ---- is harmless because // - internal state changes are protected via the internalStateLock // - we do not have an ordering requirement between UnlockMessage and a tx abort // // tx commits cannot ---- with UnlockMessage as the ReceiveContext state machine does not allow // UnlockMessage calls if the tx holding this lock committed public void UnlockMessage(MsmqReceiveContext receiveContext, TimeSpan timeout) { TimeoutHelper helper = new TimeoutHelper(timeout); long lookupId = receiveContext.LookupId; lock (this.internalStateLock) { if (ReceiveContextExists(receiveContext)) { ((ILockingQueue)this.queue).UnlockMessage(lookupId, helper.RemainingTime()); this.messageExpiryMap.Remove(lookupId); } } }
public void DeleteMessage(MsmqReceiveContext receiveContext, TimeSpan timeout) { TimeoutHelper helper = new TimeoutHelper(timeout); long lookupId = receiveContext.LookupId; lock (this.internalStateLock) { if (!this.messageExpiryMap.ContainsKey(lookupId)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MessageValidityExpired", new object[] { lookupId }))); } MsmqReceiveContext item = this.messageExpiryMap[lookupId]; if (DateTime.UtcNow > item.ExpiryTime) { item.MarkContextExpired(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MessageValidityExpired", new object[] { lookupId }))); } ((ILockingQueue) this.queue).DeleteMessage(lookupId, helper.RemainingTime()); if (Transaction.Current != null) { List<MsmqReceiveContext> list; if (!this.transMessages.TryGetValue(Transaction.Current.TransactionInformation.DistributedIdentifier, out list)) { list = new List<MsmqReceiveContext>(); this.transMessages.Add(Transaction.Current.TransactionInformation.DistributedIdentifier, list); Transaction.Current.TransactionCompleted += this.transactionCompletedHandler; } list.Add(item); } else { this.messageExpiryMap.Remove(lookupId); } } }
public static IAsyncResult CreateComplete(MsmqReceiveContext receiver, TimeSpan timeout, AsyncCallback callback, object state) { if (onComplete == null) { onComplete = new Action<object>(MsmqReceiveContext.ReceiveContextAsyncResult.OnComplete); } return new MsmqReceiveContext.ReceiveContextAsyncResult(receiver, timeout, callback, state, onComplete); }
private bool ReceiveContextExists(MsmqReceiveContext receiveContext) { MsmqReceiveContext context = null; return(this.messageExpiryMap.TryGetValue(receiveContext.LookupId, out context) && object.ReferenceEquals(receiveContext, context)); }