Exemple #1
0
        protected IRemoteController CreateRemoteController()
        {
            try
            {
#if NETFRAMEWORK
                var transport = new Thrift.Transport.TFramedTransport(new Thrift.Transport.TSocket("localhost", 9701));
                transport.Open();
                var protocol = new Thrift.Protocol.TBinaryProtocol(transport);
                return(new ThreadSafeRemoteController(protocol));
#else
                var rcHostAddress    = AddressUtil.GetAddressByName("localhost");
                var tSocketTransport = new Thrift.Transport.Client.TSocketTransport(rcHostAddress, 9701);
                var transport        = new Thrift.Transport.TFramedTransport(tSocketTransport);
                if (!transport.IsOpen)
                {
                    transport.OpenAsync().Wait();
                }
                var protocol = new Thrift.Protocol.TBinaryProtocol(transport);
                return(new ThreadSafeRemoteController(protocol));
#endif
            }
            catch (Exception e)
            {
                _logger.Finest("Cannot start Remote Controller", e);
                _logger.Finest(e.StackTrace);
                throw new AssertionException("Cannot start Remote Controller", e);
            }
        }
        Task <IRemoteControllerClient> ConnectToRemoteControllerAsync()
        {
            // assume we can start the RC, else mark the test as inconclusive without even trying
            // so... if starting the RC fails once, we probably have a problem (is it even running?)
            // and there is no point trying again and again - faster to stop here
            Assume.That(_canConnectToRemoveController, Is.True, () => "Cannot connect to the Remote Controller (is it running?).");

            try
            {
#if NETFRAMEWORK
                var transport = new Thrift.Transport.TFramedTransport(new Thrift.Transport.TSocket("localhost", 9701));
                transport.Open();
                var protocol = new Thrift.Protocol.TBinaryProtocol(transport);
                return(Task.FromResult(RemoteControllerClient.Create(protocol)));
#else
                var rcHostAddress    = NetworkAddress.GetIPAddressByName("localhost");
                var tSocketTransport = new Thrift.Transport.Client.TSocketTransport(rcHostAddress, 9701);
                var transport        = new Thrift.Transport.TFramedTransport(tSocketTransport);
                if (!transport.IsOpen)
                {
                    await transport.OpenAsync().CfAwait();
                }
                var protocol = new Thrift.Protocol.TBinaryProtocol(transport);
                return(RemoteControllerClient.Create(protocol));
#endif
            }
            catch (Exception e)
            {
                _canConnectToRemoveController = false; // fail fast other tests
                Logger?.LogDebug(e, "Cannot connect to the Remote Controller (is it running?)");
                throw new AssertionException("Cannot connect to the Remote Controller (is it running?)", e);
            }
        }
        /// <summary>
        /// 更新比对记录标识
        /// </summary>
        /// <param name="info"></param>
        /// <param name="IP"></param>
        /// <returns></returns>
        public static int UpdateCmp(RealtimeCmpInfoLBS 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);
                info.Channelname = "##@" + info.Channelname;
                _BusinessServerClient.UpdateRealtimeCmpLBS(info);
                if ("DEBUG".Equals(GlobalCache.AppMode))
                {
                    MessageBox.Show("推送成功");
                }
                transport.Close();
                return(0);
            }
            catch (Exception ex)
            {
                if ("DEBUG".Equals(GlobalCache.AppMode))
                {
                    MessageBox.Show(ex.Message);
                }
                Logger <WarningMessageCmd> .Log.Error("UpdateCmp", ex);

                return(-1);
            }
        }
Exemple #4
0
        public static byte[] EncodeMsg(Thrift.Protocol.TBase reqMsg)
        {
            var tmem  = new Thrift.Transport.TMemoryBuffer();
            var proto = new Thrift.Protocol.TBinaryProtocol(tmem);

            //proto.WriteMessageBegin(new Thrift.Protocol.TMessage("ff::RegisterToBrokerReq", Thrift.Protocol.TMessageType.Call, 0));
            reqMsg.Write(proto);
            //proto.WriteMessageEnd();
            byte[] byteData = tmem.GetBuffer();
            return(byteData);
        }
