コード例 #1
0
        static void Main(string[] args)
        {
            // Initialize log4net
            l4n.Config.XmlConfigurator.Configure();

            // Create log
            var log = new LogEntry();
            log.Category = "Program";
            log.Message = "This is a test error message from the program";

            // Connect
            var socket = new TSocket("192.168.1.144",65510,300);
            var transport = new TFramedTransport(socket);
            var protocol = new TBinaryProtocol(transport,false,false);
            var scribeClient = new scribe.Client(protocol);
            transport.Open();

            // Send
            var logs = new List<LogEntry>();
            logs.Add(log);
            var result = scribeClient.Log(logs);

            // Close
            transport.Close();

            // use log4net to log
            var logger = l4n.LogManager.GetLogger("ScribeAppender.Test.Program");
            logger.Debug("This is a test error message from the logger");
        }
 public Apache.Cassandra.Cassandra.Iface CreateConnection(String host, Int32 port)
 {
     TSocket socket = new TSocket(host, port);
     TTransport trans = new TFramedTransport(socket);
     trans.Open();
     return new Apache.Cassandra.Cassandra.Client(new TBinaryProtocol(trans));
 }
コード例 #3
0
        public IClient Create(IEndpoint endpoint, IClientPool ownerPool)
        {
            TSocket socket = null;
            TTransport transport = null;
            if (endpoint.Timeout == 0)
            {
                socket = new TSocket(endpoint.Address, endpoint.Port);
            }
            else
            {
                socket = new TSocket(endpoint.Address, endpoint.Port, endpoint.Timeout);
            }
            TcpClient tcpClient = socket.TcpClient;
            transport = new TFramedTransport(socket);
            TProtocol protocol = new TBinaryProtocol(transport);
            CassandraClient cassandraClient = new CassandraClient(protocol);
            IClient client = new DefaultClient()
            {
                CassandraClient = cassandraClient,
                Endpoint = endpoint,
                OwnerPool = ownerPool,
                TcpClient = tcpClient,
                Created = DateTime.Now
            };

            return client;
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: KevinT/fluentcassandra
        private static void Main()
        {
            TTransport framedTransport = new TFramedTransport(new TSocket("localhost", 9160));
            TTransport socketTransport = new TSocket("localhost", 9160);
            TProtocol framedProtocol = new TBinaryProtocol(framedTransport);
            TProtocol socketProtocol = new TBinaryProtocol(socketTransport);

            var client = new Cassandra.Client(framedProtocol, framedProtocol); // all framed
            //var client = new Cassandra.Client(socketProtocol, socketProtocol); // all socket
            //var client = new Cassandra.Client(framedProtocol, socketProtocol); // in: framed out: socket
            //var client = new Cassandra.Client(socketProtocol, framedProtocol); // in: socket out: framed

            framedTransport.Open();
            socketTransport.Open();
            Console.WriteLine("Start");

            client.set_keyspace("Keyspace1");

            Console.WriteLine("Count Key");
            var key = Encoding.ASCII.GetBytes("MyKey");
            var columns = new List<byte[]>(new[] { Encoding.ASCII.GetBytes("MyColumn") });
            var column_parent = new ColumnParent {
                Column_family = "Standard1"
            };
            var predicate = new SlicePredicate {
                Column_names = columns
            };
            client.get_count(key, column_parent, predicate, ConsistencyLevel.ALL);

            Console.WriteLine("Done");
            Console.Read();
        }
コード例 #5
0
ファイル: ThriftTool.cs プロジェクト: died/logs.died.tw
 public static Cassandra.Client GetWebClient()
 {
     var transport = new TFramedTransport(new TSocket("localhost", 9160));
     var client = new Cassandra.Client(new TBinaryProtocol(transport));
     transport.Open();
     client.set_keyspace(_keySpace);
     return client;
 }
コード例 #6
0
        public ThriftClient(string host, int port)
        {
            if (host == null) throw new ArgumentNullException("host");

            _transport = new TFramedTransport(new TSocket(host, port));
            TProtocol protocol = new TCompactProtocol(_transport);
            _client = new ThriftSourceProtocol.Client(protocol);
            _transport.Open();
        }
コード例 #7
0
ファイル: ThriftTool.cs プロジェクト: died/logs.died.tw
 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;
 }
コード例 #8
0
        public override void Open(string hostname)
        {
            base.Open(hostname);

            TTransport transport = new TFramedTransport(new TSocket(hostname, 9160));
            TProtocol protocol = new TBinaryProtocol(transport);
            _client = new Cassandra.Client(protocol);

            transport.Open();
        }
