Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CSHARP-589: isolating the core from the public api.

  • Loading branch information...
commit f7bdc76c2d35d5ab5f9ec4959a6195a010ef96cb 1 parent 7be9756
@craiggwilson craiggwilson authored
View
39 MongoDB.Driver/Communication/MongoConnection.cs
@@ -198,10 +198,10 @@ internal void Authenticate(string databaseName, MongoCredentials credentials)
// (with the restriction that a particular database can only be authenticated against once and therefore with only one set of credentials)
// assume that IsAuthenticated was called first and returned false
- internal bool CanAuthenticate(MongoDatabase database)
+ internal bool CanAuthenticate(string databaseName, MongoCredentials credentials)
{
if (_state == MongoConnectionState.Closed) { throw new InvalidOperationException("Connection is closed."); }
- if (database == null)
+ if (databaseName == null)
{
return true;
}
@@ -214,13 +214,13 @@ internal bool CanAuthenticate(MongoDatabase database)
else
{
// a connection with existing authentications can't be used without credentials
- if (database.Credentials == null)
+ if (credentials == null)
{
return false;
}
// a connection with existing authentications can't be used with new admin credentials
- if (database.Credentials.Admin)
+ if (credentials.Admin)
{
return false;
}
@@ -232,7 +232,7 @@ internal bool CanAuthenticate(MongoDatabase database)
}
// a connection with an existing authentication to a database can't authenticate for the same database again
- if (_authentications.ContainsKey(database.Name))
+ if (_authentications.ContainsKey(databaseName))
{
return false;
}
@@ -241,10 +241,10 @@ internal bool CanAuthenticate(MongoDatabase database)
}
}
- internal void CheckAuthentication(MongoDatabase database)
+ internal void CheckAuthentication(string databaseName, MongoCredentials credentials)
{
if (_state == MongoConnectionState.Closed) { throw new InvalidOperationException("Connection is closed."); }
- if (database.Credentials == null)
+ if (credentials == null)
{
if (_authentications.Count != 0)
{
@@ -253,12 +253,11 @@ internal void CheckAuthentication(MongoDatabase database)
}
else
{
- var credentials = database.Credentials;
- var authenticationDatabaseName = credentials.Admin ? "admin" : database.Name;
+ var authenticationDatabaseName = credentials.Admin ? "admin" : databaseName;
Authentication authentication;
if (_authentications.TryGetValue(authenticationDatabaseName, out authentication))
{
- if (authentication.Credentials != database.Credentials)
+ if (authentication.Credentials != credentials)
{
// this shouldn't happen because a connection would have been chosen from the connection pool only if it was viable
if (authenticationDatabaseName == "admin")
@@ -279,7 +278,7 @@ internal void CheckAuthentication(MongoDatabase database)
// this shouldn't happen because a connection would have been chosen from the connection pool only if it was viable
throw new MongoInternalException("The connection cannot be authenticated against the admin database because it is already authenticated against other databases.");
}
- Authenticate(authenticationDatabaseName, database.Credentials);
+ Authenticate(authenticationDatabaseName, credentials);
}
}
}
@@ -310,27 +309,27 @@ internal void Close()
}
}
- internal bool IsAuthenticated(MongoDatabase database)
+ internal bool IsAuthenticated(string databaseName, MongoCredentials credentials)
{
if (_state == MongoConnectionState.Closed) { throw new InvalidOperationException("Connection is closed."); }
- if (database == null)
+ if (databaseName == null)
{
return true;
}
lock (_connectionLock)
{
- if (database.Credentials == null)
+ if (credentials == null)
{
return _authentications.Count == 0;
}
else
{
- var authenticationDatabaseName = database.Credentials.Admin ? "admin" : database.Name;
+ var authenticationDatabaseName = credentials.Admin ? "admin" : databaseName;
Authentication authentication;
if (_authentications.TryGetValue(authenticationDatabaseName, out authentication))
{
- return database.Credentials == authentication.Credentials;
+ return credentials == authentication.Credentials;
}
else
{
@@ -373,10 +372,10 @@ internal void Open()
tcpClient.Connect(ipEndPoint);
var stream = (Stream)tcpClient.GetStream();
- if (_serverInstance.Server.Settings.UseSsl)
+ if (_serverInstance.Settings.UseSsl)
{
SslStream sslStream;
- if (_serverInstance.Server.Settings.VerifySslCertificate)
+ if (_serverInstance.Settings.VerifySslCertificate)
{
sslStream = new SslStream(stream, false); // don't leave inner stream open
}
@@ -458,7 +457,7 @@ internal void Open()
using (var buffer = new BsonBuffer())
{
var networkStream = GetNetworkStream();
- var readTimeout = (int)_serverInstance.Server.Settings.SocketTimeout.TotalMilliseconds;
+ var readTimeout = (int)_serverInstance.Settings.SocketTimeout.TotalMilliseconds;
if (readTimeout != 0)
{
networkStream.ReadTimeout = readTimeout;
@@ -511,7 +510,7 @@ internal WriteConcernResult SendMessage(MongoRequestMessage message, WriteConcer
try
{
var networkStream = GetNetworkStream();
- var writeTimeout = (int)_serverInstance.Server.Settings.SocketTimeout.TotalMilliseconds;
+ var writeTimeout = (int)_serverInstance.Settings.SocketTimeout.TotalMilliseconds;
if (writeTimeout != 0)
{
networkStream.WriteTimeout = writeTimeout;
View
33 MongoDB.Driver/Communication/MongoConnectionPool.cs
@@ -29,7 +29,7 @@ public class MongoConnectionPool
{
// private fields
private object _connectionPoolLock = new object();
- private MongoServer _server;
+ private MongoServerSettings _settings;
private MongoServerInstance _serverInstance;
private int _poolSize;
private List<MongoConnection> _availableConnections = new List<MongoConnection>();
@@ -42,7 +42,7 @@ public class MongoConnectionPool
// constructors
internal MongoConnectionPool(MongoServerInstance serverInstance)
{
- _server = serverInstance.Server;
+ _settings = serverInstance.Settings;
_serverInstance = serverInstance;
_poolSize = 0;
}
@@ -81,16 +81,11 @@ public MongoServerInstance ServerInstance
}
// internal methods
- internal MongoConnection AcquireConnection(MongoDatabase database)
+ internal MongoConnection AcquireConnection(string databaseName, MongoCredentials credentials)
{
- if (database != null && database.Server != _server)
- {
- throw new ArgumentException("This connection pool is for a different server.", "database");
- }
-
lock (_connectionPoolLock)
{
- if (_waitQueueSize >= _server.Settings.WaitQueueSize)
+ if (_waitQueueSize >= _settings.WaitQueueSize)
{
throw new MongoConnectionException("Too many threads are already waiting for a connection.");
}
@@ -98,7 +93,7 @@ internal MongoConnection AcquireConnection(MongoDatabase database)
_waitQueueSize += 1;
try
{
- DateTime timeoutAt = DateTime.UtcNow + _server.Settings.WaitQueueTimeout;
+ DateTime timeoutAt = DateTime.UtcNow + _settings.WaitQueueTimeout;
while (true)
{
if (_availableConnections.Count > 0)
@@ -106,7 +101,7 @@ internal MongoConnection AcquireConnection(MongoDatabase database)
// first try to find the most recently used connection that is already authenticated for this database
for (int i = _availableConnections.Count - 1; i >= 0; i--)
{
- if (_availableConnections[i].IsAuthenticated(database))
+ if (_availableConnections[i].IsAuthenticated(databaseName, credentials))
{
var connection = _availableConnections[i];
_availableConnections.RemoveAt(i);
@@ -117,7 +112,7 @@ internal MongoConnection AcquireConnection(MongoDatabase database)
// otherwise find the most recently used connection that can be authenticated for this database
for (int i = _availableConnections.Count - 1; i >= 0; i--)
{
- if (_availableConnections[i].CanAuthenticate(database))
+ if (_availableConnections[i].CanAuthenticate(databaseName, credentials))
{
var connection = _availableConnections[i];
_availableConnections.RemoveAt(i);
@@ -133,7 +128,7 @@ internal MongoConnection AcquireConnection(MongoDatabase database)
}
// create a new connection if maximum pool size has not been reached
- if (_poolSize < _server.Settings.MaxConnectionPoolSize)
+ if (_poolSize < _settings.MaxConnectionPoolSize)
{
// make sure connection is created successfully before incrementing poolSize
// connection will be opened later outside of the lock
@@ -208,11 +203,11 @@ internal void MaintainPoolSize()
// remove old connections before idle connections
var now = DateTime.UtcNow;
- if (oldestConnection != null && now > oldestConnection.CreatedAt + _server.Settings.MaxConnectionLifeTime)
+ if (oldestConnection != null && now > oldestConnection.CreatedAt + _settings.MaxConnectionLifeTime)
{
connectionToRemove = oldestConnection;
}
- else if (_poolSize > _server.Settings.MinConnectionPoolSize && lruConnection != null && now > lruConnection.LastUsedAt + _server.Settings.MaxConnectionIdleTime)
+ else if (_poolSize > _settings.MinConnectionPoolSize && lruConnection != null && now > lruConnection.LastUsedAt + _settings.MaxConnectionIdleTime)
{
connectionToRemove = lruConnection;
}
@@ -226,7 +221,7 @@ internal void MaintainPoolSize()
RemoveConnection(connectionToRemove);
}
- if (_poolSize < _server.Settings.MinConnectionPoolSize)
+ if (_poolSize < _settings.MinConnectionPoolSize)
{
ThreadPool.QueueUserWorkItem(EnsureMinConnectionPoolSizeWorkItem, _generationId);
}
@@ -255,7 +250,7 @@ internal void ReleaseConnection(MongoConnection connection)
// but only remove one connection at most per timer tick to avoid connection storms
if (_connectionsRemovedSinceLastTimerTick == 0)
{
- if (DateTime.UtcNow - connection.CreatedAt > _server.Settings.MaxConnectionLifeTime)
+ if (DateTime.UtcNow - connection.CreatedAt > _settings.MaxConnectionLifeTime)
{
RemoveConnection(connection);
return;
@@ -303,7 +298,7 @@ private void EnsureMinConnectionPoolSizeWorkItem(object state)
lock (_connectionPoolLock)
{
// stop if the connection pool generationId has changed or we have already reached MinConnectionPoolSize
- if (_generationId != forGenerationId || _poolSize >= _server.Settings.MinConnectionPoolSize)
+ if (_generationId != forGenerationId || _poolSize >= _settings.MinConnectionPoolSize)
{
return;
}
@@ -320,7 +315,7 @@ private void EnsureMinConnectionPoolSizeWorkItem(object state)
var added = false;
lock (_connectionPoolLock)
{
- if (_generationId == forGenerationId && _poolSize < _server.Settings.MaxConnectionPoolSize)
+ if (_generationId == forGenerationId && _poolSize < _settings.MaxConnectionPoolSize)
{
_availableConnections.Add(connection);
_poolSize++;
View
26 MongoDB.Driver/Communication/MongoServerInstance.cs
@@ -43,7 +43,7 @@ public sealed class MongoServerInstance
// private fields
private readonly object _serverInstanceLock = new object();
- private readonly MongoServer _server;
+ private readonly MongoServerSettings _settings;
private readonly MongoConnectionPool _connectionPool;
private readonly PingTimeAggregator _pingTimeAggregator;
private MongoServerAddress _address;
@@ -60,11 +60,11 @@ public sealed class MongoServerInstance
/// <summary>
/// Initializes a new instance of the <see cref="MongoServerInstance"/> class.
/// </summary>
- /// <param name="server">The server.</param>
+ /// <param name="settings">The settings.</param>
/// <param name="address">The address.</param>
- internal MongoServerInstance(MongoServer server, MongoServerAddress address)
+ internal MongoServerInstance(MongoServerSettings settings, MongoServerAddress address)
{
- _server = server;
+ _settings = settings;
_address = address;
_sequentialId = Interlocked.Increment(ref __nextSequentialId);
_state = MongoServerState.Disconnected;
@@ -284,9 +284,9 @@ public int SequentialId
/// <summary>
/// Gets the server for this server instance.
/// </summary>
- public MongoServer Server
+ public MongoServerSettings Settings
{
- get { return _server; }
+ get { return _settings; }
}
/// <summary>
@@ -315,7 +315,7 @@ public IPEndPoint GetIPEndPoint()
var ipEndPoint = Interlocked.CompareExchange(ref _ipEndPoint, null, null);
if (ipEndPoint == null)
{
- var addressFamily = _server.Settings.IPv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
+ var addressFamily = _settings.IPv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
ipEndPoint = _address.ToIPEndPoint(addressFamily);
Interlocked.CompareExchange(ref _ipEndPoint, _ipEndPoint, null);
}
@@ -369,9 +369,11 @@ public void VerifyState()
/// <summary>
/// Acquires the connection.
/// </summary>
- /// <param name="database">The database.</param>
+ /// <param name="databaseName">Name of the database.</param>
+ /// <param name="credentials">The credentials.</param>
/// <returns>A MongoConnection.</returns>
- internal MongoConnection AcquireConnection(MongoDatabase database)
+ /// <exception cref="System.InvalidOperationException"></exception>
+ internal MongoConnection AcquireConnection(string databaseName, MongoCredentials credentials)
{
MongoConnection connection;
lock (_serverInstanceLock)
@@ -383,11 +385,11 @@ internal MongoConnection AcquireConnection(MongoDatabase database)
}
}
- connection = _connectionPool.AcquireConnection(database);
+ connection = _connectionPool.AcquireConnection(databaseName, credentials);
try
{
- connection.CheckAuthentication(database); // will authenticate if necessary
+ connection.CheckAuthentication(databaseName, credentials); // will authenticate if necessary
}
catch (MongoAuthenticationException)
{
@@ -424,7 +426,7 @@ internal void Connect()
try
{
- var connection = _connectionPool.AcquireConnection(null);
+ var connection = _connectionPool.AcquireConnection(null, null);
try
{
Ping(connection);
View
28 MongoDB.Driver/Communication/Proxies/DirectMongoServerProxy.cs
@@ -27,7 +27,7 @@ internal sealed class DirectMongoServerProxy : IMongoServerProxy
{
// private fields
private readonly object _stateLock = new object();
- private readonly MongoServer _server;
+ private readonly MongoServerSettings _settings;
private readonly MongoServerInstance _instance;
private int _connectionAttempt;
@@ -35,22 +35,22 @@ internal sealed class DirectMongoServerProxy : IMongoServerProxy
/// <summary>
/// Initializes a new instance of the <see cref="DirectMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
- public DirectMongoServerProxy(MongoServer server)
+ /// <param name="settings">The settings.</param>
+ public DirectMongoServerProxy(MongoServerSettings settings)
{
- _server = server;
- _instance = new MongoServerInstance(server, server.Settings.Servers.First());
+ _settings = settings;
+ _instance = new MongoServerInstance(settings, settings.Servers.First());
}
/// <summary>
/// Initializes a new instance of the <see cref="DirectMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
+ /// <param name="serverSettings">The server settings.</param>
/// <param name="instance">The instance.</param>
/// <param name="connectionAttempt">The connection attempt.</param>
- public DirectMongoServerProxy(MongoServer server, MongoServerInstance instance, int connectionAttempt)
+ public DirectMongoServerProxy(MongoServerSettings serverSettings, MongoServerInstance instance, int connectionAttempt)
{
- _server = server;
+ _settings = serverSettings;
_instance = instance;
_connectionAttempt = connectionAttempt;
}
@@ -112,7 +112,7 @@ public MongoServerInstance ChooseServerInstance(ReadPreference readPreference)
{
lock (_stateLock)
{
- Connect(_server.Settings.ConnectTimeout, readPreference);
+ Connect(_settings.ConnectTimeout, readPreference);
}
}
@@ -139,17 +139,17 @@ public void Connect(TimeSpan timeout, ReadPreference readPreference)
{
_connectionAttempt++;
var exceptions = new List<Exception>();
- foreach (var address in _server.Settings.Servers)
+ foreach (var address in _settings.Servers)
{
try
{
_instance.Address = address;
_instance.Connect(); // TODO: what about timeout?
- if (_server.Settings.ReplicaSetName != null &&
- (_instance.InstanceType != MongoServerInstanceType.ReplicaSetMember || _instance.ReplicaSetInformation.Name != _server.Settings.ReplicaSetName))
+ if (_settings.ReplicaSetName != null &&
+ (_instance.InstanceType != MongoServerInstanceType.ReplicaSetMember || _instance.ReplicaSetInformation.Name != _settings.ReplicaSetName))
{
- exceptions.Add(new MongoConnectionException(string.Format("The server '{0}' is not a member of replica set '{1}'.", address, _server.Settings.ReplicaSetName)));
+ exceptions.Add(new MongoConnectionException(string.Format("The server '{0}' is not a member of replica set '{1}'.", address, _settings.ReplicaSetName)));
_instance.Disconnect();
continue;
}
@@ -166,7 +166,7 @@ public void Connect(TimeSpan timeout, ReadPreference readPreference)
}
}
- var firstAddress = _server.Settings.Servers.First();
+ var firstAddress = _settings.Servers.First();
var firstException = exceptions.First();
var message = string.Format("Unable to connect to server {0}: {1}.", firstAddress, firstException.Message);
var connectionException = new MongoConnectionException(message, firstException);
View
18 MongoDB.Driver/Communication/Proxies/DiscoveringMongoServerProxy.cs
@@ -27,7 +27,7 @@ namespace MongoDB.Driver.Internal
internal sealed class DiscoveringMongoServerProxy : IMongoServerProxy
{
private readonly object _lock = new object();
- private readonly MongoServer _server;
+ private readonly MongoServerSettings _settings;
private readonly ReadOnlyCollection<MongoServerInstance> _instances;
// volatile will ensure that our reads are not reordered such one could get placed before a write. This
@@ -41,12 +41,12 @@ internal sealed class DiscoveringMongoServerProxy : IMongoServerProxy
/// <summary>
/// Initializes a new instance of the <see cref="DiscoveringMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
- public DiscoveringMongoServerProxy(MongoServer server)
+ /// <param name="settings">The settings.</param>
+ public DiscoveringMongoServerProxy(MongoServerSettings settings)
{
_state = MongoServerState.Disconnected;
- _server = server;
- _instances = server.Settings.Servers.Select(a => new MongoServerInstance(server, a)).ToList().AsReadOnly();
+ _settings = settings;
+ _instances = settings.Servers.Select(a => new MongoServerInstance(settings, a)).ToList().AsReadOnly();
}
// public properties
@@ -122,7 +122,7 @@ public MongoServerState State
/// <returns>A MongoServerInstance</returns>
public MongoServerInstance ChooseServerInstance(ReadPreference readPreference)
{
- EnsureInstanceManager(_server.Settings.ConnectTimeout);
+ EnsureInstanceManager(_settings.ConnectTimeout);
return _serverProxy.ChooseServerInstance(readPreference);
}
@@ -248,11 +248,11 @@ private void CreateActualProxy(MongoServerInstance instance, BlockingQueue<Mongo
{
if (instance.InstanceType == MongoServerInstanceType.ReplicaSetMember)
{
- _serverProxy = new ReplicaSetMongoServerProxy(_server, _instances, connectionQueue, _connectionAttempt);
+ _serverProxy = new ReplicaSetMongoServerProxy(_settings, _instances, connectionQueue, _connectionAttempt);
}
else if (instance.InstanceType == MongoServerInstanceType.ShardRouter)
{
- _serverProxy = new ShardedMongoServerProxy(_server, _instances, connectionQueue, _connectionAttempt);
+ _serverProxy = new ShardedMongoServerProxy(_settings, _instances, connectionQueue, _connectionAttempt);
}
else if (instance.InstanceType == MongoServerInstanceType.StandAlone)
{
@@ -262,7 +262,7 @@ private void CreateActualProxy(MongoServerInstance instance, BlockingQueue<Mongo
otherInstance.Disconnect();
}
- _serverProxy = new DirectMongoServerProxy(_server, instance, _connectionAttempt);
+ _serverProxy = new DirectMongoServerProxy(_settings, instance, _connectionAttempt);
}
else
{
View
20 MongoDB.Driver/Communication/Proxies/MongoServerProxyFactory.cs
@@ -29,18 +29,18 @@ internal class MongoServerProxyFactory
/// <summary>
/// Creates an IMongoServerProxy of some type that depends on the server settings.
/// </summary>
- /// <param name="server">The server.</param>
+ /// <param name="settings">The settings.</param>
/// <returns>An IMongoServerProxy.</returns>
- public IMongoServerProxy Create(MongoServer server)
+ public IMongoServerProxy Create(MongoServerSettings settings)
{
- var connectionMode = server.Settings.ConnectionMode;
- if (server.Settings.ConnectionMode == ConnectionMode.Automatic)
+ var connectionMode = settings.ConnectionMode;
+ if (settings.ConnectionMode == ConnectionMode.Automatic)
{
- if (server.Settings.ReplicaSetName != null)
+ if (settings.ReplicaSetName != null)
{
connectionMode = ConnectionMode.ReplicaSet;
}
- else if (server.Settings.Servers.Count() == 1)
+ else if (settings.Servers.Count() == 1)
{
connectionMode = ConnectionMode.Direct;
}
@@ -49,13 +49,13 @@ public IMongoServerProxy Create(MongoServer server)
switch (connectionMode)
{
case ConnectionMode.Direct:
- return new DirectMongoServerProxy(server);
+ return new DirectMongoServerProxy(settings);
case ConnectionMode.ReplicaSet:
- return new ReplicaSetMongoServerProxy(server);
+ return new ReplicaSetMongoServerProxy(settings);
case ConnectionMode.ShardRouter:
- return new ShardedMongoServerProxy(server);
+ return new ShardedMongoServerProxy(settings);
default:
- return new DiscoveringMongoServerProxy(server);
+ return new DiscoveringMongoServerProxy(settings);
}
}
}
View
30 MongoDB.Driver/Communication/Proxies/MultipleInstanceMongoServerProxy.cs
@@ -30,36 +30,36 @@ internal abstract class MultipleInstanceMongoServerProxy : IMongoServerProxy
private readonly object _lock = new object();
private readonly ConnectedInstanceCollection _connectedInstances;
private readonly List<MongoServerInstance> _instances;
- private readonly MongoServer _server;
+ private readonly MongoServerSettings _settings;
private int _connectionAttempt;
private int _outstandingInstanceConnections;
private MongoServerState _state;
/// <summary>
- /// Initializes a new instance of the <see cref="ShardedMongoServerProxy"/> class.
+ /// Initializes a new instance of the <see cref="MultipleInstanceMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
- protected MultipleInstanceMongoServerProxy(MongoServer server)
+ /// <param name="settings">The settings.</param>
+ protected MultipleInstanceMongoServerProxy(MongoServerSettings settings)
{
- _server = server;
+ _settings = settings;
_connectedInstances = new ConnectedInstanceCollection();
_instances = new List<MongoServerInstance>();
- MakeInstancesMatchAddresses(server.Settings.Servers);
+ MakeInstancesMatchAddresses(settings.Servers);
}
/// <summary>
- /// Initializes a new instance of the <see cref="ShardedMongoServerProxy"/> class.
+ /// Initializes a new instance of the <see cref="MultipleInstanceMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
+ /// <param name="settings">The settings.</param>
/// <param name="instances">The instances.</param>
/// <param name="connectionQueue">The state change queue.</param>
/// <param name="connectionAttempt">The connection attempt.</param>
/// <remarks>This constructor is used when the instances have already been instructed to connect.</remarks>
- protected MultipleInstanceMongoServerProxy(MongoServer server, IEnumerable<MongoServerInstance> instances, BlockingQueue<MongoServerInstance> connectionQueue, int connectionAttempt)
+ protected MultipleInstanceMongoServerProxy(MongoServerSettings settings, IEnumerable<MongoServerInstance> instances, BlockingQueue<MongoServerInstance> connectionQueue, int connectionAttempt)
{
_state = MongoServerState.Connecting;
- _server = server;
+ _settings = settings;
_connectedInstances = new ConnectedInstanceCollection();
_connectionAttempt = connectionAttempt;
@@ -141,11 +141,11 @@ public MongoServerState State
// protected properties
/// <summary>
- /// Gets the server.
+ /// Gets the server settings.
/// </summary>
- protected MongoServer Server
+ protected MongoServerSettings Settings
{
- get { return _server; }
+ get { return _settings; }
}
// public methods
@@ -165,7 +165,7 @@ public MongoServerInstance ChooseServerInstance(ReadPreference readPreference)
}
if (attempt == 1)
{
- Connect(_server.Settings.ConnectTimeout, readPreference);
+ Connect(_settings.ConnectTimeout, readPreference);
}
}
@@ -341,7 +341,7 @@ protected void EnsureInstanceWithAddress(MongoServerAddress address)
{
if (!_instances.Any(x => x.Address == address))
{
- var instance = new MongoServerInstance(_server, address);
+ var instance = new MongoServerInstance(_settings, address);
AddInstance(instance);
if (_state != MongoServerState.Disconnecting && _state != MongoServerState.Disconnected)
{
View
16 MongoDB.Driver/Communication/Proxies/ReplicaSetMongoServerProxy.cs
@@ -35,22 +35,22 @@ internal sealed class ReplicaSetMongoServerProxy : MultipleInstanceMongoServerPr
/// <summary>
/// Initializes a new instance of the <see cref="ReplicaSetMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
- public ReplicaSetMongoServerProxy(MongoServer server)
- : base(server)
+ /// <param name="settings">The settings.</param>
+ public ReplicaSetMongoServerProxy(MongoServerSettings settings)
+ : base(settings)
{
- _replicaSetName = server.Settings.ReplicaSetName;
+ _replicaSetName = settings.ReplicaSetName;
}
/// <summary>
/// Initializes a new instance of the <see cref="ReplicaSetMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
+ /// <param name="serverSettings">The server settings.</param>
/// <param name="instances">The instances.</param>
/// <param name="stateChangeQueue">The state change queue.</param>
/// <param name="connectionAttempt">The connection attempt.</param>
- public ReplicaSetMongoServerProxy(MongoServer server, IEnumerable<MongoServerInstance> instances, BlockingQueue<MongoServerInstance> stateChangeQueue, int connectionAttempt)
- : base(server, instances, stateChangeQueue, connectionAttempt)
+ public ReplicaSetMongoServerProxy(MongoServerSettings serverSettings, IEnumerable<MongoServerInstance> instances, BlockingQueue<MongoServerInstance> stateChangeQueue, int connectionAttempt)
+ : base(serverSettings, instances, stateChangeQueue, connectionAttempt)
{ }
// public properties
@@ -72,7 +72,7 @@ public string ReplicaSetName
// protected methods
protected override MongoServerInstance ChooseServerInstance(ConnectedInstanceCollection connectedInstances, ReadPreference readPreference)
{
- var secondaryAcceptableLatency = Server.Settings.SecondaryAcceptableLatency;
+ var secondaryAcceptableLatency = Settings.SecondaryAcceptableLatency;
switch (readPreference.ReadPreferenceMode)
{
View
14 MongoDB.Driver/Communication/Proxies/ShardedMongoServerProxy.cs
@@ -34,20 +34,20 @@ internal sealed class ShardedMongoServerProxy : MultipleInstanceMongoServerProxy
/// <summary>
/// Initializes a new instance of the <see cref="ShardedMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
- public ShardedMongoServerProxy(MongoServer server)
- : base(server)
+ /// <param name="settings">The settings.</param>
+ public ShardedMongoServerProxy(MongoServerSettings settings)
+ : base(settings)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="ShardedMongoServerProxy"/> class.
/// </summary>
- /// <param name="server">The server.</param>
+ /// <param name="settings">The settings.</param>
/// <param name="instances">The instances.</param>
/// <param name="stateChangedQueue">The state changed queue.</param>
/// <param name="connectionAttempt">The connection attempt.</param>
- public ShardedMongoServerProxy(MongoServer server, IEnumerable<MongoServerInstance> instances, BlockingQueue<MongoServerInstance> stateChangedQueue, int connectionAttempt)
- : base(server, instances, stateChangedQueue, connectionAttempt)
+ public ShardedMongoServerProxy(MongoServerSettings settings, IEnumerable<MongoServerInstance> instances, BlockingQueue<MongoServerInstance> stateChangedQueue, int connectionAttempt)
+ : base(settings, instances, stateChangedQueue, connectionAttempt)
{ }
// protected methods
@@ -70,7 +70,7 @@ protected override MongoServerInstance ChooseServerInstance(ConnectedInstanceCol
}
else
{
- var secondaryAcceptableLatency = Server.Settings.SecondaryAcceptableLatency;
+ var secondaryAcceptableLatency = Settings.SecondaryAcceptableLatency;
var minPingTime = instancesWithPingTime[0].CachedAveragePingTime;
var maxPingTime = minPingTime + secondaryAcceptableLatency;
var n = instancesWithPingTime.Count(i => i.CachedAveragePingTime <= maxPingTime);
View
14 MongoDB.Driver/MongoServer.cs
@@ -69,7 +69,7 @@ public MongoServer(MongoServerSettings settings)
_sequentialId = Interlocked.Increment(ref __nextSequentialId);
// Console.WriteLine("MongoServer[{0}]: {1}", sequentialId, settings);
- _serverProxy = new MongoServerProxyFactory().Create(this);
+ _serverProxy = new MongoServerProxyFactory().Create(_settings);
}
// factory methods
@@ -937,7 +937,7 @@ public virtual IDisposable RequestStart(MongoDatabase initialDatabase, ReadPrefe
}
var serverInstance = _serverProxy.ChooseServerInstance(readPreference);
- var connection = serverInstance.AcquireConnection(initialDatabase);
+ var connection = serverInstance.AcquireConnection(initialDatabase.Name, initialDatabase.Credentials);
lock (_serverLock)
{
@@ -973,7 +973,7 @@ public virtual IDisposable RequestStart(MongoDatabase initialDatabase, MongoServ
}
}
- var connection = serverInstance.AcquireConnection(initialDatabase);
+ var connection = serverInstance.AcquireConnection(initialDatabase.Name, initialDatabase.Credentials);
lock (_serverLock)
{
@@ -1052,12 +1052,12 @@ internal MongoConnection AcquireConnection(MongoDatabase database, ReadPreferenc
// check authentication outside of lock
if (requestConnection != null)
{
- requestConnection.CheckAuthentication(database); // will throw exception if authentication fails
+ requestConnection.CheckAuthentication(database.Name, database.Credentials); // will throw exception if authentication fails
return requestConnection;
}
var serverInstance = _serverProxy.ChooseServerInstance(readPreference);
- return serverInstance.AcquireConnection(database);
+ return serverInstance.AcquireConnection(database.Name, database.Credentials);
}
internal MongoConnection AcquireConnection(MongoDatabase database, MongoServerInstance serverInstance)
@@ -1084,11 +1084,11 @@ internal MongoConnection AcquireConnection(MongoDatabase database, MongoServerIn
// check authentication outside of lock
if (requestConnection != null)
{
- requestConnection.CheckAuthentication(database); // will throw exception if authentication fails
+ requestConnection.CheckAuthentication(database.Name, database.Credentials); // will throw exception if authentication fails
return requestConnection;
}
- return serverInstance.AcquireConnection(database);
+ return serverInstance.AcquireConnection(database.Name, database.Credentials);
}
internal void ReleaseConnection(MongoConnection connection)
Please sign in to comment.
Something went wrong with that request. Please try again.