Example #1
0
 /// <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);
 }
Example #2
0
 public static void SetState(RetryCache.CacheEntryWithPayload e, bool success, object
                             payload)
 {
     if (e == null)
     {
         return;
     }
     e.payload = payload;
     e.Completed(success);
 }
Example #3
0
 public virtual void AddCacheEntryWithPayload(byte[] clientId, int callId, object
                                              payload)
 {
     // since the entry is loaded from editlog, we can assume it succeeded.
     RetryCache.CacheEntry newEntry = new RetryCache.CacheEntryWithPayload(clientId, callId
                                                                           , payload, Runtime.NanoTime() + expirationTime, true);
     Lock.Lock();
     try
     {
         set.Put(newEntry);
     }
     finally
     {
         Lock.Unlock();
     }
     retryCacheMetrics.IncrCacheUpdated();
 }