コード例 #9
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _transport.Close();
                    _transport.Dispose();
                    _transport = null;
                }
            }

            _disposed = true;
        }
コード例 #10
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            TSocket socket;
            Cassandra.Client client;

            socket = new TSocket(hostNameTextBox.Text, int.Parse(portTextBox.Text));
            //socket.Open();

            TFramedTransport transport = new TFramedTransport(socket);
            TBinaryProtocol protocol = new TBinaryProtocol(transport);
            client = new Cassandra.Client(protocol);

            transport.Open();

            mainForm.Client = client;
            this.DialogResult = DialogResult.OK;
        }
コード例 #11
0
            public TTransport CreateTransport()
            {
                if (url == null)
                {
                    // endpoint transport
                    TTransport trans = null;
                    if (pipe != null)
                        trans = new TNamedPipeClientTransport(pipe);
                    else
                    {
                        if (encrypted)
                        {
                            string certPath = "../keys/client.p12";
                            X509Certificate cert = new X509Certificate2(certPath, "thrift");
                            trans = new TTLSSocket(host, port, 0, cert, (o, c, chain, errors) => true, null, SslProtocols.Tls);
                        }
                        else
                        {
                            trans = new TSocket(host, port);
                        }
                    }

                    // layered transport
                    if (buffered)
                        trans = new TBufferedTransport(trans);
                    if (framed)
                        trans = new TFramedTransport(trans);

                    if (_isFirstTransport)
                    {
                        //ensure proper open/close of transport
                        trans.Open();
                        trans.Close();
                        _isFirstTransport = false;
                    }
                    return trans;
                }
                else
                {
                    return new THttpClient(new Uri(url));
                }
            }
コード例 #12
0
        static void Execute(int port)
        {
            try
            {
                TTransport trans;
                trans = new TSocket("localhost", port);
                trans = new TFramedTransport(trans);
                trans.Open();

                TProtocol Protocol = new TBinaryProtocol(trans, true, true);

                TMultiplexedProtocol multiplex;

                multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_BENCHMARKSERVICE);
                BenchmarkService.Iface bench = new BenchmarkService.Client(multiplex);

                multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_AGGR);
                Aggr.Iface aggr = new Aggr.Client(multiplex);

                for (sbyte i = 1; 10 >= i; ++i)
                {
                    aggr.addValue(bench.fibonacci(i));
                }

                foreach (int k in aggr.getValues())
                {
                    Console.Write(k.ToString() + " ");
                    Console.WriteLine("");
                }
                trans.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #13
0
        /// <summary>
        /// create an instance
        /// </summary>
        /// <returns></returns>
        private TTransport CreateInstance()
        {
            TSocket socket = new TSocket(config.Host, config.Port);
            if (config.Timeout > 0)
                socket.Timeout = config.Timeout;

            TTransport transport = new TFramedTransport(socket);
            transport.Open();
            return transport;
        }
コード例 #14
0
ファイル: Producer.cs プロジェクト: robskillington/NScribely
		private void FlushQueue()
		{
			if (Queue.Count < 1)
			{
				ScheduleFlush();
				return;
			}

			TFramedTransport transport;
			TBinaryProtocol protocol;

			try
			{
				var socket = new TSocket(Host, Port)
					{
						Timeout = DefaultEndpointTimeoutMs
					};

				transport = new TFramedTransport(socket);
				protocol = new TBinaryProtocol(transport, false, false);

				transport.Open();
			}
			catch (IOException exception)
			{
				// Connection failure, reschedule another flush
				ScheduleFlush();

				return;
			}
			

			var client = new ScribeClient.Client(protocol);
			var retry = new List<Item>();

			while (Queue.Count > 0)
			{
				Item item;

				try
				{
					item = Queue.Dequeue() as Item;
				}
				catch (InvalidOperationException)
				{
					// No item available, while loop will ensure we fall out after this
					continue;
				}

				if (item == null)
				{
					continue;
				}

				try
				{
					client.Log(new List<LogEntry>
						{
							new LogEntry
								{
									Category = item.Category,
									Message = item.Message
								}
						});
				}
				catch (IOException)
				{
					// Retry next iteration
					retry.Add(item);

					// Break out, likely not connected anymore
					break;
				}
				catch (Exception)
				{
					// Retry next iteration
					retry.Add(item);
				}
			}

			// Add to the queue items to retry
			foreach (var item in retry)
			{
				Queue.Enqueue(item);
			}

			// Raise flushed event
			QueueFlushed(this, EventArgs.Empty);

			// Reschedule another flush
			ScheduleFlush();

			try
			{
				transport.Close();
			}
			catch (IOException exception)
			{
				// Likely the connection was never open
			}
		}
