当前位置: 首页>>代码示例>>C#>>正文


C# MongoServerInstance类代码示例

本文整理汇总了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;
        }
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:30,代码来源:DirectConnector.cs

示例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;
 }
开发者ID:wireclub,项目名称:mongo-csharp-driver,代码行数:14,代码来源:DirectMongoServerProxy.cs

示例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);
     }
 }
开发者ID:kayone,项目名称:mongo-csharp-driver,代码行数:14,代码来源:ConnectedInstanceCollection.cs

示例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));
        }
开发者ID:simi--,项目名称:mongo-csharp-driver,代码行数:9,代码来源:MongoConnectionPool.cs

示例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);
        }
开发者ID:moonreplace,项目名称:mongo-csharp-driver,代码行数:11,代码来源:MongoConnectionPool.cs

示例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();
     }
 }
开发者ID:hriazi,项目名称:mongo-csharp-driver,代码行数:16,代码来源:ConnectedInstanceCollection.cs

示例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
            };
        }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:15,代码来源:MongoConnectionPool.cs

示例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;
     }
 }
开发者ID:kayone,项目名称:mongo-csharp-driver,代码行数:21,代码来源:ConnectedInstanceCollection.cs

示例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);
开发者ID:nickgervasi,项目名称:mongo-csharp-driver,代码行数:8,代码来源:MultipleInstanceMongoServerProxy.cs

示例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;
 }
开发者ID:wireclub,项目名称:mongo-csharp-driver,代码行数:11,代码来源:ShardedMongoServerProxy.cs

示例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);
                    }
                }
            }
        }
开发者ID:nickgervasi,项目名称:mongo-csharp-driver,代码行数:25,代码来源:MultipleInstanceMongoServerProxy.cs

示例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);
     }
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:9,代码来源:ReplicaSetMongoServerProxy.cs

示例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));
            }
        }
开发者ID:kayone,项目名称:mongo-csharp-driver,代码行数:39,代码来源:MultipleConnectionMongoServerProxy.cs

示例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);
         }
     });
 }
开发者ID:nickgervasi,项目名称:mongo-csharp-driver,代码行数:19,代码来源:MultipleInstanceMongoServerProxy.cs

示例15: RemoveInstance

 private void RemoveInstance(MongoServerInstance instance)
 {
     _connectedInstances.Remove(instance);
     lock (_lock)
     {
         _instances.Remove(instance);
         instance.StateChanged -= InstanceStateChanged;
         instance.DisconnectPermanently();
         ProcessInstanceStateChange(instance);
     }
 }
开发者ID:nickgervasi,项目名称:mongo-csharp-driver,代码行数:11,代码来源:MultipleInstanceMongoServerProxy.cs


注:本文中的MongoServerInstance类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。