/// <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(); } } }
/// <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); }
protected virtual object CreateInstance(Service service, TTransport transport) { ThriftService thriftService = service as ThriftService; if (thriftService == null) { throw new InvalidCastException("无法转换成ThriftService"); } if (transport == null) { throw new ArgumentNullException(nameof(transport)); } if (!transport.IsOpen) { transport.Open(); } TProtocol protocol = new TBinaryProtocol(transport); TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(protocol, thriftService.Name); object instance = Activator.CreateInstance(thriftService.ServiceType, multiplexedProtocol); IDynamicProxyBuilder proxyBuilder = GlobalSetting.GetService <IDynamicProxyBuilder>(); if (proxyBuilder == null) { return(instance); } Type proxyType = proxyBuilder.CreateProxy(thriftService.ServiceInterfaceType); return(Activator.CreateInstance(proxyType, instance)); }
/// <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(); } } }
public void Connect() { Transport.Open(); TestConnection(); NodeInfo = Client.getInfo(); Console.WriteLine("Connected to {0}", NodeInfo.GetName()); }
/// <summary> /// validate the status on borrow. /// </summary> private void ValidateOnBorrow(TTransport instance) { if (!instance.IsOpen) { instance.Open(); } }
public void Open() { if (transport != null) { transport.Open(); } }
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(); } } }
/// <summary> /// 连接打开 /// </summary> /// <returns>是否开启成功</returns> public void Open() { if (!transport.IsOpen) { transport.Open(); } }
public static Cassandra.Client GetClient() { if (_client == null) { if (_transport == null) { _transport = new TFramedTransport(new TSocket("localhost", 9160)); } var client = new Cassandra.Client(new TBinaryProtocol(_transport)); if (!_transport.IsOpen) { try { _transport.Open(); } catch (Exception e) { Utility.Logging("transport open fail:" + e.Message); } } if (!_setKeySpace) { client.set_keyspace(_keySpace); _setKeySpace = true; } //return client; _client = client; } return(_client); }
private void ValidateInstance(TTransport instance) { if (!instance.IsOpen) { instance.Open(); } }
public void initData() { typeKey.Add(10, "M基站"); typeValue.Add("M基站", 10); typeKey.Add(11, "R基站"); typeValue.Add("R基站", 11); typeKey.Add(12, "C基站"); typeValue.Add("C基站", 12); try { trans = new TSocket("localhost", 9090); trans = new TFramedTransport(trans); trans.Open(); TProtocol Protocol = new TBinaryProtocol(trans, true, true); TMultiplexedProtocol multiplex; multiplex = new TMultiplexedProtocol(Protocol, "LogicFunctionService"); client = new LogicFunctionService.Client(multiplex); } catch (Exception ex) { MessageBox.Show("初始化异常:" + ex.Message); return; } loadDataToView(); }
/// <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); }
public void Init(string strIp = "localhost", int port = 9090) { this.strIp = strIp; this.nPort = port; SendLog("", "ResetLogMirror"); try { transport = new TSocket(strIp, port); TProtocol protocol = new TBinaryProtocol(transport); client = new SendLog.Client(protocol); transport.Open(); ThreadStart start = new ThreadStart(() => { while (!_isStop) { Update(); Thread.Sleep(100); } }); Thread thread = new Thread(start); thread.Start(); } catch (Exception x) { Debug.LogError("日志服务器连接失败!"); } }
public ThriftResearchAPI.Client GetThriftClientObject(TTransport Transport) { Protocol = new TBinaryProtocol(Transport); ObjClient = new ThriftResearchAPI.Client(Protocol); Transport.Open(); return(ObjClient); }
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); } }
private void initClient() { transport = new TFramedTransport(new TSocket(SERVER_IP, SERVER_PORT, TIME_OUT)); TProtocol protocol = new TBinaryProtocol(transport); client = new BigQueueService.Client(protocol); transport.Open(); }
public KvStorageEngine() { transport = new TSocket(SettingService.Local.IpAddress, SettingService.Local.Port, 30000); TProtocol protocol = new TBinaryProtocol(transport); client = new BrokerCenter.Client(protocol); transport.Open(); }
public bool Operate(int slaveid, bool open) { try { if (!transport.IsOpen) { transport.Open(); } OperateError error = client.OperateDevice(slaveid, open); return(error.Status); } catch (Exception ex) { LogHelper.Error("启停设备失败", ex); return(false); } }
public void OpenConnection() { if (!transport.IsOpen) { Console.WriteLine("Opening Connection"); transport.Open(); } Assert.True(transport.IsOpen); }
/// <summary> /// Connects to server. /// </summary> private void ConnectToServer() { // initializing socket connection to the server transport = new TSocket(SERVER_HOST, SERVER_PORT); protocol = new TBinaryProtocol(transport); client = new GameService.Client(protocol); transport.Open(); Debug.Log("CLIENT AND SERVER CONNECTED"); }
//初始化 public bool Init() { lock (this) { try { transport = new TSocket(m_host, m_port, m_timeout); protocol = new TBinaryProtocol(transport); TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "SercurityService"); SercurityClient = new SercurityService.Client(mp); TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "SaleService"); SaleClient = new SaleService.Client(mp2); TMultiplexedProtocol mp3 = new TMultiplexedProtocol(protocol, "DataSyncService"); DataSyncClient = new DataSyncService.Client(mp3); if (transport != null && !transport.IsOpen) { transport.Open(); } return(true); } catch (Exception ex) { if (transport != null) { transport.Dispose(); } if (protocol != null) { protocol.Dispose(); } if (DataSyncClient != null) { DataSyncClient.Dispose(); } if (SaleClient != null) { SaleClient.Dispose(); } if (SercurityClient != null) { SercurityClient.Dispose(); } if (SystemClient != null) { SystemClient.Dispose(); } transport = null; protocol = null; SercurityClient = null; SystemClient = null; SaleClient = null; DataSyncClient = null; _log.Error(ex.Message.ToString()); return(false); } } }
/// <summary> /// /// </summary> public void Open() { if (IsOpen) { return; } _transport.Open(); }
public void Setup() { var socket = new TSocket(host, port); transport = new TFramedTransport(socket); var protocol = new TBinaryProtocol(transport); Client = new ZipkinCollector.Client(protocol); transport.Open(); }
private TProtocol getTProtocol(string ipAddress, int port, int timeout) { TSocket socketTransport = new TSocket(ipAddress, port, timeout); mTransport = new TFramedTransport(socketTransport); TProtocol protocol = new TCompactProtocol(mTransport); mTransport.Open(); return(protocol); }
public void Open() { if (m_Transport != null && !m_Transport.IsOpen) { m_Transport.Open(); } if (m_Session == null) { m_Session = GetSession(); } }
public Client(string host, int port) { TSocket socket = null; socket = new TSocket(host, port); transport = new TFramedTransport(socket); TProtocol protocol = new TBinaryProtocol(transport); client = new CassandraClient(protocol); transport.Open(); }
/// <summary> /// Establishes and opens a physical connection with the service. /// </summary> /// <returns>Client service objects to invoke RPC calls to the client.</returns> public Services Connect() { try { _transport.Open(); return(new Services(_transport)); } catch (Exception ex) { throw ex; } }
public void Connect(string ip, int port) { if (this.transport != null && this.transport.IsOpen) { this.transport.Close(); } this.transport = new TSocket(ip, port); this.protocol = new TBinaryProtocol(transport); this.client = new Thrift.TheGraph.Client(this.protocol); transport.Open(); }
private void InitClient(RpcAgentConfiguration config) { TTransport transport = config.GetThriftTransport(); transport.Open(); TProtocol protocol = config.GetThriftProtcol(transport); ThriftWPWithinService.Client client = new ThriftWPWithinService.Client(protocol); _transport = transport; _client = client; Log.InfoFormat("Client connected to Thrift RPC Agent endpoint at {0}:{1} using {2}", config.ServiceHost, config.ServicePort, config.Protocol); }