-
Notifications
You must be signed in to change notification settings - Fork 2k
/
AdoNetGatewayListProvider.cs
65 lines (59 loc) · 2.28 KB
/
AdoNetGatewayListProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Orleans.Clustering.AdoNet.Storage;
using Orleans.Messaging;
using Orleans.Configuration;
namespace Orleans.Runtime.Membership
{
public class AdoNetGatewayListProvider : IGatewayListProvider
{
private readonly ILogger _logger;
private readonly string _clusterId;
private readonly AdoNetClusteringClientOptions _options;
private RelationalOrleansQueries _orleansQueries;
private readonly IServiceProvider _serviceProvider;
private readonly TimeSpan _maxStaleness;
public AdoNetGatewayListProvider(
ILogger<AdoNetGatewayListProvider> logger,
IServiceProvider serviceProvider,
IOptions<AdoNetClusteringClientOptions> options,
IOptions<GatewayOptions> gatewayOptions,
IOptions<ClusterOptions> clusterOptions)
{
this._logger = logger;
this._serviceProvider = serviceProvider;
this._options = options.Value;
this._clusterId = clusterOptions.Value.ClusterId;
this._maxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;
}
public TimeSpan MaxStaleness
{
get { return this._maxStaleness; }
}
public bool IsUpdatable
{
get { return true; }
}
public async Task InitializeGatewayListProvider()
{
if (_logger.IsEnabled(LogLevel.Trace)) _logger.LogTrace("AdoNetClusteringTable.InitializeGatewayListProvider called.");
_orleansQueries = await RelationalOrleansQueries.CreateInstance(_options.Invariant, _options.ConnectionString);
}
public async Task<IList<Uri>> GetGateways()
{
if (_logger.IsEnabled(LogLevel.Trace)) _logger.LogTrace("AdoNetClusteringTable.GetGateways called.");
try
{
return await _orleansQueries.ActiveGatewaysAsync(this._clusterId);
}
catch (Exception ex)
{
if (_logger.IsEnabled(LogLevel.Debug)) _logger.LogDebug(ex, "AdoNetClusteringTable.Gateways failed");
throw;
}
}
}
}