-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ServerDescription.cs
708 lines (666 loc) · 29.6 KB
/
ServerDescription.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
/* Copyright 2013-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Net;
using System.Text;
using MongoDB.Driver.Core.Clusters;
using MongoDB.Driver.Core.Misc;
using MongoDB.Shared;
namespace MongoDB.Driver.Core.Servers
{
/// <summary>
/// Represents information about a server.
/// </summary>
public sealed class ServerDescription : IEquatable<ServerDescription>
{
#region static
private static bool Equals(Exception x, Exception y)
{
if (x == null && y == null)
{
return true;
}
if (x == null || y == null)
{
return false;
}
return
x.GetType() == y.GetType() &&
string.Equals(x.Message, y.Message, StringComparison.Ordinal) &&
string.Equals(x.StackTrace, y.StackTrace, StringComparison.Ordinal) &&
Equals(x.InnerException, y.InnerException);
}
#endregion
// fields
private readonly TimeSpan _averageRoundTripTime;
private readonly EndPoint _canonicalEndPoint;
private readonly ElectionId _electionId;
private readonly EndPoint _endPoint;
private readonly Exception _heartbeatException;
private readonly TimeSpan _heartbeatInterval;
private readonly bool _helloOk;
private readonly DateTime? _lastHeartbeatTimestamp;
private readonly DateTime _lastUpdateTimestamp;
private readonly DateTime? _lastWriteTimestamp;
private readonly TimeSpan? _logicalSessionTimeout;
private readonly int _maxBatchCount;
private readonly int _maxDocumentSize;
private readonly int _maxMessageSize;
private readonly int _maxWireDocumentSize;
private readonly string _reasonChanged;
private readonly ReplicaSetConfig _replicaSetConfig;
private readonly ServerId _serverId;
private readonly ServerState _state;
private readonly TagSet _tags;
private readonly TopologyVersion _topologyVersion;
private readonly ServerType _type;
private readonly SemanticVersion _version;
private readonly Range<int> _wireVersionRange;
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="ServerDescription" /> class.
/// </summary>
/// <param name="serverId">The server identifier.</param>
/// <param name="endPoint">The end point.</param>
/// <param name="reasonChanged">The reason the server description was last changed.</param>
/// <param name="averageRoundTripTime">The average round trip time.</param>
/// <param name="canonicalEndPoint">The canonical end point.</param>
/// <param name="electionId">The election identifier.</param>
/// <param name="heartbeatException">The heartbeat exception.</param>
/// <param name="heartbeatInterval">The heartbeat interval.</param>
/// <param name="helloOk">Whether the server supports the hello command.</param>
/// <param name="lastHeartbeatTimestamp">The last heartbeat timestamp.</param>
/// <param name="lastUpdateTimestamp">The last update timestamp.</param>
/// <param name="lastWriteTimestamp">The last write timestamp.</param>
/// <param name="logicalSessionTimeout">The logical session timeout.</param>
/// <param name="maxBatchCount">The maximum batch count.</param>
/// <param name="maxDocumentSize">The maximum size of a document.</param>
/// <param name="maxMessageSize">The maximum size of a message.</param>
/// <param name="maxWireDocumentSize">The maximum size of a wire document.</param>
/// <param name="replicaSetConfig">The replica set configuration.</param>
/// <param name="state">The server state.</param>
/// <param name="tags">The replica set tags.</param>
/// <param name="topologyVersion">The topology version.</param>
/// <param name="type">The server type.</param>
/// <param name="version">The server version.</param>
/// <param name="wireVersionRange">The wire version range.</param>
/// <exception cref="ArgumentException">EndPoint and ServerId.EndPoint must match.</exception>
public ServerDescription(
ServerId serverId,
EndPoint endPoint,
Optional<string> reasonChanged = default(Optional<string>),
Optional<TimeSpan> averageRoundTripTime = default(Optional<TimeSpan>),
Optional<EndPoint> canonicalEndPoint = default(Optional<EndPoint>),
Optional<ElectionId> electionId = default(Optional<ElectionId>),
Optional<Exception> heartbeatException = default(Optional<Exception>),
Optional<TimeSpan> heartbeatInterval = default(Optional<TimeSpan>),
Optional<bool> helloOk = default(Optional<bool>),
Optional<DateTime?> lastHeartbeatTimestamp = default(Optional<DateTime?>),
Optional<DateTime> lastUpdateTimestamp = default(Optional<DateTime>),
Optional<DateTime?> lastWriteTimestamp = default(Optional<DateTime?>),
Optional<TimeSpan?> logicalSessionTimeout = default(Optional<TimeSpan?>),
Optional<int> maxBatchCount = default(Optional<int>),
Optional<int> maxDocumentSize = default(Optional<int>),
Optional<int> maxMessageSize = default(Optional<int>),
Optional<int> maxWireDocumentSize = default(Optional<int>),
Optional<ReplicaSetConfig> replicaSetConfig = default(Optional<ReplicaSetConfig>),
Optional<ServerState> state = default(Optional<ServerState>),
Optional<TagSet> tags = default(Optional<TagSet>),
Optional<TopologyVersion> topologyVersion = default(Optional<TopologyVersion>),
Optional<ServerType> type = default(Optional<ServerType>),
Optional<SemanticVersion> version = default(Optional<SemanticVersion>),
Optional<Range<int>> wireVersionRange = default(Optional<Range<int>>))
{
Ensure.IsNotNull(endPoint, nameof(endPoint));
Ensure.IsNotNull(serverId, nameof(serverId));
if (!EndPointHelper.Equals(endPoint, serverId.EndPoint))
{
throw new ArgumentException("EndPoint and ServerId.EndPoint must match.");
}
_averageRoundTripTime = averageRoundTripTime.WithDefault(TimeSpan.Zero);
_canonicalEndPoint = canonicalEndPoint.WithDefault(null);
_electionId = electionId.WithDefault(null);
_endPoint = endPoint;
_heartbeatException = heartbeatException.WithDefault(null);
_heartbeatInterval = heartbeatInterval.WithDefault(TimeSpan.Zero);
_helloOk = helloOk.WithDefault(false);
_lastHeartbeatTimestamp = lastHeartbeatTimestamp.WithDefault(null);
_lastUpdateTimestamp = lastUpdateTimestamp.WithDefault(DateTime.UtcNow);
_lastWriteTimestamp = lastWriteTimestamp.WithDefault(null);
_logicalSessionTimeout = logicalSessionTimeout.WithDefault(null);
_maxBatchCount = maxBatchCount.WithDefault(1000);
_maxDocumentSize = maxDocumentSize.WithDefault(4 * 1024 * 1024);
_maxMessageSize = maxMessageSize.WithDefault(Math.Max(_maxDocumentSize + 1024, 16000000));
_maxWireDocumentSize = maxWireDocumentSize.WithDefault(_maxDocumentSize + 16 * 1024);
_reasonChanged = reasonChanged.WithDefault("NotSpecified");
_replicaSetConfig = replicaSetConfig.WithDefault(null);
_serverId = serverId;
_state = state.WithDefault(ServerState.Disconnected);
_tags = tags.WithDefault(null);
_topologyVersion = topologyVersion.WithDefault(null);
_type = type.WithDefault(ServerType.Unknown);
_version = version.WithDefault(null);
_wireVersionRange = wireVersionRange.WithDefault(null);
}
// properties
/// <summary>
/// Gets the average round trip time.
/// </summary>
/// <value>
/// The average round trip time.
/// </value>
public TimeSpan AverageRoundTripTime
{
get { return _averageRoundTripTime; }
}
/// <summary>
/// Gets the canonical end point. This is the endpoint that the cluster knows this
/// server by. Currently, it only applies to a replica set config and will match
/// what is in the replica set configuration.
/// </summary>
public EndPoint CanonicalEndPoint
{
get { return _canonicalEndPoint; }
}
/// <summary>
/// Gets the election identifier.
/// </summary>
public ElectionId ElectionId
{
get { return _electionId; }
}
/// <summary>
/// Gets the end point.
/// </summary>
/// <value>
/// The end point.
/// </value>
public EndPoint EndPoint
{
get { return _endPoint; }
}
/// <summary>
/// Gets the most recent heartbeat exception.
/// </summary>
/// <value>
/// The the most recent heartbeat exception (null if the most recent heartbeat succeeded).
/// </value>
public Exception HeartbeatException
{
get { return _heartbeatException; }
}
/// <summary>
/// Gets the heartbeat interval.
/// </summary>
/// <value>
/// The heartbeat interval.
/// </value>
public TimeSpan HeartbeatInterval
{
get { return _heartbeatInterval; }
}
/// <summary>
/// Whether the server supports the hello command.
/// </summary>
/// <value>
/// True if the server responded with helloOk:true; false otherwise.
/// </value>
public bool HelloOk
{
get { return _helloOk; }
}
/// <summary>
/// Gets a value indicating whether this server is compatible with the driver.
/// </summary>
/// <value>
/// <c>true</c> if this server is compatible with the driver; otherwise, <c>false</c>.
/// </value>
public bool IsCompatibleWithDriver =>
_type == ServerType.LoadBalanced ||
_type == ServerType.Unknown ||
_wireVersionRange == null ||
_wireVersionRange.Overlaps(Cluster.SupportedWireVersionRange);
/// <summary>
/// Gets a value indicating whether this instance is a data bearing server.
/// </summary>
/// <value>
/// <c>true</c> if this instance is a data bearing server; otherwise, <c>false</c>.
/// </value>
public bool IsDataBearing
{
get
{
switch (_type)
{
case ServerType.Standalone:
case ServerType.ReplicaSetPrimary:
case ServerType.ReplicaSetSecondary:
case ServerType.ShardRouter:
case ServerType.LoadBalanced:
return true;
default:
return false;
}
}
}
/// <summary>
/// Gets the last heartbeat timestamp.
/// </summary>
/// <value>
/// The last heartbeat timestamp.
/// </value>
public DateTime? LastHeartbeatTimestamp
{
get { return _lastHeartbeatTimestamp; }
}
/// <summary>
/// Gets the last update timestamp (when the ServerDescription itself was last updated).
/// </summary>
/// <value>
/// The last update timestamp.
/// </value>
public DateTime LastUpdateTimestamp
{
get { return _lastUpdateTimestamp; }
}
/// <summary>
/// Gets the last write timestamp (from the lastWrite field of the hello or legacy hello result).
/// </summary>
/// <value>
/// The last write timestamp.
/// </value>
public DateTime? LastWriteTimestamp
{
get { return _lastWriteTimestamp; }
}
/// <summary>
/// Gets the logical session timeout.
/// </summary>
/// <value>
/// The logical session timeout.
/// </value>
public TimeSpan? LogicalSessionTimeout
{
get { return _logicalSessionTimeout; }
}
/// <summary>
/// Gets the maximum number of documents in a batch.
/// </summary>
/// <value>
/// The maximum number of documents in a batch.
/// </value>
public int MaxBatchCount
{
get { return _maxBatchCount; }
}
/// <summary>
/// Gets the maximum size of a document.
/// </summary>
/// <value>
/// The maximum size of a document.
/// </value>
public int MaxDocumentSize
{
get { return _maxDocumentSize; }
}
/// <summary>
/// Gets the maximum size of a message.
/// </summary>
/// <value>
/// The maximum size of a message.
/// </value>
public int MaxMessageSize
{
get { return _maxMessageSize; }
}
/// <summary>
/// Gets the maximum size of a wire document.
/// </summary>
/// <value>
/// The maximum size of a wire document.
/// </value>
public int MaxWireDocumentSize
{
get { return _maxWireDocumentSize; }
}
/// <summary>
/// Gets the maximum wire version.
/// </summary>
/// <value>
/// The maximum wire version.
/// </value>
public int MaxWireVersion
{
get
{
if (_wireVersionRange == null)
{
throw new InvalidOperationException("MaxWireVersion is not known.");
}
return _wireVersionRange.Max;
}
}
/// <summary>
/// The reason the server description was last changed.
/// </summary>
/// <value>The reason the server description was last changed.</value>
public string ReasonChanged => _reasonChanged;
/// <summary>
/// Gets the replica set configuration.
/// </summary>
/// <value>
/// The replica set configuration.
/// </value>
public ReplicaSetConfig ReplicaSetConfig
{
get { return _replicaSetConfig; }
}
/// <summary>
/// Gets the server identifier.
/// </summary>
/// <value>
/// The server identifier.
/// </value>
public ServerId ServerId
{
get { return _serverId; }
}
/// <summary>
/// Gets the server state.
/// </summary>
/// <value>
/// The server state.
/// </value>
public ServerState State
{
get { return _state; }
}
/// <summary>
/// Gets the replica set tags.
/// </summary>
/// <value>
/// The replica set tags (null if not a replica set or if the replica set has no tags).
/// </value>
public TagSet Tags
{
get { return _tags; }
}
/// <summary>
/// Gets the server type.
/// </summary>
/// <value>
/// The server type.
/// </value>
public ServerType Type
{
get { return _type; }
}
/// <summary>
/// Gets the topology version.
/// </summary>
/// <value>
/// The server topology version.
/// </value>
public TopologyVersion TopologyVersion
{
get { return _topologyVersion; }
}
/// <summary>
/// Gets the approximate server version (only the major and minor version numbers are known).
/// </summary>
/// <value>
/// The server version.
/// </value>
[Obsolete("This property will be removed in a later release.")]
public SemanticVersion Version
{
get { return _version; }
}
/// <summary>
/// Gets the wire version range.
/// </summary>
/// <value>
/// The wire version range.
/// </value>
public Range<int> WireVersionRange
{
get { return _wireVersionRange; }
}
// methods
/// <inheritdoc/>
public override bool Equals(object obj)
{
return Equals(obj as ServerDescription);
}
/// <inheritdoc/>
public bool Equals(ServerDescription other)
{
if (object.ReferenceEquals(other, null) || other.GetType() != typeof(ServerDescription))
{
return false;
}
return
_averageRoundTripTime == other._averageRoundTripTime &&
object.Equals(_canonicalEndPoint, other._canonicalEndPoint) &&
object.Equals(_electionId, other._electionId) &&
EndPointHelper.Equals(_endPoint, other._endPoint) &&
Equals(_heartbeatException, other._heartbeatException) &&
_heartbeatInterval == other._heartbeatInterval &&
_helloOk == other._helloOk &&
_lastHeartbeatTimestamp == other.LastHeartbeatTimestamp &&
_lastUpdateTimestamp == other._lastUpdateTimestamp &&
_lastWriteTimestamp == other._lastWriteTimestamp &&
_logicalSessionTimeout == other._logicalSessionTimeout &&
_maxBatchCount == other._maxBatchCount &&
_maxDocumentSize == other._maxDocumentSize &&
_maxMessageSize == other._maxMessageSize &&
_maxWireDocumentSize == other._maxWireDocumentSize &&
_reasonChanged.Equals(other._reasonChanged, StringComparison.Ordinal) &&
object.Equals(_replicaSetConfig, other._replicaSetConfig) &&
_serverId.Equals(other._serverId) &&
_state == other._state &&
object.Equals(_tags, other._tags) &&
_type == other._type &&
object.Equals(_version, other._version) &&
object.Equals(_wireVersionRange, other._wireVersionRange);
}
/// <inheritdoc/>
public override int GetHashCode()
{
// revision is ignored
return new Hasher()
.Hash(_averageRoundTripTime)
.Hash(_canonicalEndPoint)
.Hash(_electionId)
.Hash(_endPoint)
.Hash(_heartbeatException)
.Hash(_heartbeatInterval)
.Hash(_helloOk)
.Hash(_lastHeartbeatTimestamp)
.Hash(_lastUpdateTimestamp)
.Hash(_lastWriteTimestamp)
.Hash(_logicalSessionTimeout)
.Hash(_maxBatchCount)
.Hash(_maxDocumentSize)
.Hash(_maxMessageSize)
.Hash(_maxWireDocumentSize)
.Hash(_reasonChanged)
.Hash(_replicaSetConfig)
.Hash(_serverId)
.Hash(_state)
.Hash(_tags)
.Hash(_topologyVersion)
.Hash(_type)
.Hash(_version)
.Hash(_wireVersionRange)
.GetHashCode();
}
/// <summary>
/// Determines whether the specified <see cref="ServerDescription" /> can be considered as equal to decide should we publish sdam events or not.
/// </summary>
/// <param name="other">The other server description.</param>
/// <returns><c>true</c>, if sdam events should be suppressed, otherwise <c>false</c>.</returns>
public bool SdamEquals(ServerDescription other)
{
return
EndPointHelper.Equals(_endPoint, other._endPoint) &&
_type == other.Type &&
object.Equals(_wireVersionRange, other._wireVersionRange) &&
EndPointHelper.Equals(_canonicalEndPoint, other._canonicalEndPoint) && // me
EndPointHelper.SequenceEquals(_replicaSetConfig?.Members, other._replicaSetConfig?.Members) && // hosts, passives, arbiters
object.Equals(_tags, other._tags) &&
_replicaSetConfig?.Name == other._replicaSetConfig?.Name && // setName
_replicaSetConfig?.Version == other._replicaSetConfig?.Version && // setVersion
object.Equals(_electionId, other._electionId) &&
EndPointHelper.Equals(_replicaSetConfig?.Primary, other._replicaSetConfig?.Primary) && // primary
_logicalSessionTimeout == other._logicalSessionTimeout &&
Equals(_heartbeatException, other._heartbeatException);
}
/// <inheritdoc/>
public override string ToString()
{
return new StringBuilder()
.Append("{ ")
.AppendFormat("ServerId: \"{0}\"", _serverId)
.AppendFormat(", EndPoint: \"{0}\"", _endPoint)
.AppendFormat(", ReasonChanged: \"{0}\"", _reasonChanged)
.AppendFormat(", State: \"{0}\"", _state)
.Append($", ServerVersion: {_version}")
.Append($", TopologyVersion: {_topologyVersion}")
.AppendFormat(", Type: \"{0}\"", _type)
.AppendFormatIf(_tags != null && !_tags.IsEmpty, ", Tags: \"{0}\"", _tags)
.AppendFormatIf(_state == ServerState.Connected, ", WireVersionRange: \"{0}\"", _wireVersionRange)
.AppendFormatIf(_electionId != null, ", ElectionId: \"{0}\"", _electionId)
.AppendFormatIf(_heartbeatException != null, ", HeartbeatException: \"{0}\"", _heartbeatException)
.AppendFormat(", LastHeartbeatTimestamp: {0}", _lastHeartbeatTimestamp.HasValue ? "\"" + LastHeartbeatTimestamp.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffffffK") + "\"" : "null")
.AppendFormat(", LastUpdateTimestamp: \"{0:yyyy-MM-ddTHH:mm:ss.fffffffK}\"", _lastUpdateTimestamp)
.Append(" }")
.ToString();
}
/// <summary>
/// Returns a new instance of ServerDescription with some values changed.
/// </summary>
/// <param name="reasonChanged">The reason the server description changed.</param>
/// <param name="averageRoundTripTime">The average round trip time.</param>
/// <param name="canonicalEndPoint">The canonical end point.</param>
/// <param name="electionId">The election identifier.</param>
/// <param name="heartbeatException">The heartbeat exception.</param>
/// <param name="heartbeatInterval">The heartbeat interval.</param>
/// <param name="helloOk">Whether the server supports the hello command.</param>
/// <param name="lastHeartbeatTimestamp">The last heartbeat timestamp.</param>
/// <param name="lastUpdateTimestamp">The last update timestamp.</param>
/// <param name="lastWriteTimestamp">The last write timestamp.</param>
/// <param name="logicalSessionTimeout">The logical session timeout.</param>
/// <param name="maxBatchCount">The maximum batch count.</param>
/// <param name="maxDocumentSize">The maximum size of a document.</param>
/// <param name="maxMessageSize">The maximum size of a message.</param>
/// <param name="maxWireDocumentSize">The maximum size of a wire document.</param>
/// <param name="replicaSetConfig">The replica set configuration.</param>
/// <param name="state">The server state.</param>
/// <param name="tags">The replica set tags.</param>
/// <param name="topologyVersion">The topology version.</param>
/// <param name="type">The server type.</param>
/// <param name="version">The server version.</param>
/// <param name="wireVersionRange">The wire version range.</param>
/// <returns>
/// A new instance of ServerDescription.
/// </returns>
public ServerDescription With(
Optional<string> reasonChanged = default(Optional<string>),
Optional<TimeSpan> averageRoundTripTime = default(Optional<TimeSpan>),
Optional<EndPoint> canonicalEndPoint = default(Optional<EndPoint>),
Optional<bool> helloOk = default(Optional<bool>),
Optional<ElectionId> electionId = default(Optional<ElectionId>),
Optional<Exception> heartbeatException = default(Optional<Exception>),
Optional<TimeSpan> heartbeatInterval = default(Optional<TimeSpan>),
Optional<DateTime?> lastHeartbeatTimestamp = default(Optional<DateTime?>),
Optional<DateTime> lastUpdateTimestamp = default(Optional<DateTime>),
Optional<DateTime?> lastWriteTimestamp = default(Optional<DateTime?>),
Optional<TimeSpan?> logicalSessionTimeout = default(Optional<TimeSpan?>),
Optional<int> maxBatchCount = default(Optional<int>),
Optional<int> maxDocumentSize = default(Optional<int>),
Optional<int> maxMessageSize = default(Optional<int>),
Optional<int> maxWireDocumentSize = default(Optional<int>),
Optional<ReplicaSetConfig> replicaSetConfig = default(Optional<ReplicaSetConfig>),
Optional<ServerState> state = default(Optional<ServerState>),
Optional<TagSet> tags = default(Optional<TagSet>),
Optional<TopologyVersion> topologyVersion = default(Optional<TopologyVersion>),
Optional<ServerType> type = default(Optional<ServerType>),
Optional<SemanticVersion> version = default(Optional<SemanticVersion>),
Optional<Range<int>> wireVersionRange = default(Optional<Range<int>>))
{
return new ServerDescription(
_serverId,
_endPoint,
reasonChanged,
averageRoundTripTime: averageRoundTripTime.WithDefault(_averageRoundTripTime),
canonicalEndPoint: canonicalEndPoint.WithDefault(_canonicalEndPoint),
electionId: electionId.WithDefault(_electionId),
heartbeatException: heartbeatException.WithDefault(_heartbeatException),
heartbeatInterval: heartbeatInterval.WithDefault(_heartbeatInterval),
helloOk: helloOk.WithDefault(_helloOk),
lastHeartbeatTimestamp: lastHeartbeatTimestamp.WithDefault(_lastHeartbeatTimestamp),
lastUpdateTimestamp: lastUpdateTimestamp.WithDefault(DateTime.UtcNow),
lastWriteTimestamp: lastWriteTimestamp.WithDefault(_lastWriteTimestamp),
logicalSessionTimeout: logicalSessionTimeout.WithDefault(_logicalSessionTimeout),
maxBatchCount: maxBatchCount.WithDefault(_maxBatchCount),
maxDocumentSize: maxDocumentSize.WithDefault(_maxDocumentSize),
maxMessageSize: maxMessageSize.WithDefault(_maxMessageSize),
maxWireDocumentSize: maxWireDocumentSize.WithDefault(_maxWireDocumentSize),
replicaSetConfig: replicaSetConfig.WithDefault(_replicaSetConfig),
state: state.WithDefault(_state),
tags: tags.WithDefault(_tags),
topologyVersion: topologyVersion.WithDefault(_topologyVersion),
type: type.WithDefault(_type),
version: version.WithDefault(_version),
wireVersionRange: wireVersionRange.WithDefault(_wireVersionRange));
}
/// <summary>
/// Returns a new ServerDescription with a new HeartbeatException.
/// </summary>
/// <param name="heartbeatException">The heartbeat exception.</param>
/// <returns>
/// A new instance of ServerDescription.
/// </returns>
public ServerDescription WithHeartbeatException(Exception heartbeatException)
{
return new ServerDescription(
_serverId,
_endPoint,
reasonChanged: "HeartbeatFailed",
averageRoundTripTime: _averageRoundTripTime,
canonicalEndPoint: _canonicalEndPoint,
electionId: _electionId,
heartbeatException: heartbeatException,
heartbeatInterval: _heartbeatInterval,
helloOk: _helloOk,
lastHeartbeatTimestamp: DateTime.UtcNow,
lastUpdateTimestamp: DateTime.UtcNow,
lastWriteTimestamp: _lastWriteTimestamp,
logicalSessionTimeout: _logicalSessionTimeout,
maxBatchCount: _maxBatchCount,
maxDocumentSize: _maxDocumentSize,
maxMessageSize: _maxMessageSize,
maxWireDocumentSize: _maxWireDocumentSize,
replicaSetConfig: _replicaSetConfig,
state: _state,
tags: _tags,
topologyVersion: _topologyVersion,
type: _type,
version: _version,
wireVersionRange: _wireVersionRange);
}
}
}