コード例 #15
0
 private TTransport CreateInstance()
 {
     TTransport transport = new TFramedTransport(new TSocket(Conf.TSeriviceHost, Conf.TServicePort));
     transport.Open();
     return transport;
 }
コード例 #16
0
ファイル: TestClient.cs プロジェクト: gembler/blade-libs
		public static void Execute(string[] args)
		{
			try
			{
				string host = "localhost";
				int port = 9090;
				string url = null;
				int numThreads = 1;
				bool buffered = false, framed = false;

				try
				{
					for (int i = 0; i < args.Length; i++)
					{
						if (args[i] == "-h")
						{
							string[] hostport = args[++i].Split(':');
							host = hostport[0];
							if (hostport.Length > 1)
							{
								port = Convert.ToInt32(hostport[1]);
							}
						}
						else if (args[i] == "-u")
						{
							url = args[++i];
						}
						else if (args[i] == "-n")
						{
							numIterations = Convert.ToInt32(args[++i]);
						}
						else if (args[i] == "-b" || args[i] == "-buffered")
						{
							buffered = true;
							Console.WriteLine("Using buffered sockets");
						}
						else if (args[i] == "-f" || args[i] == "-framed")
						{
							framed = true;
							Console.WriteLine("Using framed transport");
						}
						else if (args[i] == "-t")
						{
							numThreads = Convert.ToInt32(args[++i]);
						}
					}
				}
				catch (Exception e)
				{
					Console.WriteLine(e.StackTrace);
				}



				//issue tests on separate threads simultaneously
				Thread[] threads = new Thread[numThreads];
				DateTime start = DateTime.Now;
				for (int test = 0; test < numThreads; test++)
				{
					Thread t = new Thread(new ParameterizedThreadStart(ClientThread));
					threads[test] = t;
					if (url == null)
					{
						TTransport trans = new TSocket(host, port);
						if (buffered)
							trans = new TBufferedTransport(trans as TStreamTransport);
						if (framed)
							trans = new TFramedTransport(trans);
							
						t.Start(trans);
					}
					else
					{
						THttpClient http = new THttpClient(new Uri(url));
						t.Start(http);
					}
				}

				for (int test = 0; test < numThreads; test++)
				{
					threads[test].Join();
				}
				Console.Write("Total time: " + (DateTime.Now - start));
			}
			catch (Exception outerEx)
			{
				Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace);
			}

			Console.WriteLine();
			Console.WriteLine();
		}
コード例 #17
0
ファイル: TestClient.cs プロジェクト: luoaguo/thrift
        public static bool Execute(string[] args)
        {
            try
            {
                string host = "localhost";
                int port = 9090;
                string url = null, pipe = null;
                int numThreads = 1;
                bool buffered = false, framed = false, encrypted = false;
                string certPath = "../../../../../keys/server.pem";

                try
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] == "-u")
                        {
                            url = args[++i];
                        }
                        else if (args[i] == "-n")
                        {
                            numIterations = Convert.ToInt32(args[++i]);
                        }
                        else if (args[i] == "-pipe")  // -pipe <name>
                        {
                            pipe = args[++i];
                            Console.WriteLine("Using named pipes transport");
                        }
                        else if (args[i].Contains("--host="))
                        {
                            host = args[i].Substring(args[i].IndexOf("=") + 1);
                        }
                        else if (args[i].Contains("--port="))
                        {
                            port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1));
                        }
                        else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
                        {
                            buffered = true;
                            Console.WriteLine("Using buffered sockets");
                        }
                        else if (args[i] == "-f" || args[i] == "--framed"  || args[i] == "--transport=framed")
                        {
                            framed = true;
                            Console.WriteLine("Using framed transport");
                        }
                        else if (args[i] == "-t")
                        {
                            numThreads = Convert.ToInt32(args[++i]);
                        }
                        else if (args[i] == "--compact" || args[i] == "--protocol=compact")
                        {
                            protocol = "compact";
                            Console.WriteLine("Using compact protocol");
                        }
                        else if (args[i] == "--json" || args[i] == "--protocol=json")
                        {
                            protocol = "json";
                            Console.WriteLine("Using JSON protocol");
                        }
                        else if (args[i] == "--ssl")
                        {
                            encrypted = true;
                            Console.WriteLine("Using encrypted transport");
                        }
                        else if (args[i].StartsWith("--cert="))
                        {
                            certPath = args[i].Substring("--cert=".Length);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }

                //issue tests on separate threads simultaneously
                Thread[] threads = new Thread[numThreads];
                DateTime start = DateTime.Now;
                for (int test = 0; test < numThreads; test++)
                {
                    Thread t = new Thread(new ParameterizedThreadStart(ClientThread));
                    threads[test] = t;
                    if (url == null)
                    {
                        // endpoint transport
                        TTransport trans = null;
                        if (pipe != null)
                            trans = new TNamedPipeClientTransport(pipe);
                        else
                        {
                            if (encrypted)
                                trans = new TTLSSocket(host, port, certPath);
                            else
                                trans = new TSocket(host, port);
                        }

                        // layered transport
                        if (buffered)
                            trans = new TBufferedTransport(trans as TStreamTransport);
                        if (framed)
                            trans = new TFramedTransport(trans);

                        //ensure proper open/close of transport
                        trans.Open();
                        trans.Close();
                        t.Start(trans);
                    }
                    else
                    {
                        THttpClient http = new THttpClient(new Uri(url));
                        t.Start(http);
                    }
                }

                for (int test = 0; test < numThreads; test++)
                {
                    threads[test].Join();
                }
                Console.Write("Total time: " + (DateTime.Now - start));
            }
            catch (Exception outerEx)
            {
                Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace);
                return false;
            }

            Console.WriteLine();
            Console.WriteLine();
            return true;
        }
