예제 #1
0
 private static void Sleep(RetryExceptionHandler handler, IDictionary <string, object> callContextDictionary, SleepHandler sleepHandler)
 {
     if (handler.IsDelayBased)
     {
         sleepHandler(handler.DelayTimeSpan);
     }
     else
     {
         try
         {
             IExpression expression = Expression.Parse(handler.DelayRateExpression);
             object      result     = expression.GetValue(null, callContextDictionary);
             decimal     d          = decimal.Parse(result.ToString());
             decimal     rounded    = decimal.Round(d * 1000, 0);
             TimeSpan    duration   = TimeSpan.FromMilliseconds(decimal.ToDouble(rounded));
             sleepHandler(duration);
         }
         catch (InvalidCastException e)
         {
             log.Warn("Was not able to cast expression to decimal [" + handler.DelayRateExpression + "]. Sleeping for 1 second", e);
             sleepHandler(new TimeSpan(0, 0, 1));
         }
         catch (Exception e)
         {
             log.Warn("Was not able to evaluate rate expression [" + handler.DelayRateExpression + "]. Sleeping for 1 second", e);
             sleepHandler(new TimeSpan(0, 0, 1));
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Creates a new RetryAdvice instance, using any arbitrary callback for delaying retries
 /// </summary>
 public RetryAdvice(SleepHandler sleepHandler)
 {
     this.sleepHandler = sleepHandler;
 }
예제 #3
0
 /// <summary>
 /// Creates a new RetryAdvice instance, using any arbitrary callback for delaying retries
 /// </summary>
 public RetryAdvice(SleepHandler sleepHandler)
 {
     this.sleepHandler = sleepHandler;
 }
예제 #4
0
 private static void Sleep(RetryExceptionHandler handler, IDictionary callContextDictionary, SleepHandler sleepHandler)
 {
     if (handler.IsDelayBased)
     {
         sleepHandler(handler.DelayTimeSpan);
     }
     else
     {
         try
         {
             IExpression expression = Expression.Parse(handler.DelayRateExpression);
             object result = expression.GetValue(null, callContextDictionary);
             decimal d = decimal.Parse(result.ToString());
             decimal rounded = decimal.Round(d*1000,0);
             TimeSpan duration = TimeSpan.FromMilliseconds(decimal.ToDouble(rounded));
             sleepHandler(duration);
         }
         catch (InvalidCastException e)
         {
             log.Warn("Was not able to cast expression to decimal [" + handler.DelayRateExpression + "]. Sleeping for 1 second", e);
             sleepHandler(new TimeSpan(0,0,1));
         }
         catch (Exception e)
         {
             log.Warn("Was not able to evaluate rate expression [" + handler.DelayRateExpression + "]. Sleeping for 1 second", e);
             sleepHandler(new TimeSpan(0,0,1));
         }
     }
 }