-
Notifications
You must be signed in to change notification settings - Fork 25
/
StreamingDataSourceBuilder.cs
87 lines (81 loc) · 3.49 KB
/
StreamingDataSourceBuilder.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using LaunchDarkly.Sdk.Server.Internal;
using LaunchDarkly.Sdk.Server.Internal.DataSources;
using LaunchDarkly.Sdk.Server.Subsystems;
using static LaunchDarkly.Sdk.Internal.Events.DiagnosticConfigProperties;
namespace LaunchDarkly.Sdk.Server.Integrations
{
/// <summary>
/// Contains methods for configuring the streaming data source.
/// </summary>
/// <remarks>
/// <para>
/// By default, the SDK uses a streaming connection to receive feature flag data from LaunchDarkly. If you want
/// to customize the behavior of the connection, create a builder with <see cref="Components.StreamingDataSource"/>,
/// change its properties with the methods of this class, and pass it to <see cref="ConfigurationBuilder.DataSource"/>.
/// </para>
/// <para>
/// Setting <see cref="ConfigurationBuilder.Offline(bool)"/> to <see langword="true"/> will supersede this
/// setting and completely disable network requests.
/// </para>
/// </remarks>
/// <example>
/// <code>
/// var config = Configuration.Builder(sdkKey)
/// .DataSource(Components.PollingDataSource()
/// .PollInterval(TimeSpan.FromSeconds(45)))
/// .Build();
/// </code>
/// </example>
public sealed class StreamingDataSourceBuilder : IComponentConfigurer<IDataSource>, IDiagnosticDescription
{
/// <summary>
/// The default value for <see cref="InitialReconnectDelay(TimeSpan)"/>: 1000 milliseconds.
/// </summary>
public static readonly TimeSpan DefaultInitialReconnectDelay = TimeSpan.FromSeconds(1);
internal TimeSpan _initialReconnectDelay = DefaultInitialReconnectDelay;
/// <summary>
/// Sets the initial reconnect delay for the streaming connection.
/// </summary>
/// <remarks>
/// <para>
/// The streaming service uses a backoff algorithm (with jitter) every time the connection needs
/// to be reestablished.The delay for the first reconnection will start near this value, and then
/// increase exponentially for any subsequent connection failures.
/// </para>
/// <para>
/// The default value is <see cref="DefaultInitialReconnectDelay"/>.
/// </para>
/// </remarks>
/// <param name="initialReconnectDelay">the reconnect time base value</param>
/// <returns>the builder</returns>
public StreamingDataSourceBuilder InitialReconnectDelay(TimeSpan initialReconnectDelay)
{
_initialReconnectDelay = initialReconnectDelay;
return this;
}
/// <inheritdoc/>
public IDataSource Build(LdClientContext context)
{
var configuredBaseUri = StandardEndpoints.SelectBaseUri(
context.ServiceEndpoints, e => e.StreamingBaseUri, "Streaming",
context.Logger);
return new StreamingDataSource(
context,
context.DataSourceUpdates,
configuredBaseUri,
_initialReconnectDelay
);
}
/// <inheritdoc/>
public LdValue DescribeConfiguration(LdClientContext context) =>
LdValue.BuildObject()
.WithStreamingProperties(
StandardEndpoints.IsCustomUri(context.ServiceEndpoints, e => e.StreamingBaseUri),
false,
_initialReconnectDelay
)
.Set("usingRelayDaemon", false)
.Build();
}
}