/// <summary> /// A server method implemented using /// <see cref="RetryCache"/> /// . /// </summary> /// <param name="input"> /// is returned back in echo, if /// <paramref name="success"/> /// is true. /// </param> /// <param name="failureOuput"> /// returned on failure, if /// <paramref name="success"/> /// is false. /// </param> /// <param name="methodTime"> /// time taken by the operation. By passing smaller/larger /// value one can simulate an operation that takes short/long time. /// </param> /// <param name="success">whether this operation completes successfully or not</param> /// <returns> /// return the input parameter /// <paramref name="input"/> /// , if /// <paramref name="success"/> /// is /// true, else return /// <paramref name="failureOutput"/> /// . /// </returns> /// <exception cref="System.Exception"/> internal virtual int Echo(int input, int failureOutput, long methodTime, bool success ) { RetryCache.CacheEntryWithPayload entry = RetryCache.WaitForCompletion(retryCache, null); if (entry != null && entry.IsSuccess()) { System.Console.Out.WriteLine("retryCount incremented " + retryCount.Get()); retryCount.IncrementAndGet(); return((int)entry.GetPayload()); } try { operationCount.IncrementAndGet(); if (methodTime > 0) { Thread.Sleep(methodTime); } } finally { RetryCache.SetState(entry, success, input); } return(success ? input : failureOutput); }
/// <summary>Static method that provides null check for retryCache</summary> public static RetryCache.CacheEntry WaitForCompletion(RetryCache cache) { if (SkipRetryCache()) { return(null); } return(cache != null?cache.WaitForCompletion(NewEntry(cache.expirationTime)) : null); }
/// <summary>Static method that provides null check for retryCache</summary> public static RetryCache.CacheEntryWithPayload WaitForCompletion(RetryCache cache , object payload) { if (SkipRetryCache()) { return(null); } return((RetryCache.CacheEntryWithPayload)(cache != null ? cache.WaitForCompletion (NewEntry(payload, cache.expirationTime)) : null)); }