Show / Hide Table of Contents

Class BackOffHandler

A thread-safe back-off handler which handles an abnormal HTTP response or an exception with IBackOff.

Inheritance
object
BackOffHandler
Implements
IHttpUnsuccessfulResponseHandler
IHttpExceptionHandler
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Google.Apis.Http
Assembly: Google.Apis.Core.dll
Syntax
public class BackOffHandler : IHttpUnsuccessfulResponseHandler, IHttpExceptionHandler

Constructors

BackOffHandler(Initializer)

Constructs a new back-off handler with the given initializer.

Declaration
public BackOffHandler(BackOffHandler.Initializer initializer)
Parameters
Type Name Description
BackOffHandler.Initializer initializer

BackOffHandler(IBackOff)

Constructs a new back-off handler with the given back-off.

Declaration
public BackOffHandler(IBackOff backOff)
Parameters
Type Name Description
IBackOff backOff

The back-off policy.

Properties

BackOff

Gets the back-off policy used by this back-off handler.

Declaration
public IBackOff BackOff { get; }
Property Value
Type Description
IBackOff

HandleExceptionFunc

Gets a delegate function which indicates whether this back-off handler should handle an exception. The default is DefaultHandleExceptionFunc.

Declaration
public Func<Exception, bool> HandleExceptionFunc { get; }
Property Value
Type Description
Func<Exception, bool>

HandleUnsuccessfulResponseFunc

Gets a delegate function which indicates whether this back-off handler should handle an abnormal HTTP response. The default is DefaultHandleUnsuccessfulResponseFunc.

Declaration
public Func<HttpResponseMessage, bool> HandleUnsuccessfulResponseFunc { get; }
Property Value
Type Description
Func<HttpResponseMessage, bool>

MaxTimeSpan

Gets the maximum time span to wait. If the back-off instance returns a greater time span, the handle method returns false. Default value is 16 seconds per a retry request.

Declaration
public TimeSpan MaxTimeSpan { get; }
Property Value
Type Description
TimeSpan

Methods

HandleExceptionAsync(HandleExceptionArgs)

Handles an exception thrown when sending a HTTP request. A simple rule must be followed, if you modify the request object in a way that the exception can be resolved, you must return true.

Declaration
public virtual Task<bool> HandleExceptionAsync(HandleExceptionArgs args)
Parameters
Type Name Description
HandleExceptionArgs args

Handle exception argument which properties such as the request, exception, current failed try.

Returns
Type Description
Task<bool>

Whether this handler has made a change that requires the request to be resent.

HandleResponseAsync(HandleUnsuccessfulResponseArgs)

Handles an abnormal response when sending a HTTP request. A simple rule must be followed, if you modify the request object in a way that the abnormal response can be resolved, you must return true.

Declaration
public virtual Task<bool> HandleResponseAsync(HandleUnsuccessfulResponseArgs args)
Parameters
Type Name Description
HandleUnsuccessfulResponseArgs args

Handle response argument which contains properties such as the request, response, current failed try.

Returns
Type Description
Task<bool>

Whether this handler has made a change that requires the request to be resent.

Wait(TimeSpan, CancellationToken)

Waits the given time span. Overriding this method is recommended for mocking purposes.

Declaration
protected virtual Task Wait(TimeSpan ts, CancellationToken cancellationToken)
Parameters
Type Name Description
TimeSpan ts

TimeSpan to wait (and block the current thread).

CancellationToken cancellationToken

The cancellation token in case the user wants to cancel the operation in the middle.

Returns
Type Description
Task

Implements

IHttpUnsuccessfulResponseHandler
IHttpExceptionHandler

Extension Methods

Utilities.ThrowIfNull<T>(T, string)
In this article
Back to top Generated by DocFX