本文整理汇总了C#中IRetryPolicy类的典型用法代码示例。如果您正苦于以下问题:C# IRetryPolicy类的具体用法?C# IRetryPolicy怎么用?C# IRetryPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRetryPolicy类属于命名空间,在下文中一共展示了IRetryPolicy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: HttpRestClientConfiguration
public HttpRestClientConfiguration(HttpMessageHandler defaultHttpClientHandler = null,
IEnumerable<DelegatingHandler> messageProcessingHandlers = null,
IRetryPolicy retryPolicy = null,
TimeSpan? httpRequestTimeout = null)
{
this._httpRequestTimeout = httpRequestTimeout ?? TimeSpan.FromMinutes(1);
this.HttpMessageHandler = defaultHttpClientHandler ?? new HttpClientHandler();
if (messageProcessingHandlers == null)
{
this._additionalDelegatingHandlers = new ReadOnlyCollection<DelegatingHandler>(new List<DelegatingHandler>());
}
else
{
this._additionalDelegatingHandlers = new ReadOnlyCollection<DelegatingHandler>(messageProcessingHandlers.ToList());
}
this.RetryPolicy = retryPolicy ?? new NoRetryPolicy();
//Here we chain the delegating handlers such that each delegating handler has the next one as its inner handler
for (int i = this.DelegatingHandlers.Count - 1; i >= 0; i--)
{
if (i - 1 >= 0)
{
this.DelegatingHandlers[i - 1].InnerHandler = this.DelegatingHandlers[i];
}
}
//the first delegating handler has the default defaultHttpClientHandler as its inner handler
if (this.DelegatingHandlers.Any())
{
this.DelegatingHandlers.Last().InnerHandler = this.HttpMessageHandler;
}
}
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:34,代码来源:HttpRestClientConfiguration.cs
示例2: Execute
public static void Execute(Action method, IRetryPolicy retryPolicy, IBackOffScheme backOffScheme, int numRetries = Constants.LoadBalancingHelperNumRetriesDefault)
{
int retryCount = 0;
bool requestSuccess = false;
while ((!requestSuccess) && (retryCount < numRetries))
{
try
{
method();
requestSuccess = true;
}
catch (Exception ex)
{
Trace.TraceError("\tAttempt {0} failed with exception {1} - {2}", retryCount, ex.GetType(), ex.Message);
retryCount++;
if ((retryCount < numRetries) && (retryPolicy.ShouldRetryAttempt(ex)))
{
var sleepInterval = backOffScheme.GetRetryInterval(retryCount);
if (sleepInterval != default (TimeSpan))
{
Trace.TraceInformation("\tWill retry after {0} milliseconds......", sleepInterval.TotalMilliseconds);
Thread.Sleep(sleepInterval);
}
}
else
{
throw;
}
}
}
}
开发者ID:gitter-badger,项目名称:hbase-sdk-for-net,代码行数:32,代码来源:LoadBalancingHelper.cs
示例3: DownloadBlob
public Task DownloadBlob(
Uri uri,
string localFile,
FileEncryption fileEncryption,
ulong initializationVector,
CloudBlobClient client,
CancellationToken cancellationToken,
IRetryPolicy retryPolicy,
Func<string> getSharedAccessSignature = null,
long start = 0,
long length = -1,
int parallelTransferThreadCount = 10,
int numberOfConcurrentTransfers = 2)
{
if (client != null && getSharedAccessSignature != null)
{
throw new InvalidOperationException("The arguments client and getSharedAccessSignature cannot both be non-null");
}
SetConnectionLimits(uri, Environment.ProcessorCount * numberOfConcurrentTransfers * parallelTransferThreadCount);
Task task =
Task.Factory.StartNew(
() =>
DownloadFileFromBlob(uri, localFile, fileEncryption, initializationVector, client,
cancellationToken, retryPolicy, getSharedAccessSignature, start: start, length: length,
parallelTransferThreadCount: parallelTransferThreadCount));
return task;
}
开发者ID:shushengli,项目名称:azure-sdk-for-media-services,代码行数:29,代码来源:BlobDownloader.cs
示例4: ExecuteReaderAsyncWithRetry
public static Task<SqlDataReader> ExecuteReaderAsyncWithRetry(
SqlCommand command,
CommandBehavior behavior,
IRetryPolicy retryPolicy)
{
return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteReaderAsync(behavior));
}
开发者ID:cleverguy25,项目名称:Fleeting,代码行数:7,代码来源:SqlCommandExtensions.cs
示例5: ExecuteNonQueryAsyncWithRetry
public static Task<int> ExecuteNonQueryAsyncWithRetry(
SqlCommand command,
CancellationToken cancellationToken,
IRetryPolicy retryPolicy)
{
return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteNonQueryAsync(cancellationToken));
}
开发者ID:cleverguy25,项目名称:Fleeting,代码行数:7,代码来源:SqlCommandExtensions.cs
示例6: UploadBlob
public Task UploadBlob(
Uri url,
string localFile,
FileEncryption fileEncryption,
CancellationToken cancellationToken,
CloudBlobClient client,
IRetryPolicy retryPolicy,
string contentType = null,
string subDirectory = "",
Func<string> getSharedAccessSignature = null)
{
SetConnectionLimits(url);
return Task.Factory.StartNew(
() => UploadFileToBlob(
cancellationToken,
url,
localFile,
contentType,
subDirectory,
fileEncryption,
client,
retryPolicy,
getSharedAccessSignature),
cancellationToken);
}
开发者ID:Ginichen,项目名称:azure-sdk-for-media-services,代码行数:25,代码来源:BlobUploader.cs
示例7: HaConnection
/// <summary>
/// Initialize a <see cref="HaConnection"/> with a list of <see cref="ManagedConnectionFactory"/>
/// These connection factories are responsibile for creating <see cref="IConnection"/> to nodes in the clusters
/// </summary>
/// <param name="retryPolicy"></param>
/// <param name="watcher"></param>
/// <param name="connectionFactories"></param>
public HaConnection(IRetryPolicy retryPolicy, IRabbitWatcher watcher, IList<ManagedConnectionFactory> connectionFactories) : base(retryPolicy, watcher)
{
_connectionFactories = new RoundRobinList<ConnectionFactory>(connectionFactories);
ConnectionEstablished handler = (endpoint, virtualHost) =>
{
if (_connectionFactories.All.Any(f => f.Endpoint + f.VirtualHost == endpoint + virtualHost))
{
if (!IsConnected)
{
while (_connectionFactories.Current.Endpoint + _connectionFactories.Current.VirtualHost != endpoint + virtualHost)
{
//IF there are 2 different Tunnels using 2 HaConnection with 2 lists of cluster nodes in different orders:
//Example:
// ConnectionString1: host=q1;username=guest;password=guest|host=q2;username=guest;password=guest|host=q3;username=guest;password=guest
// ConnectionString2: host=q2;username=guest;password=guest|host=q3;username=guest;password=guest|host=q1;username=guest;password=guest
// When the first tunnel established the connection successfully to q1, it fires event and these lines of code is triggered.
// The 2nd HaConnection needs to set it's _connectionFactories.Current to q1 established by other tunnel. Before changing, _connectionFactories.Current is q3 by the order in the ConnectionString2
_connectionFactories.GetNext();
}
}
FireConnectedEvent();
}
};
ManagedConnectionFactory.ConnectionEstablished += handler;
_unsubscribeEvents = () => { ManagedConnectionFactory.ConnectionEstablished -= handler; };
}
开发者ID:vanthoainguyen,项目名称:Burrow.NET,代码行数:36,代码来源:HaConnection.cs
示例8: OpenAsyncWithRetry
public static Task OpenAsyncWithRetry(
this SqlConnection connection,
CancellationToken cancellationToken,
IRetryPolicy retryPolicy)
{
return retryPolicy.ExecuteAsyncWithRetry(() => connection.OpenAsync(cancellationToken));
}
开发者ID:cleverguy25,项目名称:Fleeting,代码行数:7,代码来源:SqlConnectionExtensions.cs
示例9: UploadBlob
public Task UploadBlob(
Uri url,
string localFile,
FileEncryption fileEncryption,
CancellationToken cancellationToken,
CloudBlobClient client,
IRetryPolicy retryPolicy,
string contentType = null,
string subDirectory = "",
Func<string> getSharedAccessSignature = null,
int parallelTransferThreadCount = 10,
int numberOfConcurrentTransfers = default(int))
{
SetConnectionLimits(url, numberOfConcurrentTransfers);
return Task.Factory.StartNew(
() => UploadFileToBlob(
cancellationToken,
url,
localFile,
contentType,
subDirectory,
fileEncryption,
client,
retryPolicy,
getSharedAccessSignature,
parallelTransferThreadCount),
cancellationToken);
}
开发者ID:JeromeZhao,项目名称:azure-sdk-for-media-services,代码行数:28,代码来源:BlobUploader.cs
示例10: EventStreamProducer
public EventStreamProducer(IEventStreamWriter streamWriter, IRetryPolicy retryPolicy)
{
Require.NotNull(streamWriter, "streamWriter");
Require.NotNull(retryPolicy, "retryPolicy");
m_streamWriter = streamWriter;
m_retryPolicy = retryPolicy;
}
开发者ID:savamura,项目名称:Journalist,代码行数:8,代码来源:EventStreamProducer.cs
示例11: Policies
/// <summary>
/// Creates a new <code>Policies</code> object using the provided policies.
/// </summary>
/// <param name="loadBalancingPolicy"> the load balancing policy to use. </param>
/// <param name="reconnectionPolicy"> the reconnection policy to use. </param>
/// <param name="retryPolicy"> the retry policy to use.</param>
public Policies(ILoadBalancingPolicy loadBalancingPolicy,
IReconnectionPolicy reconnectionPolicy,
IRetryPolicy retryPolicy)
{
this._loadBalancingPolicy = loadBalancingPolicy;
this._reconnectionPolicy = reconnectionPolicy;
this._retryPolicy = retryPolicy;
}
开发者ID:hjarraya,项目名称:csharp-driver,代码行数:14,代码来源:Policies.cs
示例12: AbstractionContext
/// <summary>
/// Initializes a new instance of the AbstractionContext class.
/// </summary>
/// <param name="tokenSource">A Cancellation token source.</param>
/// <param name="logger">A logger instance.</param>
/// <param name="httpOperationTimeout">The HTTP operation timeout.</param>
/// <param name="retryPolicy">The retry policy.</param>
public AbstractionContext(CancellationTokenSource tokenSource, ILogger logger, TimeSpan httpOperationTimeout, IRetryPolicy retryPolicy)
{
this.RetryPolicy = retryPolicy;
tokenSource.ArgumentNotNull("tokenSource");
logger.ArgumentNotNull("logger");
this.CancellationTokenSource = tokenSource;
this.Logger = logger;
this.HttpOperationTimeout = httpOperationTimeout;
}
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:16,代码来源:AbstractionContext.cs
示例13: HttpRestClientRetryPolicy
public HttpRestClientRetryPolicy(IRetryPolicy retryPolicy)
{
if (retryPolicy == null)
{
throw new ArgumentNullException("retryPolicy");
}
this.retryPolicy = retryPolicy;
}
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:9,代码来源:HttpRestClientRetryPolicy.cs
示例14: ElasticRequestProcessor
public ElasticRequestProcessor(IElasticConnection connection, IElasticMapping mapping, ILog log, IRetryPolicy retryPolicy)
{
Argument.EnsureNotNull("connection", connection);
Argument.EnsureNotNull("mapping", mapping);
Argument.EnsureNotNull("log", log);
Argument.EnsureNotNull("retryPolicy", retryPolicy);
this.connection = connection;
this.mapping = mapping;
this.log = log;
this.retryPolicy = retryPolicy;
}
开发者ID:jarlrasm,项目名称:ElasticLINQ,代码行数:12,代码来源:ElasticRequestProcessor.cs
示例15: DurableConnection
internal DurableConnection(IRetryPolicy retryPolicy, IRabbitWatcher watcher)
{
if (retryPolicy == null)
{
throw new ArgumentNullException(nameof(retryPolicy));
}
if (watcher == null)
{
throw new ArgumentNullException(nameof(watcher));
}
_retryPolicy = retryPolicy;
_watcher = watcher;
}
开发者ID:vanthoainguyen,项目名称:Burrow.NET,代码行数:13,代码来源:DurableConnection.cs
示例16: CuratorZookeeperClient
/**
*
* @param connectString list of servers to connect to
* @param sessionTimeoutMs session timeout
* @param connectionTimeoutMs connection timeout
* @param watcher default watcher or null
* @param retryPolicy the retry policy to use
*/
public CuratorZookeeperClient(String connectString,
int sessionTimeoutMs,
int connectionTimeoutMs,
Watcher watcher,
IRetryPolicy retryPolicy)
: this(new DefaultZookeeperFactory(),
new FixedEnsembleProvider(connectString),
sessionTimeoutMs,
connectionTimeoutMs,
watcher,
retryPolicy,
false)
{
}
开发者ID:Lagrang,项目名称:CuratorNet,代码行数:22,代码来源:CuratorZookeeperClient.cs
示例17: CuratorZookeeperClient
/**
* @param zookeeperFactory factory for creating {@link ZooKeeper} instances
* @param ensembleProvider the ensemble provider
* @param sessionTimeoutMs session timeout
* @param connectionTimeoutMs connection timeout
* @param watcher default watcher or null
* @param retryPolicy the retry policy to use
* @param canBeReadOnly if true, allow ZooKeeper client to enter
* read only mode in case of a network partition. See
* {@link ZooKeeper#ZooKeeper(String, int, Watcher, long, byte[], bool)}
* for details
*/
public CuratorZookeeperClient(IZookeeperFactory zookeeperFactory, IEnsembleProvider ensembleProvider, int sessionTimeoutMs, int connectionTimeoutMs, IWatcher watcher, IRetryPolicy retryPolicy, bool canBeReadOnly)
{
if ( sessionTimeoutMs < connectionTimeoutMs )
{
log.Warn(String.Format("session timeout [{0}] is less than connection timeout [{1}]", sessionTimeoutMs, connectionTimeoutMs));
}
// retryPolicy = Preconditions.checkNotNull(retryPolicy, "retryPolicy cannot be null");
// ensembleProvider = Preconditions.checkNotNull(ensembleProvider, "ensembleProvider cannot be null");
this.connectionTimeoutMs = connectionTimeoutMs;
state = new ConnectionState(zookeeperFactory, ensembleProvider, TimeSpan.FromMilliseconds(sessionTimeoutMs), TimeSpan.FromMilliseconds(connectionTimeoutMs), watcher, tracer, canBeReadOnly);
SetRetryPolicy(retryPolicy);
}
开发者ID:yepuv1,项目名称:curator.net,代码行数:27,代码来源:CuratorZookeeperClient.cs
示例18: TestSqlRetryPolicy
private static async Task TestSqlRetryPolicy(IRetryPolicy retryPolicy, int interval)
{
var retryCount = 0;
retryPolicy.Retry += (sender, args) =>
{
retryCount++;
// Assert
Assert.Equal(typeof(TimeoutException), args.Exception.GetType());
Assert.Equal(retryCount, args.RetryCount);
Assert.Equal(retryCount * interval, args.Delay.TotalMilliseconds);
};
var taskFunction = TaskFunctionTestFactory.GetTaskFunctionTResultWithRetry();
// Act
await retryPolicy.ExecuteAsyncWithRetry(taskFunction);
}
开发者ID:cleverguy25,项目名称:Fleeting,代码行数:18,代码来源:SqlRetryPolicyFactoryTest.cs
示例19: DurableConnection
public DurableConnection(IRetryPolicy retryPolicy, IRabbitWatcher watcher, ConnectionFactory connectionFactory)
{
if (retryPolicy == null)
{
throw new ArgumentNullException("retryPolicy");
}
if (watcher == null)
{
throw new ArgumentNullException("watcher");
}
if (connectionFactory == null)
{
throw new ArgumentNullException("connectionFactory");
}
_retryPolicy = retryPolicy;
_watcher = watcher;
ConnectionFactory = connectionFactory;
}
开发者ID:sovanesyan,项目名称:Burrow.NET,代码行数:19,代码来源:DurableConnection.cs
示例20: DownloadBlob
public Task DownloadBlob(
Uri uri,
string localFile,
FileEncryption fileEncryption,
ulong initializationVector,
CloudBlobClient client,
CancellationToken cancellationToken,
IRetryPolicy retryPolicy,
Func<string> getSharedAccessSignature = null,
long start = 0,
long length = -1)
{
if (client != null && getSharedAccessSignature != null)
{
throw new InvalidOperationException("The arguments client and getSharedAccessSignature cannot both be non-null");
}
SetConnectionLimits(uri);
Task task = Task.Factory.StartNew(() => DownloadFileFromBlob(uri, localFile, fileEncryption, initializationVector, client, cancellationToken, retryPolicy, getSharedAccessSignature, start:start, length:length));
return task;
}
开发者ID:Ginichen,项目名称:azure-sdk-for-media-services,代码行数:22,代码来源:BlobDownloader.cs
注:本文中的IRetryPolicy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论