/// <summary>
 /// 读取单行
 /// </summary>
 public static void getattachmentSingle()
 {
     //     TTransport transport = null;
     try
     {
         tablename = table2name;
         //打开连接
         transport.Open();
         string rowkey = "k1";
         //根据表名,RowKey名来获取结果集
         List <TRowResult> reslut = client.getRow(Encoding.UTF8.GetBytes(tablename), Encoding.UTF8.GetBytes(rowkey), null);
         //遍历结果集
         foreach (var key in reslut)
         {
             Console.WriteLine("RowKey:\n{0}", Encoding.UTF8.GetString(key.Row));
             //打印Qualifier和对应的Value
             foreach (var k in key.Columns)
             {
                 Console.WriteLine("******************" + "\n" + Encoding.UTF8.GetString(k.Key));
                 Console.WriteLine("Value:" + Encoding.UTF8.GetString(k.Value.Value));
             }
         }
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e);
     }
     finally
     {
         if (null != transport)
         {
             transport.Close();
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// 读取Hbase数据
        /// </summary>
        /// <param name="tempList"></param>
        /// <param name="IPAddress"></param>
        /// <param name="Port"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static Dictionary <string, string> ReadKeyHbaseData(List <string> tempList, string IPAddress, int Port,
                                                                   string strTableName)
        {
            Dictionary <string, string> dis = new Dictionary <string, string>();

            try
            {
                int count = 0;
                if (transport == null)
                {
                    transport = new TSocket(IPAddress, Port);
                }

                //实例化一个协议对象
                TProtocol tProtocol = new TBinaryProtocol(transport);
                //实例化一个Hbase的Client对象
                var client = new Hbase.Client(tProtocol);
                //打开连接
                transport.Open();
                foreach (var temp in tempList)
                {
                    //根据表名,RowKey名来获取结果集
                    var reslut = client.getRow(Encoding.UTF8.GetBytes(strTableName),
                                               Encoding.UTF8.GetBytes(temp), null);
                    foreach (var keys in reslut)
                    {
                        foreach (var k in keys.Columns)
                        {
                            if (dis.ContainsKey(Encoding.UTF8.GetString(keys.Row)))
                            {
                                continue;
                            }
                            dis.Add(Encoding.UTF8.GetString(keys.Row), Encoding.UTF8.GetString(k.Value.Value));
                            ++count;
                            //LoggerManager.Create().InfoWrite(string.Format("已下载{0}条记录", ++count));
                            if (count % 1000 != 0)
                            {
                                continue;
                            }
                            LoggerManager.Create().InfoWrite(string.Format("已下载指定RowKey{0}条", count));
                        }
                    }
                }
                LoggerManager.Create().InfoWrite(string.Format("Hbases下载指定数据成功,共下载数据{0}条", count));
            }
            catch (Exception ex)
            {
                LoggerManager.Create().ErrorWrite(string.Format("Hbase读取指定数据失败,错误信息:{0}", ex.Message));
            }
            finally
            {
                if (transport != null)
                {
                    transport.Close();
                }
            }
            return(dis);
        }
Exemple #3
0
 public static void Close()
 {
     if (transport.IsOpen)
     {
         transport.Close();
     }
 }
Exemple #4
0
    public static void Main(string[] args)
    {
        int port = 9090;

        for (int i = 0; i < args.Length; i++)
        {
            switch (args[i])
            {
            case "--port":
                port = int.Parse(args[++i]);
                break;

            case "--help":
                Console.WriteLine("--port: Port used to connect with the server. (int)");
                break;
            }
        }

        try
        {
            TSocket tSocket = new TSocket("localhost", port);
            tSocket.TcpClient.NoDelay = true;
            TTransport  transport = tSocket;
            TProtocol   protocol  = new TBinaryProtocol(transport);
            Game.Client client    = new Game.Client(protocol);
            transport.Open();
            playGame(client);
            transport.Close();
        }
        catch (TApplicationException x)
        {
            Console.WriteLine(x.StackTrace);
        }
    }
Exemple #5
0
 /// <summary>
 /// 关闭连接,请慎用,这个主要是提供给连接池管理用来释放连接的
 /// 业务千万不能用这个
 /// </summary>
 public void Close()
 {
     isConnected = false;
     try
     {
         if (transport != null)
         {
             if (transport.IsOpen)
             {
                 transport.Close();
             }
             transport.Dispose();
             logger.LogDebug($"关闭链接:{transport.GetHashCode()},{clientItem.Ip}:{clientItem.Port}");
             transport = null;
         }
         if (client != null)
         {
             client.Dispose();
             client = null;
         }
     }
     catch (Exception ex)
     {
         logger.LogError(ex, "GrantMicroService.GrantRpc.Thrift.Client.Dispose.Error");
     }
 }
 /// <summary>
 /// 调用函数
 /// </summary>
 /// <param name="FuncName">函数名</param>
 /// <param name="paramArr">参数列表</param>
 /// <returns></returns>
 public Result CallFunc(string FuncName, params string[] paramArr)
 {
     try
     {
         if (OpenNum == 0)
         {
             transport.Open();
         }
         OpenNum++;
         string Params = paramArr == null || paramArr.Length == 0 ? null : string.Join(Delimiter, paramArr);
         string result = client.CallFunc(FuncName, Params, Delimiter);
         return(Result.Parse(result));
     }
     catch (Exception ex)
     {
         Logger.log("ThriftClient.CallFunc", ex);
         return(new Result(ResultCode.Defeat, ex.Message));
     }
     finally {
         OpenNum--;
         if (OpenNum == 0)
         {
             transport.Close();
         }
     }
 }
Exemple #7
0
 /// <summary>
 /// 关闭连接,请慎用,这个主要是提供给连接池管理用来释放连接的
 /// 业务千万不能用这个
 /// </summary>
 public void Close()
 {
     isConnected = false;
     try
     {
         if (transport != null)
         {
             if (transport.IsOpen)
             {
                 transport.Close();
             }
             transport.Dispose();
             transport = null;
         }
         if (client != null)
         {
             client.Dispose();
             client = null;
         }
     }
     catch (Exception ex)
     {
         logger.LogError(ex, "SuperGMS.GrantRpc.Thrift.Client.Dispose.Error");
     }
 }
        /**
         * 点击事件
         **/
        public static void InputEvent(Int32 port, MouseEventType type)
        {
            TSocket socket = new TSocket("127.0.0.1", port, 1000);

            TFramedTransport.Factory factory = new
                                               TFramedTransport.Factory();
            TTransport transport = factory.GetTransport(socket);

            TBinaryProtocol.Factory factory1 =
                new TBinaryProtocol.Factory();
            TProtocol            protocol = factory1.GetProtocol(transport);
            TMultiplexedProtocol impl1
                = new TMultiplexedProtocol(protocol, "ScreenService");

            ScreenService.Client client =
                new ScreenService.Client(impl1);
            try
            {
                socket.Open();
                bool r
                    = client.InputEvent(type);
            }
            catch (Exception x)
            {
                Console.WriteLine(x.StackTrace);
            }
            finally
            {
                transport.Close();
            }
        }
 /// <summary>
 /// validate the status on return.
 /// </summary>
 private void ValidateOnReturn(TTransport instance)
 {
     if (instance.IsOpen)
     {
         instance.Close();
     }
 }
Exemple #10
0
 private void closeClient()
 {
     if (transport != null)
     {
         transport.Close();
     }
 }
Exemple #11
0
        public string TestConnection(string IPAddress, int Port)
        {
            TTransport transport = null;

            try
            {
                //192.168.2.111:60010
                //实例化Socket连接
                transport = new TSocket(IPAddress, Port);
                //实例化一个协议对象
                TProtocol tProtocol = new TBinaryProtocol(transport);
                //实例化一个Hbase的Client对象
                var client = new Hbase.Client(tProtocol);
                //打开连接
                transport.Open();

                return("联接成功..");
            }
            catch (Exception ex)
            {
                return("联接失败.." + ":" + ex.ToString());
            }

            finally
            {
                if (transport != null)
                {
                    transport.Close();
                }
            }
        }
Exemple #12
0
 protected override void OnClosing(CancelEventArgs e)
 {
     if (trans != null)
     {
         trans.Close();
     }
 }
        private void Execute(object threadContext)
        {
            TTransport tTransport = (TTransport)threadContext;
            TTransport transport  = null;
            TTransport transport1 = null;
            TProtocol  protocol   = null;
            TProtocol  tProtocol  = null;

            try
            {
                transport  = this.inputTransportFactory.GetTransport(tTransport);
                transport1 = this.outputTransportFactory.GetTransport(tTransport);
                protocol   = this.inputProtocolFactory.GetProtocol(transport);
                tProtocol  = this.outputProtocolFactory.GetProtocol(transport1);
                while (this.processor.Process(protocol, tProtocol))
                {
                }
            }
            catch (TTransportException tTransportException)
            {
            }
            catch (Exception exception)
            {
                this.logDelegate(string.Concat("Error: ", exception));
            }
            if (transport != null)
            {
                transport.Close();
            }
            if (transport1 != null)
            {
                transport1.Close();
            }
        }
Exemple #14
0
 /// <summary>
 /// Close th econnection to the server
 /// </summary>
 /// <param name="client"></param>
 public void Disconnect(AsapiServer.Client client)
 {
     try {
         transport.Close();
     }
     catch (TApplicationException x) { }
 }
 public void Close()
 {
     if (transport != null)
     {
         transport.Close();
     }
 }
        /// <summary>
        /// user singin
        /// 为什么采用整形返回设计:1、必须有回执 2、便于处理异常并准确提示错误
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <returns></returns>
        public static int Singin(ref string ip, ref string port)
        {
            int res   = 505;
            int _port = Convert.ToInt32(port);

            BusinessServer.Client bServerClient = null;
            TTransport            transport     = SocketOpter.Init(ip, _port, 800, ref bServerClient);

            if (!transport.IsOpen)
            {
                try
                {
                    transport.Open();
                    if (transport.IsOpen)
                    {
                        GlobalCache.Host = ip;
                        GlobalCache.Port = _port;
                        res = 200;
                    }
                }
                catch (System.Exception ex)
                {
                    Logger <ThriftServiceBasic> .Log.Error("Singin", ex);

                    res = 404;
                }
                finally
                {
                    transport.Close();
                }
            }
            return(res);
        }
Exemple #17
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_isDisposed)
            {
                if (disposing)
                {
                    GC.SuppressFinalize(this);
                }
            }
            try
            {
                _transport.Close();
            }
            catch (Exception e)
            {
                Log.Warn("Error closing connection to RPC Agent", e);
            }

            if (_listener != null)
            {
                try
                {
                    _listener.Stop();
                }
                catch (Exception e)
                {
                    Log.Warn("Error stopping callback listener", e);
                }
            }
            //Dispose of resources here
            _isDisposed = true;
        }
        /**
         * 获取手机屏幕分辨率
         **/
        public static String sendPoint(Int32 port, Int32 x, Int32 y)
        {
            TSocket socket = new TSocket("127.0.0.1", port, 1000);

            TFramedTransport.Factory factory = new
                                               TFramedTransport.Factory();
            TTransport transport = factory.GetTransport(socket);

            TBinaryProtocol.Factory factory1 =
                new TBinaryProtocol.Factory();
            TProtocol            protocol = factory1.GetProtocol(transport);
            TMultiplexedProtocol impl1
                = new TMultiplexedProtocol(protocol, "ScreenService");

            ScreenService.Client client =
                new ScreenService.Client(impl1);
            try
            {
                socket.Open();
                return(client.sendPoint(x, y));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                transport.Close();
            }
            return("");
        }
        public static string RemoveProcess(Int32 port, String lineNumber)
        {
            TSocket socket = new TSocket("127.0.0.1", port, 3000);

            TFramedTransport.Factory factory = new
                                               TFramedTransport.Factory();
            TTransport transport = factory.GetTransport(socket);

            TBinaryProtocol.Factory factory1 =
                new TBinaryProtocol.Factory();
            TProtocol            protocol = factory1.GetProtocol(transport);
            TMultiplexedProtocol impl1
                = new TMultiplexedProtocol(protocol, "NodeService");

            NodeService.Client client =
                new NodeService.Client(impl1);
            try
            {
                socket.Open();
                return(client.RemoveProcess(lineNumber));
            }
            catch (Exception x)
            {
                Console.WriteLine(x.StackTrace);
            }
            finally
            {
                transport.Close();
            }
            return("");
        }