Exemple #5
0
        public static bool decodeMsg <T>(T reqMsg, string strData) where T : Thrift.Protocol.TBase
        {
            byte[] data  = System.Text.Encoding.UTF8.GetBytes(strData);
            var    tmem  = new Thrift.Transport.TMemoryBuffer(data);
            var    proto = new Thrift.Protocol.TBinaryProtocol(tmem);

            //var msgdef = new Thrift.Protocol.TMessage("ffthrift", Thrift.Protocol.TMessageType.Call, 0);
            //proto.ReadMessageBegin();
            reqMsg.Read(proto);
            //proto.ReadMessageEnd();
            return(true);
        }
Exemple #6
0
        public static string encodeMsg <T>(T reqMsg) where T : Thrift.Protocol.TBase
        {
            var tmem  = new Thrift.Transport.TMemoryBuffer();
            var proto = new Thrift.Protocol.TBinaryProtocol(tmem);

            //proto.WriteMessageBegin(new Thrift.Protocol.TMessage("ff::RegisterToBrokerReq", Thrift.Protocol.TMessageType.Call, 0));
            reqMsg.Write(proto);
            //proto.WriteMessageEnd();
            byte[] byteData = tmem.GetBuffer();
            string strRet   = System.Text.Encoding.UTF8.GetString(byteData, 0, byteData.Length);

            return(strRet);
        }
Exemple #7
0
        public static bool DecodeMsg(Thrift.Protocol.TBase reqMsg, byte[] data)
        {
            if (data.Length == 0)
            {
                return(false);
            }
            var tmem  = new Thrift.Transport.TMemoryBuffer(data);
            var proto = new Thrift.Protocol.TBinaryProtocol(tmem);

            //var msgdef = new Thrift.Protocol.TMessage("ffthrift", Thrift.Protocol.TMessageType.Call, 0);
            //proto.ReadMessageBegin();
            reqMsg.Read(proto);
            //proto.ReadMessageEnd();
            return(true);
        }
Exemple #8
0
        public static void Main(String[] args)
        {
            try {
                Thrift.Transport.TTransport transport;
                transport = new Thrift.Transport.TSocket("suchlol.com", 9090);
                transport.Open();

                Thrift.Protocol.TProtocol protocol = new  Thrift.Protocol.TBinaryProtocol(transport);
                client = new geospatial.thrift.Geospatial.Client(protocol);

                perform(client);
                transport.Close();
            } catch (TException x) {
                Console.WriteLine(x.StackTrace);
            }
        }
 /// <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);
     }
 }
Exemple #10
0
    public void SendAsync(Thrift.Protocol.TBase data, Action<bool> completed)
    {
        MemoryStream stream = new MemoryStream();
        Thrift.Protocol.TProtocol tProtocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(null, stream));

        data.Write(tProtocol);

        SendAsync(stream.ToArray(), completed);
    }
