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"); }
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); } }
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); } }
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 } }