Exemple #20
0
 void OnDestroy()
 {
     if (mInstance == this)
     {
         mInstance = null;
     }
     transport.Close();
 }
Exemple #21
0
            public void Execute()
            {
                var token = CancellationToken.None;

                if (done)
                {
                    Console.WriteLine("Execute called more than once");
                    throw new InvalidOperationException();
                }

                for (var i = 0; i < numIterations; i++)
                {
                    try
                    {
                        if (!transport.IsOpen)
                        {
                            transport.OpenAsync(token).GetAwaiter().GetResult();
                        }
                    }
                    catch (TTransportException ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine("Connect failed: " + ex.Message);
                        ReturnCode |= ErrorUnknown;
                        Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
                        continue;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine("Connect failed: " + ex.Message);
                        ReturnCode |= ErrorUnknown;
                        Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
                        continue;
                    }

                    try
                    {
                        ReturnCode |= ExecuteClientTestAsync(client).GetAwaiter().GetResult();;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
                        ReturnCode |= ErrorUnknown;
                    }
                }
                try
                {
                    transport.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error while closing transport");
                    Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
                }
                done = true;
            }
Exemple #22
0
 public byte[] getSession(int timeout, string sessionKey)
 {
     byte[] result = null;
     try
     {
         SessionDao.Client client = getSessionDaoStub(timeout);
         result = client.getSession(getPlatformArgs(), sessionKey);
     }
     catch (Exception e)
     {
         throw e;
     }
     finally
     {
         mTransport.Close();
     }
     return(result);
 }
