Borrowed much of the layout from NoRM, I just couldn't resist it was very elegant in its design.
Inheritance: IConnection, IDisposable
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override IConnection CreateConnection()
        {
            if (!Servers.HasNext)
                return null;

            var server = Servers.Next();
            var conn = new Connection(server);

            return conn;
        }
Exemplo n.º 2
0
		private void ServerRecover(object unused)
		{
			lock(_lock)
			{
				if(!_failed)
					return;

				var connection = new Connection(_server, ConnectionType.Simple, 1024);

				try
				{
					connection.Open();
					_failed = false;
				}
				catch { }
				finally
				{
					connection.Close();
				}
			}
		}
		private void ServerRecover()
		{
			try
			{
				if (_blackListed.Count > 0)
				{
					var clonedBlackList = (HashSet<Server>)null;

					lock (_lock)
						clonedBlackList = new HashSet<Server>(_blackListed);

					foreach (var server in clonedBlackList)
					{
						var connection = new Connection(server, ConnectionType.Simple, 1024);

						try
						{
							connection.Open();
							lock(_lock)
							{
							   _blackListed.Remove(server);
							   _serverQueue.Enqueue(server);
							}
						}
						catch { }
						finally
						{
							connection.Close();
						}
					}
					clonedBlackList.Clear();
				}
			}
			finally
			{
				_recoveryTimer.Change(_recoveryTimerInterval, Timeout.Infinite);
			}
		}