Exemplo n.º 1
0
 private void Initialize(TransactionDelegate transactionDelegate, RetryDelegate retryDelegate, TransactionOptions options)
 {
     _options            = options;
     State               = TransactionState.Active;
     TransactionDelegate = transactionDelegate;
     RetryDelegate       = retryDelegate;
 }
        public static bool Retry(RetryDelegate del, int numberOfRetries, int msPause)
        {
            int counter = 0;

RetryLabel:
            try
            {
                counter++;
                del.Invoke();
                return(true);
            }
            catch (Exception ex)
            {
                if (counter > numberOfRetries)
                {
                    throw ex;
                }
                else
                {
                    if (msPause > 0)
                    {
                        Thread.Sleep(msPause);
                    }
                    goto RetryLabel;
                }
            }
        }
Exemplo n.º 3
0
 public BCRetryData(RetryDelegate in_delegate, object in_retryData, SuccessCallback in_success = null, FailureCallback in_failure = null)
 {
     retryDelegate = in_delegate;
     retryData     = in_retryData;
     success       = in_success;
     failure       = in_failure;
 }
 public abstract Task <TResult> DeleteAsync <TData, TResult>(TData document,
                                                             Func <TResult> success,
                                                             Func <TResult> onNotFound,
                                                             Func <ExtendedErrorInformationCodes, string, TResult> onFailure =
                                                             default(Func <ExtendedErrorInformationCodes, string, TResult>),
                                                             RetryDelegate onTimeout = default(RetryDelegate))
     where TData : class, ITableEntity;
Exemplo n.º 5
0
        public static T Times <T>(RetryDelegate <T> del, int numberOfRetries, int msPause, bool throwExceptions)
        {
            int counter = 0;

BeginLabel:
            try
            {
                counter++;
                return(del.Invoke());
            }
            catch (Exception ex)
            {
                if (counter > numberOfRetries)
                {
                    if (throwExceptions)
                    {
                        throw;
                    }
                    else
                    {
                        return(default(T));
                    }
                }
                else
                {
                    if (RetryDelegateFailed != null)
                    {
                        RetryDelegateFailed(ex, counter);
                    }

                    Thread.Sleep(msPause);
                    goto BeginLabel;
                }
            }
        }
        /// <summary>
        /// Retry delegate.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="del"></param>
        /// <param name="numberOfRetries"></param>
        /// <param name="msPause"></param>
        /// <returns></returns>
        public static T Retry <T>(RetryDelegate <T> del, int numberOfRetries, int msPause)
        {
            var counter = 0;

RetryLabel:

            try
            {
                counter++;
                return(del.Invoke());
            }
            catch (Exception ex)
            {
                if (counter > numberOfRetries)
                {
                    throw;
                }

                if (msPause > 0)
                {
                    Thread.Sleep(msPause);
                }

                goto RetryLabel;
            }
        }
 public abstract Task <TResult> UpdateIfNotModifiedAsync <TData, TResult>(TData data,
                                                                          Func <TResult> success,
                                                                          Func <TResult> documentModified,
                                                                          Func <ExtendedErrorInformationCodes, string, TResult> onFailure =
                                                                          default(Func <ExtendedErrorInformationCodes, string, TResult>),
                                                                          RetryDelegate onTimeout =
                                                                          default(RetryDelegate))
     where TData : ITableEntity;
 public abstract Task <TResult> CreateAsync <TResult, TDocument>(string rowKey, string partitionKey, TDocument document,
                                                                 Func <TResult> onSuccess,
                                                                 Func <TResult> onAlreadyExists,
                                                                 Func <ExtendedErrorInformationCodes, string, TResult> onFailure =
                                                                 default(Func <ExtendedErrorInformationCodes, string, TResult>),
                                                                 RetryDelegate onTimeout =
                                                                 default(RetryDelegate))
     where TDocument : class, ITableEntity;
 public abstract Task <TResult> FindByIdAsync <TEntity, TResult>(
     string rowKey, string partitionKey,
     Func <TEntity, TResult> onSuccess,
     Func <TResult> onNotFound,
     Func <ExtendedErrorInformationCodes, string, TResult> onFailure =
     default(Func <ExtendedErrorInformationCodes, string, TResult>),
     RetryDelegate onTimeout =
     default(RetryDelegate))
     where TEntity : class, ITableEntity;
Exemplo n.º 10
0
            public static T Retry <T>(RetryDelegate <T> Action, CompletedDelegate <T, Object> Completed,
                                      Object completed_delegate_object, int wait_secs, int max_tries, TimeSpan timeout_secs)
            {
                T        result      = default(T);
                DateTime start       = DateTime.UtcNow;
                int      tries       = 0;
                var      method_name = Action.Method.Name;

                while (TimeToGiveUp(start, timeout_secs, tries, max_tries) == false)
                {
                    try
                    {
                        tries++;
                        result = Action.Invoke();
                        if (Completed(result, completed_delegate_object) == true)
                        {
                            return(result);
                        }
                    }
                    catch (Exception e)
                    {
                        GenUtils.PriorityLogMsg("exception", "RetryDelegate: " + method_name,
                                                e.Message + e.StackTrace);
                        throw (e);
                    }
                    HttpUtils.Wait(wait_secs);
                }

                if (TimedOut(start, timeout_secs))
                {
                    throw RetryTimedOut;
                }

                if (ExceededTries(tries, max_tries))
                {
                    throw RetryExceededMaxTries;
                }

                return(result);                 // default(T)
            }
Exemplo n.º 11
0
        // Retry delegate with default retry settings.

        public static T Retry <T>(RetryDelegate <T> del)
        {
            return(Retry <T>(del, retryCount, retryIntervalMS));
        }
Exemplo n.º 12
0
        // Retry delegate with default retry settings.

        public static bool Retry(RetryDelegate del)
        {
            return(Retry(del, retryCount, retryIntervalMS));
        }
Exemplo n.º 13
0
        public static Transaction ExecuteTransaction(TransactionDelegate transactionDelegate, RetryDelegate retryDelegate, TransactionOptions options)
        {
            _trasaction = new Transaction(transactionDelegate, retryDelegate);


            _trasaction.TransactionDelegate.Invoke(_trasaction);

            while (_trasaction.State == TransactionState.Aborted && _trasaction.RetryDelegate != null && _trasaction.RetryDelegate.Invoke(_trasaction))
            {
                _trasaction.TransactionDelegate.Invoke(_trasaction);
            }

            return(_trasaction);
        }
Exemplo n.º 14
0
 internal Transaction(TransactionDelegate transactionDelegate, RetryDelegate retryDelegate)
 {
     Initialize(transactionDelegate, retryDelegate, new TransactionOptions());
 }
Exemplo n.º 15
0
 internal Transaction(TransactionDelegate transactionDelegate, RetryDelegate retryDelegate, TransactionOptions options)
 {
     Initialize(transactionDelegate, retryDelegate, options);
 }
Exemplo n.º 16
0
 private void reTry(RetryDelegate retryAction)
 {
     if (this.sleeping)
       {
     this.sleeping = false;
     retryAction.DynamicInvoke(new object[0]);
       }
       else
       {
     this.sleeping = true;
     SA_StorageWorker bw_NewWorker = new SA_StorageWorker(this);
     bw_NewWorker.DoWork += new DoWorkEventHandler(this.bw_Sleep_DoWork);
     this.SetCurrentWorker(bw_NewWorker);
       }
 }
Exemplo n.º 17
0
 public static Transaction ExecuteTransaction(TransactionDelegate transactionDelegate, RetryDelegate retryDelegate)
 {
     return(ExecuteTransaction(transactionDelegate, retryDelegate, new TransactionOptions()));
 }
Exemplo n.º 18
0
 public RetryPolicy(RetryDelegate shouldRetryAfter = null)
 {
     this.shouldRetryAfter = shouldRetryAfter ??
                             Default;
 }
Exemplo n.º 19
0
 // Retry delegate with default retry settings.
 public static T Retry <T>(RetryDelegate <T> del, int numberOfRetries)
 {
     return(Retry <T>(del, numberOfRetries, RetryIntervalMs));
 }