/// <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); }
///<summary> /// TJSONProtocol Constructor ///</summary> public TJSONProtocol(TTransport trans) : base(trans) { context = new JSONBaseContext(this); reader = new LookaheadReader(this); }
/// <summary> /// Loops on processing a client forever /// threadContext will be a TTransport instance /// </summary> /// <param name="threadContext"></param> private void Execute(Object threadContext) { TTransport client = (TTransport)threadContext; TTransport inputTransport = null; TTransport outputTransport = null; TProtocol inputProtocol = null; TProtocol outputProtocol = null; Object connectionContext = null; try { inputTransport = inputTransportFactory.GetTransport(client); outputTransport = outputTransportFactory.GetTransport(client); inputProtocol = inputProtocolFactory.GetProtocol(inputTransport); outputProtocol = outputProtocolFactory.GetProtocol(outputTransport); //Recover event handler (if any) and fire createContext server event when a client connects if (serverEventHandler != null) { connectionContext = serverEventHandler.createContext(inputProtocol, outputProtocol); } //Process client requests until client disconnects while (!stop) { if (!inputTransport.Peek()) { break; } //Fire processContext server event //N.B. This is the pattern implemented in C++ and the event fires provisionally. //That is to say it may be many minutes between the event firing and the client request //actually arriving or the client may hang up without ever makeing a request. if (serverEventHandler != null) { serverEventHandler.processContext(connectionContext, inputTransport); } //Process client request (blocks until transport is readable) if (!processor.Process(inputProtocol, outputProtocol)) { break; } } } catch (TTransportException) { //Usually a client disconnect, expected } catch (Exception x) { //Unexpected logDelegate("Error: " + x); } //Fire deleteContext server event after client disconnects if (serverEventHandler != null) { serverEventHandler.deleteContext(connectionContext, inputProtocol, outputProtocol); } //Close transports if (inputTransport != null) { inputTransport.Close(); } if (outputTransport != null) { outputTransport.Close(); } }
public TBinaryProtocol(TTransport trans) : this(trans, false, true) { }
public Task ProcessContextAsync(object serverContext, TTransport transport, CancellationToken cancellationToken) { callCount++; return(Task.CompletedTask); }
public TFramedTransport(TTransport transport) : this() { this.transport = transport; }
/// <summary> /// /// </summary> public void Close() { CheckWasDisposed(); if (!IsOpen) return; lock (_lock) { _transport.Close(); _transport = null; _client = null; } }
protected TProtocol(TTransport trans) { this.trans = trans; }
public static void 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; 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"); } } } 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, "../../../../../keys/client.pem"); } 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); } Console.WriteLine(); Console.WriteLine(); }
public static void ClientTest(TTransport transport) { TProtocol proto; if (protocol == "compact") { proto = new TCompactProtocol(transport); } else if (protocol == "json") { proto = new TJSONProtocol(transport); } else { proto = new TBinaryProtocol(transport); } ThriftTest.Client client = new ThriftTest.Client(proto); 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)"); sbyte i8 = client.testByte((sbyte)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); byte[] binOut = PrepareTestData(true); Console.Write("testBinary(" + BytesToHex(binOut) + ")"); try { byte[] binIn = client.testBinary(binOut); Console.WriteLine(" = " + BytesToHex(binIn)); if (binIn.Length != binOut.Length) { throw new Exception("testBinary: length mismatch"); } for (int ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs) { if (binIn[ofs] != binOut[ofs]) { throw new Exception("testBinary: content mismatch at offset " + ofs.ToString()); } } } catch (Thrift.TApplicationException e) { Console.Write("testBinary(" + BytesToHex(binOut) + "): " + e.Message); } // binary equals? only with hashcode option enabled ... if (typeof(CrazyNesting).GetMethod("Equals").DeclaringType == typeof(CrazyNesting)) { CrazyNesting one = new CrazyNesting(); CrazyNesting two = new CrazyNesting(); one.String_field = "crazy"; two.String_field = "crazy"; one.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF }; two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF }; if (!one.Equals(two)) { throw new Exception("CrazyNesting.Equals failed"); } } Console.Write("testStruct({\"Zero\", 1, -3, -5})"); Xtruct o = new Xtruct(); o.String_thing = "Zero"; o.Byte_thing = (sbyte)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 = (sbyte)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 = (sbyte)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("}"); sbyte 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 Oneway(1)"); client.testOneway(1); Console.Write("Test Calltime()"); var startt = DateTime.UtcNow; for (int k = 0; k < 1000; ++k) { client.testVoid(); } Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call"); }
protected TProtocol(TTransport trans) { Trans = trans; RecursionLimit = trans.Configuration.RecursionLimit; RecursionDepth = 0; }
protected TProtocol(TTransport trans) { Trans = trans; RecursionLimit = DefaultRecursionDepth; RecursionDepth = 0; }
public TJSONProtocol(TTransport trans) : base(trans) { this.context = new TJSONProtocol.JSONBaseContext(this); this.reader = new TJSONProtocol.LookaheadReader(this); }
public TProtocol GetProtocol(TTransport trans) { return(_func(trans)); }
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)"); sbyte i8 = client.testByte((sbyte)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 = (sbyte)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 = (sbyte)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 = (sbyte)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("}"); sbyte 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 Oneway(1)"); client.testOneway(1); Console.Write("Test Calltime()"); var startt = DateTime.UtcNow; for (int k = 0; k < 1000; ++k) { client.testVoid(); } Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call"); }
protected TProtocol(TTransport trans) { this.trans = trans; this.recursionLimit = DEFAULT_RECURSION_DEPTH; this.recursionDepth = 0; }
public TCompactProtocol(TTransport trans) : base(trans) { ttypeToCompactType[(int)TType.Stop] = Types.STOP; ttypeToCompactType[(int)TType.Bool] = Types.BOOLEAN_TRUE; ttypeToCompactType[(int)TType.Byte] = Types.BYTE; ttypeToCompactType[(int)TType.I16] = Types.I16; ttypeToCompactType[(int)TType.I32] = Types.I32; ttypeToCompactType[(int)TType.I64] = Types.I64; ttypeToCompactType[(int)TType.Double] = Types.DOUBLE; ttypeToCompactType[(int)TType.String] = Types.BINARY; ttypeToCompactType[(int)TType.List] = Types.LIST; ttypeToCompactType[(int)TType.Set] = Types.SET; ttypeToCompactType[(int)TType.Map] = Types.MAP; ttypeToCompactType[(int)TType.Struct] = Types.STRUCT; }
private async Task Execute(TTransport client, CancellationToken cancellationToken) { Logger.LogTrace("Started client request processing"); var processor = ProcessorFactory.GetAsyncProcessor(client, this); TTransport inputTransport = null; TTransport outputTransport = null; TProtocol inputProtocol = null; TProtocol outputProtocol = null; object connectionContext = null; try { try { inputTransport = InputTransportFactory.GetTransport(client); outputTransport = OutputTransportFactory.GetTransport(client); inputProtocol = InputProtocolFactory.GetProtocol(inputTransport); outputProtocol = OutputProtocolFactory.GetProtocol(outputTransport); if (ServerEventHandler != null) { connectionContext = await ServerEventHandler.CreateContextAsync(inputProtocol, outputProtocol, cancellationToken); } while (!cancellationToken.IsCancellationRequested) { if (!await inputTransport.PeekAsync(cancellationToken)) { break; } if (ServerEventHandler != null) { await ServerEventHandler.ProcessContextAsync(connectionContext, inputTransport, cancellationToken); } if (!await processor.ProcessAsync(inputProtocol, outputProtocol, cancellationToken)) { break; } } } catch (TTransportException ttx) { Logger.LogTrace($"Transport exception: {ttx}"); } catch (Exception x) { Logger.LogError($"Error: {x}"); } if (ServerEventHandler != null) { await ServerEventHandler.DeleteContextAsync(connectionContext, inputProtocol, outputProtocol, cancellationToken); } } finally { //Close transports inputTransport?.Close(); outputTransport?.Close(); // disposable stuff should be disposed inputProtocol?.Dispose(); outputProtocol?.Dispose(); inputTransport?.Dispose(); outputTransport?.Dispose(); } Logger.LogTrace("Completed client request processing"); }
public ClientTest(TestParams param) { transport = param.CreateTransport(); client = new ThriftTest.Client(param.CreateProtocol(transport)); numIterations = param.numIterations; }
public override async Task ServeAsync(CancellationToken cancellationToken) { ServerCancellationToken = cancellationToken; try { try { ServerTransport.Listen(); } catch (TTransportException ttx) { LogError("Error, could not listen on ServerTransport: " + ttx); return; } //Fire the preServe server event when server is up but before any client connections if (ServerEventHandler != null) { await ServerEventHandler.PreServeAsync(cancellationToken); } while (!(stop || ServerCancellationToken.IsCancellationRequested)) { try { using (TTransport client = await ServerTransport.AcceptAsync(cancellationToken)) { await ExecuteAsync(client); } } catch (TaskCanceledException) { stop = true; } catch (TTransportException ttx) { if (!stop || ttx.Type != TTransportException.ExceptionType.Interrupted) { LogError(ttx.ToString()); } } } if (stop) { try { ServerTransport.Close(); } catch (TTransportException ttx) { LogError("TServerTransport failed on close: " + ttx.Message); } stop = false; } } finally { ServerCancellationToken = default; } }
public TBinaryProtocol(TTransport trans, bool strictRead, bool strictWrite) : base(trans) { StrictRead = strictRead; StrictWrite = strictWrite; }
public TProtocol GetProtocol(TTransport trans) { return(new TBinaryProtocol(trans, strictRead_, strictWrite_)); }
public override TProtocol GetProtocol(TTransport trans) { return(new TBinaryProtocol(trans, StrictRead, StrictWrite)); }
public TBinaryProtocol(TTransport trans, bool strictRead, bool strictWrite) : base(trans) { strictRead_ = strictRead; strictWrite_ = strictWrite; }
private void PushToPool(TTransport transport) { pool.Push(transport); idelCount++; }
public override TProtocol GetProtocol(TTransport trans) { return(new TJsonProtocol(trans)); }
public TJsonHeaderServerProtocol(TTransport transport) : base(transport) { HEAD_INFO = new Dictionary <string, string>(); }
public TProtocol GetProtocol(TTransport trans) { return(new TJSONProtocol(trans)); }
public override void Serve() { try { serverTransport.Listen(); } catch (TTransportException ttx) { logDelegate(ttx.ToString()); return; } //Fire the preServe server event when server is up but before any client connections if (serverEventHandler != null) { serverEventHandler.preServe(); } while (!stop) { TTransport client = null; TTransport inputTransport = null; TTransport outputTransport = null; TProtocol inputProtocol = null; TProtocol outputProtocol = null; Object connectionContext = null; try { using (client = serverTransport.Accept()) { if (client != null) { using (inputTransport = inputTransportFactory.GetTransport(client)) { using (outputTransport = outputTransportFactory.GetTransport(client)) { inputProtocol = inputProtocolFactory.GetProtocol(inputTransport); outputProtocol = outputProtocolFactory.GetProtocol(outputTransport); //Recover event handler (if any) and fire createContext server event when a client connects if (serverEventHandler != null) { connectionContext = serverEventHandler.createContext(inputProtocol, outputProtocol); } //Process client requests until client disconnects while (!stop) { if (!inputTransport.Peek()) { break; } //Fire processContext server event //N.B. This is the pattern implemented in C++ and the event fires provisionally. //That is to say it may be many minutes between the event firing and the client request //actually arriving or the client may hang up without ever makeing a request. if (serverEventHandler != null) { serverEventHandler.processContext(connectionContext, inputTransport); } //Process client request (blocks until transport is readable) if (!processor.Process(inputProtocol, outputProtocol)) { break; } } } } } } } catch (TTransportException ttx) { if (!stop || ttx.Type != TTransportException.ExceptionType.Interrupted) { logDelegate(ttx.ToString()); } } catch (Exception x) { //Unexpected logDelegate(x.ToString()); } //Fire deleteContext server event after client disconnects if (serverEventHandler != null) { serverEventHandler.deleteContext(connectionContext, inputProtocol, outputProtocol); } } }
public TProtocol GetProtocol(TTransport trans) { return new TBinaryProtocol(trans, strictRead_, strictWrite_); }
public SafeBinaryProtocol(TTransport trans, TSocket socket, TProtocol protocol) : base(trans) { _binaryProtocol = new TBinaryProtocol(trans); }
public TBinaryProtocol(TTransport trans, bool strictRead, bool strictWrite) :base(trans) { strictRead_ = strictRead; strictWrite_ = strictWrite; }
public SafeTransport(String host, int port) { _transport = new TBufferedTransport(new TSocket(host, port)); }
public virtual TTransport GetTransport(TTransport trans) { return trans; }
public TProtocol GetProtocol(TTransport trans) { return(new TCompactProtocol(trans)); }
public TProtocol GetProtocol(TTransport trans) { return new TCompactProtocol(trans); }
/// <summary> /// Builds a DataReader that accesses data from a stream. This uses the provided stream directly. /// </summary> /// <param name="inPipeStream">The stream to use</param> public DataReader(Stream inPipeStream) { _inPipe = new TStreamTransport(inPipeStream, null); _inProto = new TBinaryProtocol(_inPipe); }
/// <summary> /// Loops on processing a client forever /// client will be a TTransport instance /// </summary> /// <param name="client"></param> private async Task ExecuteAsync(TTransport client) { var cancellationToken = ServerCancellationToken; var processor = ProcessorFactory.GetAsyncProcessor(client, this); TTransport inputTransport = null; TTransport outputTransport = null; TProtocol inputProtocol = null; TProtocol outputProtocol = null; object connectionContext = null; try { try { inputTransport = InputTransportFactory.GetTransport(client); outputTransport = OutputTransportFactory.GetTransport(client); inputProtocol = InputProtocolFactory.GetProtocol(inputTransport); outputProtocol = OutputProtocolFactory.GetProtocol(outputTransport); //Recover event handler (if any) and fire createContext server event when a client connects if (ServerEventHandler != null) { connectionContext = await ServerEventHandler.CreateContextAsync(inputProtocol, outputProtocol, cancellationToken); } //Process client requests until client disconnects while (!(stop || cancellationToken.IsCancellationRequested)) { if (!await inputTransport.PeekAsync(cancellationToken)) { break; } //Fire processContext server event //N.B. This is the pattern implemented in C++ and the event fires provisionally. //That is to say it may be many minutes between the event firing and the client request //actually arriving or the client may hang up without ever makeing a request. if (ServerEventHandler != null) { await ServerEventHandler.ProcessContextAsync(connectionContext, inputTransport, cancellationToken); } //Process client request (blocks until transport is readable) if (!await processor.ProcessAsync(inputProtocol, outputProtocol, cancellationToken)) { break; } } } catch (TTransportException) { //Usually a client disconnect, expected } catch (Exception x) { //Unexpected LogError("Error: " + x); } //Fire deleteContext server event after client disconnects if (ServerEventHandler != null) { await ServerEventHandler.DeleteContextAsync(connectionContext, inputProtocol, outputProtocol, cancellationToken); } } finally { //Close transports inputTransport?.Close(); outputTransport?.Close(); // disposable stuff should be disposed inputProtocol?.Dispose(); outputProtocol?.Dispose(); inputTransport?.Dispose(); outputTransport?.Dispose(); } }
public TProtocol GetProtocol(TTransport trans) { return new TJSONProtocol(trans); }
public override TTransport GetTransport(TTransport trans) { return new TFramedTransport(trans); }