Exemple #23
0
 public bool Close()
 {
     if (_transport.IsOpen)
     {
         _transport.Close();
     }
     _isConnected = false;
     return(true);
 }
Exemple #24
0
 public void CloseConnection()
 {
     if (transport.IsOpen)
     {
         Console.WriteLine("Closing Connection");
         transport.Close();
     }
     Assert.False(transport.IsOpen);
 }
Exemple #25
0
        /// <summary>
        ///
        /// </summary>
        public void Close()
        {
            if (!IsOpen)
            {
                return;
            }

            _transport.Close();
        }
Exemple #26
0
 public void Intercept(IInvocation invocation)
 {
     invocation.Proceed();
     if (invocation.Method.Name.IndexOf("TestSendHttpSearch") >= 0)
     {
         TTransport transport = invocation.Arguments[0] as TTransport;
         transport.Close();
     }
 }
 /// <summary>
 /// destory the instance.
 /// </summary>
 /// <param name="instance"></param>
 private void DestoryInstance(TTransport instance)
 {
     instance.Flush();
     if (instance.IsOpen)
     {
         instance.Close();
     }
     instance.Dispose();
 }
Exemple #28
0
            public async Task Execute()
            {
                if (done)
                {
                    Console.WriteLine("Execute called more than once");
                    throw new InvalidOperationException();
                }

                for (var i = 0; i < numIterations; i++)
                {
                    try
                    {
                        if (!transport.IsOpen)
                        {
                            await transport.OpenAsync(MakeTimeoutToken());
                        }
                    }
                    catch (TTransportException ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine("Connect failed: " + ex.Message);
                        ReturnCode |= ErrorUnknown;
                        Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                        continue;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine("Connect failed: " + ex.Message);
                        ReturnCode |= ErrorUnknown;
                        Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                        continue;
                    }

                    try
                    {
                        ReturnCode |= await ExecuteClientTest(client);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                        ReturnCode |= ErrorUnknown;
                    }
                }
                try
                {
                    transport.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error while closing transport");
                    Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                }
                done = true;
            }
Exemple #29
0
        public static void ClientThread(object obj)
        {
            TTransport transport = (TTransport)obj;

            for (int i = 0; i < numIterations; i++)
            {
                ClientTest(transport);
            }
            transport.Close();
        }
Exemple #30
0
        public string getToken(int timeout, string key)
        {
            string result = String.Empty;

            try
            {
                TokenAo.Client client = getTokenAoStub(timeout);
                result = client.getToken(getPlatformArgs(), key);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                mTransport.Close();
            }
            return(result);
        }