Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
		/// <summary>
		/// 
		/// </summary>
		private void InitTransportAndClient()
		{
			var socket = new TSocket(Server.Host, Server.Port, Server.Timeout * 1000);

			switch (ConnectionType)
			{
				case ConnectionType.Simple:
					_transport = socket;
					break;

				case ConnectionType.Buffered:
					_transport = new TBufferedTransport(socket, BufferSize);
					break;

				case ConnectionType.Framed:
					_transport = new TFramedTransport(socket);
					break;

				default:
					goto case ConnectionType.Framed;
			}

			var protocol = new TBinaryProtocol(_transport);
			_client = new Cassandra.Client(protocol);
		}
 public TFramedTransport(TTransport transport)
 {
     if (transport == null)
         throw new ArgumentNullException("transport");
     this.transport = transport;
     InitWriteBuffer();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        internal Connection(Server server, ConnectionBuilder builder)
        {
            Created = DateTime.Now;
            Server = server;

            var socket = new TSocket(server.Host, server.Port, server.Timeout * 1000);

            switch(builder.ConnectionType)
            {
                case ConnectionType.Simple:
                    _transport = socket;
                    break;

                case ConnectionType.Buffered:
                    _transport = new TBufferedTransport(socket, builder.BufferSize);
                    break;

                case ConnectionType.Framed:
                    _transport = new TFramedTransport(socket);
                    break;
            }

            _protocol = new TBinaryProtocol(_transport);
            _client = new Cassandra.Client(_protocol);
        }
Ejemplo n.º 5
0
 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();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// DNHClientComponent
        /// </summary>
        public DNHClientComponent()
        {
            InitializeComponent();

            transport = new TSocket(hostName, port);
            protocol = new TBinaryProtocol(transport);
            client = new DNHService.Client(protocol);
        }
Ejemplo n.º 7
0
 public EpmService()
 {
     disposed = false;
     pool = new ConnectionProvider();
     transport = pool.GetConnection();
     TProtocol protocol = new TBinaryProtocol(transport);
     client = new Datahouse.Client(protocol);
 }
 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();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 public ThriftConnection(IConnectionSettings connectionSettings)
 {
     Created = DateTime.Now;
     var tsocket = new TSocket(connectionSettings.Host, connectionSettings.Port);
     _transport = new TBufferedTransport(tsocket, 1024);
     _protocol = new TBinaryProtocol(_transport);
     _client = new Rest.Client(_protocol);
 }
 public TBufferedTransport(TTransport transport, int bufSize = 1024)
 {
     if (transport == null)
         throw new ArgumentNullException("transport");
     if (bufSize <= 0)
         throw new ArgumentException("bufSize", "Buffer size must be a positive number.");
     this.transport = transport;
     this.bufSize = bufSize;
 }
Ejemplo n.º 11
0
 public static Cassandra.Client GetClient(string keyspace, ref TTransport transport)
 {
     TTransport frameTransport = new TFramedTransport(new TSocket("localhost", 9160));
     TProtocol frameProtocol = new TBinaryProtocol(frameTransport);
     var client = new Cassandra.Client(frameProtocol, frameProtocol);
     frameTransport.Open();
     client.set_keyspace(keyspace);
     transport = frameTransport;
     return client;
 }
Ejemplo n.º 12
0
        public HClient()
        {
            socket = new TSocket(host, port);
            this.Transport = new TBufferedTransport(socket);
            //Transport.Open();
            this.protocol = new TBinaryProtocol(Transport);
            this.Client = new Apache.Hadoop.Hbase.Hbase.Client(protocol);

            this.IsFree = true;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        internal Connection(Server server)
        {
            Created = DateTime.Now;
            Server = server;

            TTransport socket = new TSocket(server.Host, server.Port, server.Timeout);

            _transport = new TFramedTransport(socket);
            _protocol = new TBinaryProtocol(_transport);
            _client = new Cassandra.Client(_protocol);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// return an instance.
        /// </summary>
        /// <param name="instance"></param>
        public void ReturnInstance(TTransport instance)
        {
            if (objectPool.Count >= config.MaxIdle)
                DestoryInstance(instance);
            else
            {
                if (config.ValidateOnReturn)
                    ValidateOnReturn(instance);

                PushObject(instance);
                activedCount--;
                resetEvent.Set();
            }
        }
Ejemplo n.º 15
0
 public void ReturnConnection(TTransport transport)
 {
     lock (locker) {
         if (idelCount == Conf.TMaxIdel)
             DestoryInstance(transport);
         else
         {
             if (Conf.TValidateOnReturn)
                 ValidateInstance(transport);
             PushToPool(transport);
             resetEvent.Set();
         }
     }
 }
Ejemplo n.º 16
0
 public Services(TTransport transport)
 {
     SessionService = new SessionService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => SessionService)));
     UserService = new UserService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => UserService)));
     SettingService = new SettingService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => SettingService)));
     ChatService = new ChatService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => ChatService)));
     ChatUserInfoService = new ChatUserInfoService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => ChatUserInfoService)));
     ChatGroupService = new ChatGroupService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => ChatGroupService)));
     InboxService = new InboxService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => InboxService)));
     InboxRuleService = new InboxRuleService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => InboxRuleService)));
     ElifService = new ElifService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => ElifService)));
     SearchService = new SearchService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => SearchService)));
     NotificationService = new NotificationService.Client(new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), Utility.Helper.NameOf(() => NotificationService)));
 }
