本文整理汇总了C#中MongoServerInstance类的典型用法代码示例。如果您正苦于以下问题:C# MongoServerInstance类的具体用法?C# MongoServerInstance怎么用?C# MongoServerInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoServerInstance类属于命名空间,在下文中一共展示了MongoServerInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
internal void Connect(
TimeSpan timeout
) {
server.ClearInstances();
var exceptions = new List<Exception>();
foreach (var address in server.Settings.Servers) {
try {
var serverInstance = new MongoServerInstance(server, address);
server.AddInstance(serverInstance);
try {
serverInstance.Connect(server.Settings.SlaveOk); // TODO: what about timeout?
} catch {
server.RemoveInstance(serverInstance);
throw;
}
return;
} catch (Exception ex) {
exceptions.Add(ex);
}
}
var innerException = exceptions.FirstOrDefault();
var connectionException = new MongoConnectionException("Unable to connect to server", innerException);
if (exceptions.Count > 1) {
connectionException.Data.Add("exceptions", exceptions);
}
throw connectionException;
}
示例2: DirectMongoServerProxy
/// <summary>
/// Initializes a new instance of the <see cref="DirectMongoServerProxy"/> class.
/// </summary>
/// <param name="sequentialId">The sequential id.</param>
/// <param name="serverSettings">The server settings.</param>
/// <param name="instance">The instance.</param>
/// <param name="connectionAttempt">The connection attempt.</param>
public DirectMongoServerProxy(int sequentialId, MongoServerProxySettings serverSettings, MongoServerInstance instance, int connectionAttempt)
{
_sequentialId = sequentialId;
_settings = serverSettings;
_instance = instance;
_connectionAttempt = connectionAttempt;
}
示例3: Contains
/// <summary>
/// Indicates if the instance exists in the chooser.
/// </summary>
/// <param name="instance">The instance.</param>
/// <returns>
/// <c>true</c> if [contains] [the specified instance]; otherwise, <c>false</c>.
/// </returns>
public bool Contains(MongoServerInstance instance)
{
lock (_lock)
{
return _instances.Contains(instance);
}
}
示例4: MongoConnectionPool
internal MongoConnectionPool(
MongoServerInstance serverInstance
) {
this.server = serverInstance.Server;
this.serverInstance = serverInstance;
poolSize = 0;
timer = new Timer(TimerCallback, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10));
}
示例5: MongoConnectionPool
// constructors
internal MongoConnectionPool(MongoServerInstance serverInstance)
{
_server = serverInstance.Server;
_serverInstance = serverInstance;
_poolSize = 0;
var dueTime = TimeSpan.FromSeconds(0);
var period = TimeSpan.FromSeconds(10);
_timer = new Timer(TimerCallback, null, dueTime, period);
}
示例6: GetPrimaryAndSecondaries
/// <summary>
/// Gets a list of primary and secondary instances.
/// </summary>
/// <param name="primary">The current primary.</param>
/// <returns>The list of primary and secondary instances.</returns>
public List<InstanceWithPingTime> GetPrimaryAndSecondaries(MongoServerInstance primary)
{
lock (_connectedInstancesLock)
{
// note: make copies of InstanceWithPingTime values because they can change after we return
return _instances
.Where(x => x.Instance == primary || x.Instance.IsSecondary)
.Select(x => new InstanceWithPingTime { Instance = x.Instance, CachedAveragePingTime = x.CachedAveragePingTime })
.ToList();
}
}
示例7: MongoConnectionPool
// constructors
internal MongoConnectionPool(MongoServerInstance serverInstance)
{
_settings = serverInstance.Settings;
_serverInstance = serverInstance;
_poolSize = 0;
_defaultAcquireConnectionOptions = new AcquireConnectionOptions
{
OkToAvoidWaitingByCreatingNewConnection = true,
OkToExceedMaxConnectionPoolSize = false,
OkToExceedWaitQueueSize = false,
WaitQueueTimeout = _settings.WaitQueueTimeout
};
}
示例8: Add
// public methods
/// <summary>
/// Adds the specified instance.
/// </summary>
/// <param name="instance">The instance.</param>
public void Add(MongoServerInstance instance)
{
lock (_lock)
{
var index = _instances.FindIndex(x => x.AveragePingTime >= instance.AveragePingTime);
if (index == -1)
{
_instances.Add(instance);
}
else
{
_instances.Insert(index + 1, instance);
}
instance.AveragePingTimeChanged += InstanceAveragePingTimeChanged;
}
}
示例9: IsValidInstance
/// <summary>
/// Determines whether the instance is a valid. If not, the instance is removed.
/// </summary>
/// <param name="instance">The instance.</param>
/// <returns>
/// <c>true</c> if the instance is valid; otherwise, <c>false</c>.
/// </returns>
protected abstract bool IsValidInstance(MongoServerInstance instance);
示例10: IsValidInstance
/// <summary>
/// Determines whether the instance is a valid. If not, the instance is removed.
/// </summary>
/// <param name="instance">The instance.</param>
/// <returns>
/// <c>true</c> if the instance is valid; otherwise, <c>false</c>.
/// </returns>
protected override bool IsValidInstance(MongoServerInstance instance)
{
return instance.InstanceType == MongoServerInstanceType.ShardRouter;
}
示例11: EnsureInstanceWithAddress
/// <summary>
/// Ensures that an instance with the address exists.
/// </summary>
/// <param name="address">The address.</param>
protected void EnsureInstanceWithAddress(MongoServerAddress address)
{
if (address == null)
{
throw new ArgumentNullException("address");
}
lock (_lock)
{
if (!_instances.Any(x => x.Address == address))
{
var instance = new MongoServerInstance(_server, address);
AddInstance(instance);
if (_state != MongoServerState.Disconnecting && _state != MongoServerState.Disconnected)
{
_state = MongoServerState.Connecting;
ConnectInstance(instance);
}
}
}
}
示例12: ProcessConnectedSecondaryStateChange
private void ProcessConnectedSecondaryStateChange(MongoServerInstance instance)
{
var address = instance.ReplicaSetInformation.Primary;
if (address != null)
{
// make sure the primary exists in the instance list
EnsureInstanceWithAddress(address);
}
}
示例13: ProcessInstanceStateChange
private void ProcessInstanceStateChange(MongoServerInstance instance)
{
lock (_lock)
{
if (instance.State == MongoServerState.Connected && _instances.Contains(instance))
{
if (!IsValidInstance(instance))
{
RemoveInstance(instance);
// TODO: log this...
return;
}
if (instance.IsMasterResult.MyAddress != null && instance.Address != instance.IsMasterResult.MyAddress)
{
// NOTE: if this gets set inside the MongoServerInstance, then there is a race condition that could cause
// the instance to get added more than once to the list because the changes occur under different locks.
// I don't like this and would rather it be in the MongoServerInstance, but haven't figured out how to do
// it yet.
// One solution is for every instance change to check to see if two instances exist in the list and remove
// the other one, as the current one is more up-to-date.
instance.Address = instance.IsMasterResult.MyAddress;
}
if (!_connectedInstances.Contains(instance))
{
_connectedInstances.Add(instance);
}
ProcessConnectedInstanceStateChange(instance);
}
else
{
_connectedInstances.Remove(instance);
}
SetState(DetermineServerState(_state, _instances));
}
}
示例14: ConnectInstance
private void ConnectInstance(MongoServerInstance instance)
{
Interlocked.Increment(ref _outstandingInstanceConnections);
ThreadPool.QueueUserWorkItem(_ =>
{
try
{
instance.Connect();
}
catch
{
// instance is keeping it's last ConnectionException
}
finally
{
Interlocked.Decrement(ref _outstandingInstanceConnections);
}
});
}
示例15: RemoveInstance
private void RemoveInstance(MongoServerInstance instance)
{
_connectedInstances.Remove(instance);
lock (_lock)
{
_instances.Remove(instance);
instance.StateChanged -= InstanceStateChanged;
instance.DisconnectPermanently();
ProcessInstanceStateChange(instance);
}
}