コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThriftSConnection"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        public ThriftSConnection(ConnectionSettingInfo connection)
        {
            this.IsErrorOccurred   = false;
            this.LastActiveTime    = DateTime.UtcNow;
            this.ConnectionSetting = connection;

            this.Initialize();
        }
コード例 #2
0
ファイル: ConnectionPool.cs プロジェクト: zhuhongcai/ThriftS
        /// <summary>
        /// Initializes a new instance of the <see cref="ConnectionPool"/> class.
        /// </summary>
        /// <param name="connectionSetting">The server.</param>
        public ConnectionPool(ConnectionSettingInfo connectionSetting)
        {
            this.ConnectionSetting = connectionSetting;

            // 有的服务可能只是初始化用一次。
            // this.MinPoolSize = 0;

            // 每个连接字符串最多128个连接,注意Timeout值不同认为是不同的连接
            this.MaxPoolSize = 128;

            // 连接保持3分钟
            this.KeepaliveTime = TimeSpan.FromSeconds(180);

            // 每30秒清理一次连接
            this.maintenanceTimer = new Timer(o => this.Cleanup(), null, 30000L, 30000L);
        }
コード例 #3
0
        /// <summary>
        /// Gets the pool.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="port">The port.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>ConnectionPool.</returns>
        public static ConnectionPool GetPool(string host, int port, int timeout)
        {
            var connection = new ConnectionSettingInfo(host, port, timeout);

            if (Pools.ContainsKey(connection) == false)
            {
                lock (Pools)
                {
                    if (Pools.ContainsKey(connection) == false)
                    {
                        Pools.Add(connection, new ConnectionPool(connection));
                    }
                }
            }

            return(Pools[connection]);
        }