Ejemplo n.º 17
0
 public Servicer()
 {
     try
     {
         disposed = false;
         pool = new ConnectionProvider();
         transport = pool.GetConnection();
         TProtocol protocol = new TBinaryProtocol(transport);
         client = new Datahouse.Client(protocol);
     }
     catch (Exception e)
     {
         LogUtil.Logger.Error(e.Message);
     }
 }
Ejemplo n.º 18
0
        public MainController(MainWindow window)
        {
            this.window = window;
            this.nao = new NaoController(NAO_IP, this);

            this.thriftTransport = new TSocket(SERVER_IP, 9090);
            thriftTransport.Open();
            TProtocol protocol = new TBinaryProtocol(thriftTransport);
            this.thriftClient = new Rpc.Client(protocol);

            this.lib = new ObjectLibrary(this, this.thriftClient, MainController.OBJECT_LIB_PATH);
            this.updateThread = new Thread(this.lib.updatePointClouds);
            this.updateThread.Start();

            this.nav = new NavigationController(this, nao, lib);
            this.navThread = null;

            switchStates(State.waiting);
        }
Ejemplo n.º 19
0
		/// <summary>
		/// 
		/// </summary>
		public Connection(Server server, TSocketSettings socketSettings)
		{
			Created = DateTime.Now;
			Server = server;
			if (server.IsFramed)
			{
				var tsocket = new TSocket(server.Host, server.Port);
				_transport = new TFramedTransport(tsocket);
//				_transport = new TFramedTransport(server.Host, server.Port, socketSettings);
			}
			else
			{
				var tsocket = new TSocket(server.Host, server.Port);
				_transport = new TBufferedTransport(tsocket, 1024); //TODO remove hardcode
			}

			_protocol = new TBinaryProtocol(_transport);
			_client = new Rest.Client(_protocol);
		}
