示例#1
0
        /// <summary>
        /// The get words.
        /// </summary>
        /// <param name="prefix">
        /// The prefix.
        /// </param>
        /// <returns>
        /// The words.
        /// </returns>
        public IList <string> Get(string prefix)
        {
            Exception maxRetriesException = null;

            for (var i = 0; i < MaxRetries; i++)
            {
                try
                {
                    if (this.client == null)
                    {
                        this.TryReConnect();
                    }

                    return(this.client.Get(prefix));
                }
                catch (SocketException ex)
                {
                    maxRetriesException = ex;

                    if (this.client != null)
                    {
                        this.client.Dispose();
                    }

                    this.client = null;
                }
            }

            if (maxRetriesException != null)
            {
                throw new Exception(string.Format("Thrift call failed after {0} retries", MaxRetries), maxRetriesException);
            }

            throw new Exception(string.Format("Thrift call failed after {0} retries", MaxRetries));
        }
示例#2
0
        /// <summary>
        /// Reconnect to server.
        /// </summary>
        private void TryReConnect()
        {
            TTransport transport = new TSocket(_host, _port);

            transport.Open();

            var proto = new TBinaryProtocol(transport);

            this.client = new AutoCompleteService.Client(proto);
        }