Exemple #11
0
 public MahoutThriftClient(Thrift.Protocol.TBinaryProtocol proto)
 {
     this._proto = proto;
     client      = new MahoutThrift.Client(_proto);
 }
        private static void TestSerialization()
        {
            var watch = new Stopwatch();
            byte[] data = null;

            Console.WriteLine("Serialization Tests:");
            Console.WriteLine();
            Console.WriteLine("Protobuf:");

            {
                StartTest(watch, "Test 1: Create and Serialize");

                for (int i = 0; i < 1000000; i++)
                {
                    data = CreateCommandBuilder().Build().ToByteArray();
                }

                EndTest(watch, data, 1000000, "Created and serialized command");
            }

            {
                StartTest(watch, "Test 2: Serialize Existing");

                var builder = CreateCommandBuilder();

                for (int i = 0; i < 1000000; i++)
                {
                    data = builder.Build().ToByteArray();
                }

                EndTest(watch, data, 1000000, "Serialized command");
            }

            Console.WriteLine();
            Console.WriteLine("FastJSON:");

            {
                StartTest(watch, "Test 1: Create and Serialize");

                for (int i = 0; i < 1000000; i++)
                {
                    var command = CreateJSONCommand();

                    data = System.Text.Encoding.ASCII.GetBytes(fastJSON.JSON.Instance.ToJSON(command));
                }

                EndTest(watch, data, 1000000, "Created and serialized command");
            }

            {
                StartTest(watch, "Test 2: Serialize Existing");

                var jsonCommand = CreateJSONCommand();

                for (int i = 0; i < 1000000; i++)
                {
                    data = System.Text.Encoding.ASCII.GetBytes(fastJSON.JSON.Instance.ToJSON(jsonCommand));
                }

                EndTest(watch, data, 1000000, "Serialized command");
            }

            Console.WriteLine();
            Console.WriteLine("JSON.Net");

            {
                StartTest(watch, "Test 1: Create and Serialize");

                for (int i = 0; i < 1000000; i++)
                {
                    var command = CreateJSONNetCommand();

                    data = System.Text.Encoding.ASCII.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(command));
                }

                EndTest(watch, data, 1000000, "Created and serialized command");
            }

            {
                StartTest(watch, "Test 2: Serialize Existing");

                var command = CreateJSONNetCommand();

                for (int i = 0; i < 1000000; i++)
                {
                    data = System.Text.Encoding.ASCII.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(command));
                }

                EndTest(watch, data, 1000000, "Serialized command");
            }

            Console.WriteLine();
            Console.WriteLine("MS XML Serializer");

            {
                StartTest(watch, "Test 1: Create and Serialize");

                var serializer = new XmlSerializer(typeof(MSXML.Command));

                for (int i = 0; i < 1000000; i++)
                {
                    var command = CreateXMLCommand();

                    var stream = new MemoryStream();

                    serializer.Serialize(stream, command);

                    data = stream.ToArray();
                }

                EndTest(watch, data, 1000000, "Created and serialized command");
            }

            {
                StartTest(watch, "Test 2: Serialize Existing");

                var serializer = new XmlSerializer(typeof(MSXML.Command));

                var command = CreateXMLCommand();

                for (int i = 0; i < 1000000; i++)
                {
                    var stream = new MemoryStream();

                    serializer.Serialize(stream, command);

                    data = stream.ToArray();
                }

                EndTest(watch, data, 1000000, "Serialized command");
            }

            Console.WriteLine();

            Console.WriteLine("MessagePack");

            {
                StartTest(watch, "Test 1: Create and Serialize");

                for (int i = 0; i < 1000000; i++)
                {
                    var command = CreateMessagePackCommand();

                    data = new CompiledPacker(true).Pack<MessagePack.Command>(command);
                }

                EndTest(watch, data, 1000000, "Created and serialized command");
            }

            {
                StartTest(watch, "Test 2: Serialize Existing");

                var command = CreateMessagePackCommand();

                for (int i = 0; i < 1000000; i++)
                {
                    data = new CompiledPacker(true).Pack<MessagePack.Command>(command);
                }

                EndTest(watch, data, 1000000, "Serialized command");
            }

            Console.WriteLine("Thrift");

            {
                StartTest(watch, "Test 1: Create and Serialize");

                for (int i = 0; i < 1000000; i++)
                {
                    var command = CreateThriftCommand();

                    var stream = new MemoryStream();

                    var protocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(stream, stream));

                    command.Write(protocol);

                    data = stream.ToArray();
                }

                EndTest(watch, data, 1000000, "Created and serialized command");
            }

            {
                StartTest(watch, "Test 2: Serialize Existing");

                var command = CreateThriftCommand();

                for (int i = 0; i < 1000000; i++)
                {
                    var stream = new MemoryStream();

                    var protocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(stream, stream));

                    command.Write(protocol);

                    data = stream.ToArray();
                }

                EndTest(watch, data, 1000000, "Serialized command");
            }
        }
Exemple #13
0
 public SqoopThriftClient(Thrift.Protocol.TBinaryProtocol proto)
 {
     this._proto = proto;
     client      = new SqoopThrift.Client(_proto);
 }