Ejemplo n.º 20
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        internal Connection(Server server, int timeout = 0)
        {
            Created = DateTime.Now;
            Server = server;
            Timeout = timeout;

            //TcpClient client = new TcpClient(server.Host, server.Port);
            //client.NoDelay = true;
            //client.SendBufferSize = timeout;
            //client.ReceiveTimeout = timeout;

            //TTransport socket = new TSocket(client);

            TTransport socket = new TSocket(server.Host, server.Port, timeout);

            _transport = new TFramedTransport(socket);
            _protocol = new TBinaryProtocol(_transport);
            _client = new Cassandra.Client(_protocol);
        }
 /// <summary>
 /// TDAPIProtocol Constructor
 /// </summary>
 public TDAPIProtocol(TTransport trans)
     : base(trans)
 {
     DAPIAliases = new Dictionary<string, string>
     {
         { "payload", "p" },
         { "version", "v" },
         { "calls", "c" },
         { "token", "t" },
         { "method", "m" },
         { "argz", "al" }, // note that 'args', represented by 'argz' in struct
         { "name", "n" },
         { "appId", "a" },
         { "snId", "n" },
         { "userId", "u" },
         { "session", "s" },
         { "secret", "as" },
         { "userToken", "t" },
         { "appToken", "t" },
         { "stringToken", "t" }
     };
 }
 /// <summary>
 /// 推送比对记录
 /// </summary>
 /// <param name="info"></param>
 /// <param name="IP"></param>
 /// <returns></returns>
 public int UpdateCmp(RealtimeCmpInfo info, string IP)
 {
     try
     {
         // 生成socket套接字;
         Thrift.Transport.TSocket tsocket = new Thrift.Transport.TSocket(IP, 6000);
         //设置连接超时为100;
         tsocket.Timeout = 3000;
         //生成客户端对象
         Thrift.Transport.TTransport transport             = tsocket;
         Thrift.Protocol.TProtocol   protocol              = new Thrift.Protocol.TBinaryProtocol(transport);
         UIServer.Client             _BusinessServerClient = new UIServer.Client(protocol);
         transport.Open();
         _BusinessServerClient.UpdateRealtimeCmp(info, "##@" + info.Channel);
         transport.Close();
         return(0);
     }
     catch (Exception ex)
     {
         _WriteLog.WriteToLog("UpdateCmp", ex);
         return(-1);
     }
 }
Ejemplo n.º 23
0
 public TProtocol GetProtocol(TTransport trans)
 {
     return new TBinaryProtocol(trans, strictRead_, strictWrite_);
 }
 public TProtocol GetProtocol(TTransport trans)
 {
     return new TJSONProtocol(trans);
 }
 ///<summary>
 /// TJSONProtocol Constructor
 ///</summary>
 public TJSONProtocol(TTransport trans)
     : base(trans)
 {
     context = new JSONBaseContext(this);
     reader = new LookaheadReader(this);
 }
Ejemplo n.º 26
0
 public TTransport GetTransport(TTransport trans)
 {
     return(trans);
 }
Ejemplo n.º 27
0
 public void processContext(Object serverContext, Thrift.Transport.TTransport transport)
 {
     Console.WriteLine("Waiting for next client trade request");
 }
Ejemplo n.º 28
0
		public TFramedTransport(TTransport transport)
		{
			this.transport = transport;
		}
Ejemplo n.º 29
0
        public TFramedTransport(TTransport transport)
        {
            InnerTransport = transport ?? throw new ArgumentNullException(nameof(transport));

            InitWriteBuffer();
        }
Ejemplo n.º 30
0
 public virtual TTransport GetTransport(TTransport trans)
 {
     return(trans);
 }
Ejemplo n.º 31
0
 public override TTransport GetTransport(TTransport trans)
 {
     return(new TBufferedTransport(trans));
 }
Ejemplo n.º 32
0
 public void processContext(Object serverContext, Thrift.Transport.TTransport transport)
 {
     callCount++;
 }
Ejemplo n.º 33
0
 public override TTransport GetTransport(TTransport trans)
 {
     return(new TFramedTransport(trans));
 }
Ejemplo n.º 34
0
 public TBinaryProtocol(TTransport trans)
     : this(trans, false, true)
 {
 }