コード例 #18
0
        private Apache.Cassandra.Cassandra.Client CreateConnection(String host)
        {
            TSocket socket = new TSocket(host, this.port);
            TTransport trans = new TFramedTransport(socket);
            try
            {
                trans.Open();
            }
            catch (TTransportException exception)
            {
                throw new Exception("unable to connect to server", exception);
            }

            Apache.Cassandra.Cassandra.Client client = new Apache.Cassandra.Cassandra.Client(new TBinaryProtocol(trans));
            if (this.ringKs != null)
            {
                try
                {
                    client.set_keyspace(this.ringKs);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }

            return client;
        }
コード例 #19
0
ファイル: ThreadPool.cs プロジェクト: complus206/arch
 /// <summary>
 /// 创建一个对象
 /// </summary>
 /// <returns></returns>
 private TTransport CreateInstance()
 {
     //TTransport transport = new TSocket(config.Host, config.Port);
     TTransport transport = new TFramedTransport(new TSocket(_Config.Host, _Config.Port));
     transport.Open();
     return transport;
 }
コード例 #20
0
        public void ThriftRunWritePerformanceSingleThread()
        {
            Console.WriteLine("============================================================");
            Console.WriteLine(" Thrift Driver write performance test single thread ");
            Console.WriteLine("============================================================");

            TTransport transport = new TFramedTransport(new TSocket("localhost", 9160));
            TProtocol protocol = new TBinaryProtocol(transport);
            Cassandra.Client client = new Cassandra.Client(protocol);

            transport.Open();

            const string dropFoo = "drop keyspace Tests";
            try
            {
                client.execute_cql3_query(Encoding.UTF8.GetBytes(dropFoo), Compression.NONE, Apache.Cassandra.ConsistencyLevel.QUORUM);
            }
            catch
            {
            }

            const string createFoo = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
            Console.WriteLine("============================================================");
            Console.WriteLine(createFoo);
            Console.WriteLine("============================================================");

            client.execute_cql3_query(Encoding.UTF8.GetBytes(createFoo),
                                      Compression.NONE, Apache.Cassandra.ConsistencyLevel.QUORUM);
            Console.WriteLine();
            Console.WriteLine();

            const string createBar = "CREATE TABLE Tests.stresstest (strid varchar,intid int,PRIMARY KEY (strid))";
            Console.WriteLine("============================================================");
            Console.WriteLine(createBar);
            Console.WriteLine("============================================================");

            client.execute_cql3_query(Encoding.UTF8.GetBytes(createBar), Compression.NONE,
                                      Apache.Cassandra.ConsistencyLevel.QUORUM);
            Console.WriteLine();
            Console.WriteLine();

            CqlPreparedResult query = client.prepare_cql3_query(Encoding.UTF8.GetBytes("UPDATE tests.stresstest SET intid = ? WHERE strid = ?"),
                                                                Compression.NONE);

            int n = 0;
            while (n < NUM_ROUND)
            {
                var timer = new Stopwatch();
                timer.Start();

                for (int i = 0; i < NUM_WRITES_PER_ROUND; i++)
                {
                    CqlResult res = client.execute_prepared_cql3_query(query.ItemId,
                                                                       new List<byte[]>
                                                                           {
                                                                                   BitConverter.GetBytes(i).Reverse().ToArray(),
                                                                                   Encoding.ASCII.GetBytes(i.ToString("X"))
                                                                           },
                                                                       Apache.Cassandra.ConsistencyLevel.QUORUM);
                }

                timer.Stop();
                double rate = (1000.0*NUM_WRITES_PER_ROUND)/timer.ElapsedMilliseconds;
                Console.WriteLine("[Cassandra-Thrift] Time : " + timer.ElapsedMilliseconds + " (rate: " + rate + " qps)");
                n++;
            }

            Console.WriteLine("============================================================");
            Console.WriteLine(dropFoo);
            Console.WriteLine("============================================================");
            client.execute_cql3_query(Encoding.UTF8.GetBytes(dropFoo), Compression.NONE, Apache.Cassandra.ConsistencyLevel.QUORUM);
        }
コード例 #21
0
ファイル: HClient.cs プロジェクト: zbw911/CS4Hadoop
        public static void userFilter()
        {
            String host = "hserver";
            int port = 9090;
            int timeout = 10000;
            var framed = false;

            TTransport transport = new TSocket(host, port, timeout);
            if (framed)
            {
                transport = new TFramedTransport(transport);
            }
            TProtocol protocol = new TBinaryProtocol(transport);
            // This is our thrift client.
            THBaseService.Iface client = new THBaseService.Client(protocol);

            // open the transport
            transport.Open();

            transport.Close();
        }
コード例 #22
0
ファイル: HClient.cs プロジェクト: zbw911/CS4Hadoop
        public static void FistTest()
        {
            Console.WriteLine("Thrift2 Demo");
            Console.WriteLine("This demo assumes you have a table called \"example\" with a column family called \"family1\"");

            String host = "hserver";
            int port = 9090;
            int timeout = 10000;
            var framed = false;

            TTransport transport = new TSocket(host, port, timeout);
            if (framed)
            {
                transport = new TFramedTransport(transport);
            }
            TProtocol protocol = new TBinaryProtocol(transport);
            // This is our thrift client.
            THBaseService.Iface client = new THBaseService.Client(protocol);

            // open the transport
            transport.Open();

            var table = "t1".ToBytes();

            TPut put = new TPut();
            put.Row = ("row1".ToBytes());

            for (var i = 0; i < 1000; i++)
            {

                TColumnValue columnValue = new TColumnValue();
                columnValue.Family = ("f1".ToBytes());
                columnValue.Qualifier = ("qualifier" + i).ToBytes();
                columnValue.Value = ("value" + i).ToBytes();
                List<TColumnValue> columnValues = new List<TColumnValue>();
                columnValues.Add(columnValue);
                put.ColumnValues = columnValues;

                client.put(table, put);
            }

            TGet get = new TGet();
            get.Row = ("row1".ToBytes());

            TResult result = client.get(table, get);

            Console.WriteLine("row = " + result.Row.ToStr());
            foreach (TColumnValue resultColumnValue in result.ColumnValues)
            {
                Console.WriteLine("family = " + resultColumnValue.Family.ToStr());
                Console.WriteLine("qualifier = " + resultColumnValue.Qualifier.ToStr());
                Console.WriteLine("value = " + resultColumnValue.Value.ToStr());
                Console.WriteLine("timestamp = " + resultColumnValue.Timestamp);
            }

            transport.Close();
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: complus206/arch
        static void WorkFunc(object obj)
        {
            int index = (int)obj;
            try
            {
                //TTransport transport = new TSocket(svrAddr, 9090);
                TTransport transport = new TFramedTransport(new TSocket(svrAddr, 9090));
                TProtocol protocol = new TBinaryProtocol(transport);
                //TProtocol protocol = new TCompactProtocol(transport);

                transport.Open();
                Serv.Client client = new Serv.Client(protocol);
                Stopwatch watch = new Stopwatch();

                //Test One by One
                //watch.Start();
                //CreateReserveOneByOne(client);
                //watch.Stop();
                //Console.WriteLine("Create reseve one by one used {0}mss", watch.Elapsed.TotalMilliseconds);

                //Test Batch
                watch = new Stopwatch();
                watch.Start();
                CreateReserveBatch(client);
                watch.Stop();
                Console.WriteLine("Create reseve batch used {0}ms", watch.Elapsed.TotalMilliseconds);

                statResults[index] = watch.Elapsed.TotalMilliseconds;

                transport.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Thread {0} error!", index);
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                manualEvents[index].Set();
                Console.WriteLine("Thread {0} finished!", index);
            }
        }