• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MongoServerInstance类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MongoServerInstance的典型用法代码示例。如果您正苦于以下问题:C# MongoServerInstance类的具体用法?C# MongoServerInstance怎么用?C# MongoServerInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MongoServerInstance类属于命名空间,在下文中一共展示了MongoServerInstance类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: ProcessConnectedInstanceStateChange

 /// <summary>
 /// Processes the connected instance state change.
 /// </summary>
 /// <param name="instance">The instance.</param>
 protected override void ProcessConnectedInstanceStateChange(MongoServerInstance instance)
 {
     if (instance.IsPrimary)
     {
         ProcessConnectedPrimaryStateChange(instance);
     }
     else
     {
         ProcessConnectedSecondaryStateChange(instance);
     }
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:15,代码来源:ReplicaSetMongoServerProxy.cs


示例17: QueueConnect

 private void QueueConnect(MongoServerInstance serverInstance)
 {
     var args = new ConnectArgs
     {
         ServerInstance = serverInstance,
         ResponseQueue = _responseQueue
     };
     ThreadPool.QueueUserWorkItem(ConnectWorkItem, args);
     _connects.Add(args);
 }
开发者ID:purplecow,项目名称:mongo-csharp-driver,代码行数:10,代码来源:ReplicaSetConnector.cs


示例18: DirectMongoServerProxy

 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="DirectMongoServerProxy"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public DirectMongoServerProxy(MongoServerSettings settings)
 {
     _settings = settings;
     _instance = new MongoServerInstance(settings, settings.Servers.First());
 }
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:10,代码来源:DirectMongoServerProxy.cs


示例19: CreateActualProxy

        private void CreateActualProxy(MongoServerInstance instance, BlockingQueue<MongoServerInstance> connectionQueue)
        {
            lock (_lock)
            {
                if (instance.InstanceType == MongoServerInstanceType.ReplicaSetMember)
                {
                    _serverProxy = new ReplicaSetMongoServerProxy(_settings, _instances, connectionQueue, _connectionAttempt);
                }
                else if (instance.InstanceType == MongoServerInstanceType.ShardRouter)
                {
                    _serverProxy = new ShardedMongoServerProxy(_settings, _instances, connectionQueue, _connectionAttempt);
                }
                else if (instance.InstanceType == MongoServerInstanceType.StandAlone)
                {
                    var otherInstances = _instances.Where(x => x != instance).ToList();
                    foreach (var otherInstance in otherInstances)
                    {
                        otherInstance.Disconnect();
                    }

                    _serverProxy = new DirectMongoServerProxy(_settings, instance, _connectionAttempt);
                }
                else
                {
                    throw new MongoConnectionException("The type of servers in the host list could not be determined.");
                }
            }
        }
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:28,代码来源:DiscoveringMongoServerProxy.cs


示例20: ProcessInstanceStateChange

        private void ProcessInstanceStateChange(MongoServerInstance instance)
        {
            List<MongoServerInstance> currentInstances;
            MongoServerState currentState;

            lock (_lock)
            {
                currentInstances = _instances;
                currentState = _state;
            }

            if (currentInstances.Contains(instance))
            {
                if (instance.State == MongoServerState.Connected)
                {
                    if (!IsValidInstance(instance))
                    {
                        RemoveInstance(instance);
                        return;
                    }

                    if (currentState != MongoServerState.Disconnecting && currentState != MongoServerState.Disconnected)
                    {
                        _connectedInstances.EnsureContains(instance);
                        ProcessConnectedInstanceStateChange(instance);
                    }
                }
                else
                {
                    _connectedInstances.Remove(instance);
                }
            }

            SetState(DetermineServerState(currentState, currentInstances));
        }
开发者ID:titolarz,项目名称:mongo-csharp-driver,代码行数:35,代码来源:MultipleConnectionMongoServerProxy.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MongoServerState类代码示例发布时间:2022-05-24
下一篇:
C# MongoServerAddress类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap