示例#1
0
        public ThriftConnection(IConnectionSettings2 connectionSettings)
        {
            this._connectionSettings = connectionSettings;
            this._timeout = connectionSettings.Timeout;
            this._poolSize = Math.Max(1, connectionSettings.MaximumAsyncConnections);

            this._resourceLock = new Semaphore(_poolSize, _poolSize);

            for (var i = 0; i <= connectionSettings.MaximumAsyncConnections; i++)
            {
                var tsocket = new TSocket(connectionSettings.Host, connectionSettings.Port);
                var transport = new TBufferedTransport(tsocket, 1024);
                var protocol = new TBinaryProtocol(transport);
                var client = new Rest.Client(protocol);
                _clients.Enqueue(client);
            }
        }
        public ThriftConnection(IConnectionConfigurationValues connectionSettings)
        {
            this._connectionSettings = connectionSettings;
            this._timeout = connectionSettings.Timeout;
            this._poolSize = Math.Max(1, connectionSettings.MaximumAsyncConnections);

            this._resourceLock = new Semaphore(_poolSize, _poolSize);
            int seed; bool shouldPingHint;
            for (var i = 0; i <= connectionSettings.MaximumAsyncConnections; i++)
            {
                var uri = this._connectionSettings.ConnectionPool.GetNext(null, out seed, out shouldPingHint);
                var host = uri.Host;
                var port = uri.Port;
                var tsocket = new TSocket(host, port);
                var transport = new TBufferedTransport(tsocket, 1024);
                var protocol = new TBinaryProtocol(transport);
                var client = new Rest.Client(protocol);
                _clients.Enqueue(client);
            }
        }
		public ThriftConnection(IConnectionConfigurationValues connectionSettings)
		{
			this._connectionSettings = connectionSettings;
			this._timeout = connectionSettings.Timeout;
			var connectionPool = this._connectionSettings.ConnectionPool;
			var maximumConnections = Math.Max(1, connectionSettings.MaximumAsyncConnections);
			var maximumUrls = connectionPool.MaxRetries + 1;
			this._poolSize = maximumConnections;
			this._resourceLock = new Semaphore(_poolSize, _poolSize);

			int seed; int initialSeed = 0; bool shouldPingHint;

			for (var i = 0; i < maximumUrls; i++)
			{
				var uri = connectionPool.GetNext(initialSeed, out seed, out shouldPingHint);
				var queue = new ConcurrentQueue<Rest.Client>();
				for (var c = 0; c < maximumConnections; c++)
				{
					var host = uri.Host;
					var port = uri.Port;
					var tsocket = new TSocket(host, port);
					var transport = new TBufferedTransport(tsocket, 1024);
					var protocol = new TBinaryProtocol(transport);
					var client = new Rest.Client(protocol);
					tsocket.Timeout = this._connectionSettings.Timeout;
					tsocket.TcpClient.SendTimeout = this._connectionSettings.Timeout;
					tsocket.TcpClient.ReceiveTimeout = this._connectionSettings.Timeout;
					//tsocket.TcpClient.NoDelay = true;

					queue.Enqueue(client);

					initialSeed = seed;
				}
				_clients.TryAdd(uri, queue);
			}
		}