Beispiel #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));
 }
Beispiel #3
0
        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();
        }
Beispiel #4
0
 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;
 }
        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();
        }
        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();
        }
Beispiel #7
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;
 }
Beispiel #8
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;
        }
        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);
            }
        }
 private TTransport CreateInstance()
 {
     TTransport transport = new TFramedTransport(new TSocket(Conf.TSeriviceHost, Conf.TServicePort));
     transport.Open();
     return transport;
 }
        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);
        }
Beispiel #12
0
 /// <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;
 }
        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;
        }
Beispiel #14
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;
        }
Beispiel #15
0
        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);
            }
        }
Beispiel #16
0
		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
			}
		}