1
- /* Copyright 2013-2016 MongoDB Inc.
1
+ /* Copyright 2013-2017 MongoDB Inc.
2
2
*
3
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
4
* you may not use this file except in compliance with the License.
14
14
*/
15
15
16
16
using System ;
17
- using System . Collections . Generic ;
18
- using System . Linq ;
19
17
using System . Net ;
20
- using System . Net . Sockets ;
21
18
using System . Text ;
22
- using System . Threading . Tasks ;
23
- using MongoDB . Bson ;
24
19
using MongoDB . Driver . Core . Clusters ;
25
- using MongoDB . Driver . Core . Connections ;
26
20
using MongoDB . Driver . Core . Misc ;
27
21
using MongoDB . Shared ;
28
22
@@ -42,6 +36,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
42
36
private readonly TimeSpan _heartbeatInterval ;
43
37
private readonly DateTime _lastUpdateTimestamp ;
44
38
private readonly DateTime ? _lastWriteTimestamp ;
39
+ private readonly TimeSpan ? _logicalSessionTimeout ;
45
40
private readonly int _maxBatchCount ;
46
41
private readonly int _maxDocumentSize ;
47
42
private readonly int _maxMessageSize ;
@@ -67,6 +62,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
67
62
/// <param name="heartbeatInterval">The heartbeat interval.</param>
68
63
/// <param name="lastUpdateTimestamp">The last update timestamp.</param>
69
64
/// <param name="lastWriteTimestamp">The last write timestamp.</param>
65
+ /// <param name="logicalSessionTimeout">The logical session timeout.</param>
70
66
/// <param name="maxBatchCount">The maximum batch count.</param>
71
67
/// <param name="maxDocumentSize">The maximum size of a document.</param>
72
68
/// <param name="maxMessageSize">The maximum size of a message.</param>
@@ -77,6 +73,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
77
73
/// <param name="type">The server type.</param>
78
74
/// <param name="version">The server version.</param>
79
75
/// <param name="wireVersionRange">The wire version range.</param>
76
+ /// <exception cref="ArgumentException">EndPoint and ServerId.EndPoint must match.</exception>
80
77
public ServerDescription (
81
78
ServerId serverId ,
82
79
EndPoint endPoint ,
@@ -87,6 +84,7 @@ public ServerDescription(
87
84
Optional < TimeSpan > heartbeatInterval = default ( Optional < TimeSpan > ) ,
88
85
Optional < DateTime > lastUpdateTimestamp = default ( Optional < DateTime > ) ,
89
86
Optional < DateTime ? > lastWriteTimestamp = default ( Optional < DateTime ? > ) ,
87
+ Optional < TimeSpan ? > logicalSessionTimeout = default ( Optional < TimeSpan ? > ) ,
90
88
Optional < int > maxBatchCount = default ( Optional < int > ) ,
91
89
Optional < int > maxDocumentSize = default ( Optional < int > ) ,
92
90
Optional < int > maxMessageSize = default ( Optional < int > ) ,
@@ -113,6 +111,7 @@ public ServerDescription(
113
111
_heartbeatInterval = heartbeatInterval . WithDefault ( TimeSpan . Zero ) ;
114
112
_lastUpdateTimestamp = lastUpdateTimestamp . WithDefault ( DateTime . UtcNow ) ;
115
113
_lastWriteTimestamp = lastWriteTimestamp . WithDefault ( null ) ;
114
+ _logicalSessionTimeout = logicalSessionTimeout . WithDefault ( null ) ;
116
115
_maxBatchCount = maxBatchCount . WithDefault ( 1000 ) ;
117
116
_maxDocumentSize = maxDocumentSize . WithDefault ( 4 * 1024 * 1024 ) ;
118
117
_maxMessageSize = maxMessageSize . WithDefault ( Math . Max ( _maxDocumentSize + 1024 , 16000000 ) ) ;
@@ -189,6 +188,20 @@ public TimeSpan HeartbeatInterval
189
188
get { return _heartbeatInterval ; }
190
189
}
191
190
191
+ /// <summary>
192
+ /// Gets a value indicating whether this server is compatible with the driver.
193
+ /// </summary>
194
+ /// <value>
195
+ /// <c>true</c> if this server is compatible with the driver; otherwise, <c>false</c>.
196
+ /// </value>
197
+ public bool IsCompatibleWithDriver
198
+ {
199
+ get
200
+ {
201
+ return _wireVersionRange == null || _wireVersionRange . Overlaps ( Cluster . SupportedWireVersionRange ) ;
202
+ }
203
+ }
204
+
192
205
/// <summary>
193
206
/// Gets the last update timestamp (when the ServerDescription itself was last updated).
194
207
/// </summary>
@@ -211,6 +224,17 @@ public DateTime? LastWriteTimestamp
211
224
get { return _lastWriteTimestamp ; }
212
225
}
213
226
227
+ /// <summary>
228
+ /// Gets the logical session timeout.
229
+ /// </summary>
230
+ /// <value>
231
+ /// The logical session timeout.
232
+ /// </value>
233
+ public TimeSpan ? LogicalSessionTimeout
234
+ {
235
+ get { return _logicalSessionTimeout ; }
236
+ }
237
+
214
238
/// <summary>
215
239
/// Gets the maximum number of documents in a batch.
216
240
/// </summary>
@@ -356,6 +380,7 @@ public bool Equals(ServerDescription other)
356
380
_heartbeatInterval == other . _heartbeatInterval &&
357
381
_lastUpdateTimestamp == other . _lastUpdateTimestamp &&
358
382
_lastWriteTimestamp == other . _lastWriteTimestamp &&
383
+ _logicalSessionTimeout == other . _logicalSessionTimeout &&
359
384
_maxBatchCount == other . _maxBatchCount &&
360
385
_maxDocumentSize == other . _maxDocumentSize &&
361
386
_maxMessageSize == other . _maxMessageSize &&
@@ -382,6 +407,7 @@ public override int GetHashCode()
382
407
. Hash ( _heartbeatInterval )
383
408
. Hash ( _lastUpdateTimestamp )
384
409
. Hash ( _lastWriteTimestamp )
410
+ . Hash ( _logicalSessionTimeout )
385
411
. Hash ( _maxBatchCount )
386
412
. Hash ( _maxDocumentSize )
387
413
. Hash ( _maxMessageSize )
@@ -423,6 +449,7 @@ public override string ToString()
423
449
/// <param name="heartbeatInterval">The heartbeat interval.</param>
424
450
/// <param name="lastUpdateTimestamp">The last update timestamp.</param>
425
451
/// <param name="lastWriteTimestamp">The last write timestamp.</param>
452
+ /// <param name="logicalSessionTimeout">The logical session timeout.</param>
426
453
/// <param name="maxBatchCount">The maximum batch count.</param>
427
454
/// <param name="maxDocumentSize">The maximum size of a document.</param>
428
455
/// <param name="maxMessageSize">The maximum size of a message.</param>
@@ -444,6 +471,7 @@ public ServerDescription With(
444
471
Optional < TimeSpan > heartbeatInterval = default ( Optional < TimeSpan > ) ,
445
472
Optional < DateTime > lastUpdateTimestamp = default ( Optional < DateTime > ) ,
446
473
Optional < DateTime ? > lastWriteTimestamp = default ( Optional < DateTime ? > ) ,
474
+ Optional < TimeSpan ? > logicalSessionTimeout = default ( Optional < TimeSpan ? > ) ,
447
475
Optional < int > maxBatchCount = default ( Optional < int > ) ,
448
476
Optional < int > maxDocumentSize = default ( Optional < int > ) ,
449
477
Optional < int > maxMessageSize = default ( Optional < int > ) ,
@@ -468,6 +496,7 @@ public ServerDescription With(
468
496
heartbeatInterval . Replaces ( _heartbeatInterval ) ||
469
497
lastUpdateTimestamp . Replaces ( _lastUpdateTimestamp ) ||
470
498
lastWriteTimestamp . Replaces ( _lastWriteTimestamp ) ||
499
+ logicalSessionTimeout . Replaces ( _logicalSessionTimeout ) ||
471
500
maxBatchCount . Replaces ( _maxBatchCount ) ||
472
501
maxDocumentSize . Replaces ( _maxDocumentSize ) ||
473
502
maxMessageSize . Replaces ( _maxMessageSize ) ||
@@ -489,6 +518,7 @@ public ServerDescription With(
489
518
heartbeatInterval : heartbeatInterval . WithDefault ( _heartbeatInterval ) ,
490
519
lastUpdateTimestamp : lastUpdateTimestamp . WithDefault ( _lastUpdateTimestamp ) ,
491
520
lastWriteTimestamp : lastWriteTimestamp . WithDefault ( _lastWriteTimestamp ) ,
521
+ logicalSessionTimeout : logicalSessionTimeout . WithDefault ( _logicalSessionTimeout ) ,
492
522
maxBatchCount : maxBatchCount . WithDefault ( _maxBatchCount ) ,
493
523
maxDocumentSize : maxDocumentSize . WithDefault ( _maxDocumentSize ) ,
494
524
maxMessageSize : maxMessageSize . WithDefault ( _maxMessageSize ) ,
0 commit comments