Repository navigation
Expand file tree
/
Copy pathDnsClusterSettingsBuilder.cs
More file actions
109 lines (101 loc) · 4.97 KB
/
Copy pathDnsClusterSettingsBuilder.cs
File metadata and controls
109 lines (101 loc) · 4.97 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Net;
using EventStore.ClientAPI.Common.Utils;
namespace EventStore.ClientAPI
{
/// <summary>
/// Fluent builder used to configure <see cref="ClusterSettings" /> for connecting to a cluster
/// using DNS discovery.
/// </summary>
public class DnsClusterSettingsBuilder
{
private string _clusterDns;
private int _maxDiscoverAttempts = Consts.DefaultMaxClusterDiscoverAttempts;
private int _managerExternalHttpPort = Consts.DefaultClusterManagerExternalHttpPort;
private TimeSpan _gossipTimeout = TimeSpan.FromSeconds(1);
private bool _preferRandomNode = false;
/// <summary>
/// Sets the DNS name under which cluster nodes are listed.
/// </summary>
/// <param name="clusterDns">The DNS name under which cluster nodes are listed.</param>
/// <returns>A <see cref="DnsClusterSettingsBuilder"/> for further configuration.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="clusterDns" /> is null or empty.</exception>
public DnsClusterSettingsBuilder SetClusterDns(string clusterDns)
{
Ensure.NotNullOrEmpty(clusterDns, "clusterDns");
_clusterDns = clusterDns;
return this;
}
/// <summary>
/// Sets the maximum number of attempts for discovery.
/// </summary>
/// <param name="maxDiscoverAttempts">The maximum number of attempts for DNS discovery.</param>
/// <returns>A <see cref="DnsClusterSettingsBuilder"/> for further configuration.</returns>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="maxDiscoverAttempts" /> is less than or equal to 0.</exception>
public DnsClusterSettingsBuilder SetMaxDiscoverAttempts(int maxDiscoverAttempts)
{
if (maxDiscoverAttempts <= 0)
throw new ArgumentOutOfRangeException("maxDiscoverAttempts", string.Format("maxDiscoverAttempts value is out of range: {0}. Allowed range: [-1, infinity].", maxDiscoverAttempts));
_maxDiscoverAttempts = maxDiscoverAttempts;
return this;
}
/// <summary>
/// Sets the period after which gossip times out if none is received.
/// </summary>
/// <param name="timeout">The period after which gossip times out if none is received.</param>
/// <returns>A <see cref="DnsClusterSettingsBuilder"/> for further configuration.</returns>
public DnsClusterSettingsBuilder SetGossipTimeout(TimeSpan timeout)
{
_gossipTimeout = timeout;
return this;
}
/// <summary>
/// Whether to randomly choose a node that's alive from the known nodes.
/// </summary>
/// <returns>A <see cref="DnsClusterSettingsBuilder"/> for further configuration.</returns>
public DnsClusterSettingsBuilder PreferRandomNode()
{
_preferRandomNode = true;
return this;
}
/// <summary>
/// Sets the well-known port on which the cluster gossip is taking place.
///
/// If you are using the commercial edition of Event Store HA, with Manager nodes in
/// place, this should be the port number of the External HTTP port on which the
/// managers are running.
///
/// If you are using the open source edition of Event Store HA, this should be the
/// External HTTP port that the nodes are running on. If you cannot use a well-known
/// port for this across all nodes, you can instead use gossip seed discovery and set
/// the <see cref="IPEndPoint" /> of some seed nodes instead.
/// </summary>
/// <param name="clusterGossipPort">The cluster gossip port.</param>
/// <returns>A <see cref="DnsClusterSettingsBuilder"/> for further configuration.</returns>
public DnsClusterSettingsBuilder SetClusterGossipPort(int clusterGossipPort)
{
Ensure.Positive(clusterGossipPort, "clusterGossipPort");
_managerExternalHttpPort = clusterGossipPort;
return this;
}
/// <summary>
/// Builds a <see cref="ClusterSettings"/> object from a <see cref="DnsClusterSettingsBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="DnsClusterSettingsBuilder"/> from which to build a <see cref="ClusterSettings"/></param>
/// <returns></returns>
public static implicit operator ClusterSettings(DnsClusterSettingsBuilder builder)
{
return builder.Build();
}
/// <summary>
/// Builds a <see cref="ClusterSettings"/> object from a <see cref="DnsClusterSettingsBuilder"/>.
/// </summary>
public ClusterSettings Build() {
return new ClusterSettings(this._clusterDns,
this._maxDiscoverAttempts,
this._managerExternalHttpPort,
this._gossipTimeout,
this._preferRandomNode);
}
}
}