Ejemplo n.º 35
0
        public static void ClientTest(TTransport transport)
        {
            TBinaryProtocol binaryProtocol = new TBinaryProtocol(transport);

            ThriftTest.Client client = new ThriftTest.Client(binaryProtocol);
            try
            {
                if (!transport.IsOpen)
                {
                    transport.Open();
                }
            }
            catch (TTransportException ttx)
            {
                Console.WriteLine("Connect failed: " + ttx.Message);
                return;
            }

            long start = DateTime.Now.ToFileTime();

            Console.Write("testVoid()");
            client.testVoid();
            Console.WriteLine(" = void");

            Console.Write("testString(\"Test\")");
            string s = client.testString("Test");
            Console.WriteLine(" = \"" + s + "\"");

            Console.Write("testByte(1)");
            byte i8 = client.testByte((byte)1);
            Console.WriteLine(" = " + i8);

            Console.Write("testI32(-1)");
            int i32 = client.testI32(-1);
            Console.WriteLine(" = " + i32);

            Console.Write("testI64(-34359738368)");
            long i64 = client.testI64(-34359738368);
            Console.WriteLine(" = " + i64);

            Console.Write("testDouble(5.325098235)");
            double dub = client.testDouble(5.325098235);
            Console.WriteLine(" = " + dub);

            Console.Write("testStruct({\"Zero\", 1, -3, -5})");
            Xtruct o = new Xtruct();
            o.String_thing = "Zero";
            o.Byte_thing = (byte)1;
            o.I32_thing = -3;
            o.I64_thing = -5;
            Xtruct i = client.testStruct(o);
            Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");

            Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
            Xtruct2 o2 = new Xtruct2();
            o2.Byte_thing = (byte)1;
            o2.Struct_thing = o;
            o2.I32_thing = 5;
            Xtruct2 i2 = client.testNest(o2);
            i = i2.Struct_thing;
            Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");

            Dictionary<int, int> mapout = new Dictionary<int, int>();
            for (int j = 0; j < 5; j++)
            {
                mapout[j] = j - 10;
            }
            Console.Write("testMap({");
            bool first = true;
            foreach (int key in mapout.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapout[key]);
            }
            Console.Write("})");

            Dictionary<int, int> mapin = client.testMap(mapout);

            Console.Write(" = {");
            first = true;
            foreach (int key in mapin.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapin[key]);
            }
            Console.WriteLine("}");

            List<int> listout = new List<int>();
            for (int j = -2; j < 3; j++)
            {
                listout.Add(j);
            }
            Console.Write("testList({");
            first = true;
            foreach (int j in listout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            List<int> listin = client.testList(listout);

            Console.Write(" = {");
            first = true;
            foreach (int j in listin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");

            //set
            THashSet<int> setout = new THashSet<int>();
            for (int j = -2; j < 3; j++)
            {
                setout.Add(j);
            }
            Console.Write("testSet({");
            first = true;
            foreach (int j in setout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            THashSet<int> setin = client.testSet(setout);

            Console.Write(" = {");
            first = true;
            foreach (int j in setin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");

            Console.Write("testEnum(ONE)");
            Numberz ret = client.testEnum(Numberz.ONE);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(TWO)");
            ret = client.testEnum(Numberz.TWO);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(THREE)");
            ret = client.testEnum(Numberz.THREE);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(FIVE)");
            ret = client.testEnum(Numberz.FIVE);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(EIGHT)");
            ret = client.testEnum(Numberz.EIGHT);
            Console.WriteLine(" = " + ret);

            Console.Write("testTypedef(309858235082523)");
            long uid = client.testTypedef(309858235082523L);
            Console.WriteLine(" = " + uid);

            Console.Write("testMapMap(1)");
            Dictionary<int, Dictionary<int, int>> mm = client.testMapMap(1);
            Console.Write(" = {");
            foreach (int key in mm.Keys)
            {
                Console.Write(key + " => {");
                Dictionary<int, int> m2 = mm[key];
                foreach (int k2 in m2.Keys)
                {
                    Console.Write(k2 + " => " + m2[k2] + ", ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            Insanity insane = new Insanity();
            insane.UserMap = new Dictionary<Numberz, long>();
            insane.UserMap[Numberz.FIVE] = 5000L;
            Xtruct truck = new Xtruct();
            truck.String_thing = "Truck";
            truck.Byte_thing = (byte)8;
            truck.I32_thing = 8;
            truck.I64_thing = 8;
            insane.Xtructs = new List<Xtruct>();
            insane.Xtructs.Add(truck);
            Console.Write("testInsanity()");
            Dictionary<long, Dictionary<Numberz, Insanity>> whoa = client.testInsanity(insane);
            Console.Write(" = {");
            foreach (long key in whoa.Keys)
            {
                Dictionary<Numberz, Insanity> val = whoa[key];
                Console.Write(key + " => {");

                foreach (Numberz k2 in val.Keys)
                {
                    Insanity v2 = val[k2];

                    Console.Write(k2 + " => {");
                    Dictionary<Numberz, long> userMap = v2.UserMap;

                    Console.Write("{");
                    if (userMap != null)
                    {
                        foreach (Numberz k3 in userMap.Keys)
                        {
                            Console.Write(k3 + " => " + userMap[k3] + ", ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}, ");

                    List<Xtruct> xtructs = v2.Xtructs;

                    Console.Write("{");
                    if (xtructs != null)
                    {
                        foreach (Xtruct x in xtructs)
                        {
                            Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}");

                    Console.Write("}, ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            byte arg0 = 1;
            int arg1 = 2;
            long arg2 = long.MaxValue;
            Dictionary<short, string> multiDict = new Dictionary<short, string>();
            multiDict[1] = "one";
            Numberz arg4 = Numberz.FIVE;
            long arg5 = 5000000;
            Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
            Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
            Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
                        + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");

            Console.WriteLine("Test Async(1)");
            client.testAsync(1);
        }
Ejemplo n.º 36
0
 public TBinaryProtocol(TTransport trans, bool strictRead, bool strictWrite)
     : base(trans)
 {
     strictRead_ = strictRead;
     strictWrite_ = strictWrite;
 }
Ejemplo n.º 37
0
		protected TProtocol(TTransport trans)
		{
			this.trans = trans;
		}
Ejemplo n.º 38
0
        /// <summary>
        /// Establish a connection to the server (ARE)
        /// </summary>
        /// <param name="ipAddress">IP-Address of the ARE</param>
        /// <param name="port">Port to connect</param>
        /// <returns>A ASAPI-client object</returns>
        public AsapiServer.Client Connect(string ipAddress, int port, int timeOutParam)
        {
            int timeOut = 10000;

            if (timeOutParam == -1) {
                // read socket timeout from the ini-file
                try {
                    IniFile ini = null;
                    if (File.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\asterics.ini")) {
                        ini = new IniFile(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\asterics.ini");
                    } else if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "asterics.ini")) {
                        ini = new IniFile(AppDomain.CurrentDomain.BaseDirectory + "asterics.ini");
                    }
                    if (ini != null) {
                        timeOut = int.Parse(ini.IniReadValue("ARE", "socket_timeout"));
                        if (timeOut < 100) {
                            timeOut = 10000;
                        }
                    }
                } catch (Exception) {
                }
            } else {
                timeOut = timeOutParam;
            }

            try {
                transport = new TSocket(ipAddress, port, timeOut); // set socket timeout to 10000ms
                protocol = new TBinaryProtocol(transport);
                client = new AsapiServer.Client(protocol);

                transport.Open();
                return client;

            } catch (Exception) { //catch (TApplicationException x) {
                //throw e;
                return null;
            }
        }
Ejemplo n.º 39
0
 public TFramedTransport(TTransport transport) : this()
 {
     this.transport = transport;
 }