1- /* Copyright 2013-2016 MongoDB Inc.
1+ /* Copyright 2013-2017 MongoDB Inc.
22*
33* Licensed under the Apache License, Version 2.0 (the "License");
44* you may not use this file except in compliance with the License.
1414*/
1515
1616using System ;
17- using System . Collections . Generic ;
18- using System . Linq ;
1917using System . Net ;
20- using System . Net . Sockets ;
2118using System . Text ;
22- using System . Threading . Tasks ;
23- using MongoDB . Bson ;
2419using MongoDB . Driver . Core . Clusters ;
25- using MongoDB . Driver . Core . Connections ;
2620using MongoDB . Driver . Core . Misc ;
2721using MongoDB . Shared ;
2822
@@ -42,6 +36,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
4236 private readonly TimeSpan _heartbeatInterval ;
4337 private readonly DateTime _lastUpdateTimestamp ;
4438 private readonly DateTime ? _lastWriteTimestamp ;
39+ private readonly TimeSpan ? _logicalSessionTimeout ;
4540 private readonly int _maxBatchCount ;
4641 private readonly int _maxDocumentSize ;
4742 private readonly int _maxMessageSize ;
@@ -67,6 +62,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
6762 /// <param name="heartbeatInterval">The heartbeat interval.</param>
6863 /// <param name="lastUpdateTimestamp">The last update timestamp.</param>
6964 /// <param name="lastWriteTimestamp">The last write timestamp.</param>
65+ /// <param name="logicalSessionTimeout">The logical session timeout.</param>
7066 /// <param name="maxBatchCount">The maximum batch count.</param>
7167 /// <param name="maxDocumentSize">The maximum size of a document.</param>
7268 /// <param name="maxMessageSize">The maximum size of a message.</param>
@@ -77,6 +73,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
7773 /// <param name="type">The server type.</param>
7874 /// <param name="version">The server version.</param>
7975 /// <param name="wireVersionRange">The wire version range.</param>
76+ /// <exception cref="ArgumentException">EndPoint and ServerId.EndPoint must match.</exception>
8077 public ServerDescription (
8178 ServerId serverId ,
8279 EndPoint endPoint ,
@@ -87,6 +84,7 @@ public ServerDescription(
8784 Optional < TimeSpan > heartbeatInterval = default ( Optional < TimeSpan > ) ,
8885 Optional < DateTime > lastUpdateTimestamp = default ( Optional < DateTime > ) ,
8986 Optional < DateTime ? > lastWriteTimestamp = default ( Optional < DateTime ? > ) ,
87+ Optional < TimeSpan ? > logicalSessionTimeout = default ( Optional < TimeSpan ? > ) ,
9088 Optional < int > maxBatchCount = default ( Optional < int > ) ,
9189 Optional < int > maxDocumentSize = default ( Optional < int > ) ,
9290 Optional < int > maxMessageSize = default ( Optional < int > ) ,
@@ -113,6 +111,7 @@ public ServerDescription(
113111 _heartbeatInterval = heartbeatInterval . WithDefault ( TimeSpan . Zero ) ;
114112 _lastUpdateTimestamp = lastUpdateTimestamp . WithDefault ( DateTime . UtcNow ) ;
115113 _lastWriteTimestamp = lastWriteTimestamp . WithDefault ( null ) ;
114+ _logicalSessionTimeout = logicalSessionTimeout . WithDefault ( null ) ;
116115 _maxBatchCount = maxBatchCount . WithDefault ( 1000 ) ;
117116 _maxDocumentSize = maxDocumentSize . WithDefault ( 4 * 1024 * 1024 ) ;
118117 _maxMessageSize = maxMessageSize . WithDefault ( Math . Max ( _maxDocumentSize + 1024 , 16000000 ) ) ;
@@ -189,6 +188,20 @@ public TimeSpan HeartbeatInterval
189188 get { return _heartbeatInterval ; }
190189 }
191190
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+
192205 /// <summary>
193206 /// Gets the last update timestamp (when the ServerDescription itself was last updated).
194207 /// </summary>
@@ -211,6 +224,17 @@ public DateTime? LastWriteTimestamp
211224 get { return _lastWriteTimestamp ; }
212225 }
213226
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+
214238 /// <summary>
215239 /// Gets the maximum number of documents in a batch.
216240 /// </summary>
@@ -356,6 +380,7 @@ public bool Equals(ServerDescription other)
356380 _heartbeatInterval == other . _heartbeatInterval &&
357381 _lastUpdateTimestamp == other . _lastUpdateTimestamp &&
358382 _lastWriteTimestamp == other . _lastWriteTimestamp &&
383+ _logicalSessionTimeout == other . _logicalSessionTimeout &&
359384 _maxBatchCount == other . _maxBatchCount &&
360385 _maxDocumentSize == other . _maxDocumentSize &&
361386 _maxMessageSize == other . _maxMessageSize &&
@@ -382,6 +407,7 @@ public override int GetHashCode()
382407 . Hash ( _heartbeatInterval )
383408 . Hash ( _lastUpdateTimestamp )
384409 . Hash ( _lastWriteTimestamp )
410+ . Hash ( _logicalSessionTimeout )
385411 . Hash ( _maxBatchCount )
386412 . Hash ( _maxDocumentSize )
387413 . Hash ( _maxMessageSize )
@@ -423,6 +449,7 @@ public override string ToString()
423449 /// <param name="heartbeatInterval">The heartbeat interval.</param>
424450 /// <param name="lastUpdateTimestamp">The last update timestamp.</param>
425451 /// <param name="lastWriteTimestamp">The last write timestamp.</param>
452+ /// <param name="logicalSessionTimeout">The logical session timeout.</param>
426453 /// <param name="maxBatchCount">The maximum batch count.</param>
427454 /// <param name="maxDocumentSize">The maximum size of a document.</param>
428455 /// <param name="maxMessageSize">The maximum size of a message.</param>
@@ -444,6 +471,7 @@ public ServerDescription With(
444471 Optional < TimeSpan > heartbeatInterval = default ( Optional < TimeSpan > ) ,
445472 Optional < DateTime > lastUpdateTimestamp = default ( Optional < DateTime > ) ,
446473 Optional < DateTime ? > lastWriteTimestamp = default ( Optional < DateTime ? > ) ,
474+ Optional < TimeSpan ? > logicalSessionTimeout = default ( Optional < TimeSpan ? > ) ,
447475 Optional < int > maxBatchCount = default ( Optional < int > ) ,
448476 Optional < int > maxDocumentSize = default ( Optional < int > ) ,
449477 Optional < int > maxMessageSize = default ( Optional < int > ) ,
@@ -468,6 +496,7 @@ public ServerDescription With(
468496 heartbeatInterval . Replaces ( _heartbeatInterval ) ||
469497 lastUpdateTimestamp . Replaces ( _lastUpdateTimestamp ) ||
470498 lastWriteTimestamp . Replaces ( _lastWriteTimestamp ) ||
499+ logicalSessionTimeout . Replaces ( _logicalSessionTimeout ) ||
471500 maxBatchCount . Replaces ( _maxBatchCount ) ||
472501 maxDocumentSize . Replaces ( _maxDocumentSize ) ||
473502 maxMessageSize . Replaces ( _maxMessageSize ) ||
@@ -489,6 +518,7 @@ public ServerDescription With(
489518 heartbeatInterval : heartbeatInterval . WithDefault ( _heartbeatInterval ) ,
490519 lastUpdateTimestamp : lastUpdateTimestamp . WithDefault ( _lastUpdateTimestamp ) ,
491520 lastWriteTimestamp : lastWriteTimestamp . WithDefault ( _lastWriteTimestamp ) ,
521+ logicalSessionTimeout : logicalSessionTimeout . WithDefault ( _logicalSessionTimeout ) ,
492522 maxBatchCount : maxBatchCount . WithDefault ( _maxBatchCount ) ,
493523 maxDocumentSize : maxDocumentSize . WithDefault ( _maxDocumentSize ) ,
494524 maxMessageSize : maxMessageSize . WithDefault ( _maxMessageSize ) ,
0 commit comments