public Task StartAsync(CancellationToken cancellationToken) { TServerTransport serverTransport = new TServerSocketTransport(Configuration.GetValue <int>("RpcPort")); TBinaryProtocol.Factory factory1 = new TBinaryProtocol.Factory(); TBinaryProtocol.Factory factory2 = new TBinaryProtocol.Factory(); TBaseServer server = new AsyncBaseServer(Processor, serverTransport, factory1, factory2, LoggerFactory); return(server.ServeAsync(cancellationToken)); }
public static void Run(CancellationToken cancellationToken, LoggerFactory loggerFactory) { TServerTransport serverTransport = new TServerSocketTransport(8005); ITProtocolFactory inputProtocolFactory = new TCompactProtocol.Factory(); ITProtocolFactory outputProtocolFactory = new TCompactProtocol.Factory(); var processor = new IHelloWorldService.AsyncProcessor(new HelloWorldService()); var server = new AsyncBaseServer(processor, serverTransport, inputProtocolFactory, outputProtocolFactory, loggerFactory); server.ServeAsync(cancellationToken); }
public static async Task RunAsync(IAsync processor, int port, ILoggerFactory loggerFactory) { using (var source = new CancellationTokenSource()) { var server = new AsyncBaseServer( new AsyncProcessor(processor), new TServerSocketTransport(port), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), loggerFactory ); await server.ServeAsync(source.Token); } }
static async Task RunNotificationServiceAsync() { var fabric = new LoggerFactory().AddConsole(LogLevel.Trace); var handler = new NotificationHandler(); ITAsyncProcessor processor = null; TServerTransport serverTransport = null; serverTransport = new TServerSocketTransport(9090); ITProtocolFactory inputProtocolFactory; ITProtocolFactory outputProtocolFactory; inputProtocolFactory = new TBinaryProtocol.Factory(); outputProtocolFactory = new TBinaryProtocol.Factory(); processor = new NotificationService.AsyncProcessor(handler); var server = new AsyncBaseServer(processor, serverTransport, inputProtocolFactory, outputProtocolFactory, fabric); await server.ServeAsync(new CancellationToken()); }
private static async Task RunSelectedConfigurationAsync(Transport transport, Protocol protocol, CancellationToken cancellationToken) { var fabric = new LoggerFactory().AddConsole(LogLevel.Trace).AddDebug(LogLevel.Trace); var handler = new ThriftService(); ITAsyncProcessor processor = null; TServerTransport serverTransport = null; switch (transport) { case Transport.Tcp: serverTransport = new TServerSocketTransport(9090); break; case Transport.TcpBuffered: serverTransport = new TServerSocketTransport(9090, 10000, true); break; case Transport.NamedPipe: serverTransport = new TNamedPipeServerTransport(".test"); break; case Transport.TcpTls: serverTransport = new TTlsServerSocketTransport(9090, false, GetCertificate(), ClientCertValidator, LocalCertificateSelectionCallback); break; case Transport.Framed: serverTransport = new TServerFramedTransport(9090); break; } ITProtocolFactory inputProtocolFactory; ITProtocolFactory outputProtocolFactory; switch (protocol) { case Protocol.Binary: inputProtocolFactory = new TBinaryProtocol.Factory(); outputProtocolFactory = new TBinaryProtocol.Factory(); processor = new Calculator.AsyncProcessor(handler); break; case Protocol.Compact: inputProtocolFactory = new TCompactProtocol.Factory(); outputProtocolFactory = new TCompactProtocol.Factory(); processor = new Calculator.AsyncProcessor(handler); break; case Protocol.Json: inputProtocolFactory = new TJsonProtocol.Factory(); outputProtocolFactory = new TJsonProtocol.Factory(); processor = new Calculator.AsyncProcessor(handler); break; case Protocol.Multiplexed: inputProtocolFactory = new TBinaryProtocol.Factory(); outputProtocolFactory = new TBinaryProtocol.Factory(); var calcHandler = new ThriftService(); var calcProcessor = new Calculator.AsyncProcessor(calcHandler); var calcHandlerShared = new SharedServiceAsyncHandler(); var calcProcessorShared = new SharedService.AsyncProcessor(calcHandlerShared); var multiplexedProcessor = new TMultiplexedProcessor(); multiplexedProcessor.RegisterProcessor(nameof(Calculator), calcProcessor); multiplexedProcessor.RegisterProcessor(nameof(SharedService), calcProcessorShared); processor = multiplexedProcessor; break; default: throw new ArgumentOutOfRangeException(nameof(protocol), protocol, null); } try { Logger.LogInformation( $"Selected TAsyncServer with {serverTransport} transport, {processor} processor and {inputProtocolFactory} protocol factories"); var server = new AsyncBaseServer(processor, serverTransport, inputProtocolFactory, outputProtocolFactory, fabric); Logger.LogInformation("Starting the server ..."); await server.ServeAsync(cancellationToken); } catch (Exception ex) { Logger.LogInformation(ex, ex.Message); } }
private static async Task RunSelectedConfigurationAsync(Transport transport, Protocol protocol, CancellationToken cancellationToken) { var fabric = new LoggerFactory(); var handler = new CalculatorAsyncHandler(); var processor = new Calculator.AsyncProcessor(handler); TServerTransport serverTransport = null; switch (transport) { case Transport.Tcp: serverTransport = new TServerSocketTransport(9090); break; case Transport.TcpBuffered: serverTransport = new TServerSocketTransport(port: 9090, clientTimeout: 10000, useBufferedSockets: true); break; case Transport.NamedPipe: serverTransport = new TNamedPipeServerTransport(".test"); break; case Transport.TcpTls: serverTransport = new TTlsServerSocketTransport(9090, false, GetCertificate(), ClientCertValidator, LocalCertificateSelectionCallback); break; } ITProtocolFactory inputProtocolFactory; ITProtocolFactory outputProtocolFactory; switch (protocol) { case Protocol.Binary: { inputProtocolFactory = new TBinaryProtocol.Factory(); outputProtocolFactory = new TBinaryProtocol.Factory(); } break; case Protocol.Compact: { inputProtocolFactory = new TCompactProtocol.Factory(); outputProtocolFactory = new TCompactProtocol.Factory(); } break; case Protocol.Json: { inputProtocolFactory = new TJsonProtocol.Factory(); outputProtocolFactory = new TJsonProtocol.Factory(); } break; default: throw new ArgumentOutOfRangeException(nameof(protocol), protocol, null); } try { Logger.LogInformation( $"Selected TAsyncServer with {serverTransport} transport and {inputProtocolFactory} protocol factories"); var server = new AsyncBaseServer(processor, serverTransport, inputProtocolFactory, outputProtocolFactory, fabric); Logger.LogInformation("Starting the server..."); await server.ServeAsync(cancellationToken); } catch (Exception x) { Logger.LogInformation(x.ToString()); } Logger.LogInformation("Server stopped."); }
public static int Execute(List <string> args) { var logger = new LoggerFactory().CreateLogger("Test"); try { var param = new ServerParam(); try { param.Parse(args); } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); Console.WriteLine("Error while parsing arguments"); Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); return(1); } // Transport TServerTransport trans; if (param.pipe != null) { trans = new TNamedPipeServerTransport(param.pipe); } else { if (param.useEncryption) { var certPath = "../../keys/server.p12"; trans = new TTlsServerSocketTransport(param.port, param.useBufferedSockets, new X509Certificate2(certPath, "thrift"), null, null, SslProtocols.Tls); } else { trans = new TServerSocketTransport(param.port, 0, param.useBufferedSockets); } } ITProtocolFactory proto; if (param.compact) { proto = new TCompactProtocol.Factory(); } else if (param.json) { proto = new TJsonProtocol.Factory(); } else { proto = new TBinaryProtocol.Factory(); } ITProcessorFactory processorFactory; // Processor var testHandler = new TestHandlerAsync(); var testProcessor = new ThriftAsync.Test.ThriftTest.AsyncProcessor(testHandler); processorFactory = new SingletonTProcessorFactory(testProcessor); TTransportFactory transFactory; if (param.useFramed) { throw new NotImplementedException("framed"); // transFactory = new TFramedTransport.Factory(); } else { transFactory = new TTransportFactory(); } TBaseServer serverEngine = new AsyncBaseServer(processorFactory, trans, transFactory, transFactory, proto, proto, logger); //Server event handler var serverEvents = new MyServerEventHandler(); serverEngine.SetEventHandler(serverEvents); // Run it var where = (!string.IsNullOrEmpty(param.pipe)) ? "on pipe " + param.pipe : "on port " + param.port; Console.WriteLine("Starting the AsyncBaseServer " + where + " with processor TPrototypeProcessorFactory prototype factory " + (param.useBufferedSockets ? " with buffered socket" : "") + (param.useFramed ? " with framed transport" : "") + (param.useEncryption ? " with encryption" : "") + (param.compact ? " with compact protocol" : "") + (param.json ? " with json protocol" : "") + "..."); serverEngine.ServeAsync(CancellationToken.None).GetAwaiter().GetResult(); Console.ReadLine(); } catch (Exception x) { Console.Error.Write(x); return(1); } Console.WriteLine("done."); return(0); }
public static int Execute(List <string> args) { var loggerFactory = new LoggerFactory();//.AddConsole().AddDebug(); var logger = new LoggerFactory().CreateLogger("Test"); try { var param = new ServerParam(); try { param.Parse(args); } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); Console.WriteLine("Error while parsing arguments"); Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); return(1); } // Transport TServerTransport trans; if (param.pipe != null) { trans = new TNamedPipeServerTransport(param.pipe); } // else if (param.useFramed) // { // trans = new TServerFramedTransport(param.port); // } else { if (param.useEncryption) { var cert = GetServerCert(); if (cert == null || !cert.HasPrivateKey) { throw new InvalidOperationException("Certificate doesn't contain private key"); } trans = new TTlsServerSocketTransport(param.port, param.useBufferedSockets, param.useFramed, cert, (sender, certificate, chain, errors) => true, null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12); } else { trans = new TServerSocketTransport(param.port, 0, param.useBufferedSockets, param.useFramed); } } ITProtocolFactory proto; if (param.compact) { proto = new TCompactProtocol.Factory(); } else if (param.json) { proto = new TJsonProtocol.Factory(); } else { proto = new TBinaryProtocol.Factory(); } ITProcessorFactory processorFactory; // Processor var testHandler = new TestHandlerAsync(); var testProcessor = new ThriftTest.AsyncProcessor(testHandler); processorFactory = new SingletonTProcessorFactory(testProcessor); TTransportFactory transFactory = new TTransportFactory(); TBaseServer serverEngine = new AsyncBaseServer(processorFactory, trans, transFactory, transFactory, proto, proto, logger); //Server event handler var serverEvents = new MyServerEventHandler(); serverEngine.SetEventHandler(serverEvents); // Run it var where = (!string.IsNullOrEmpty(param.pipe)) ? "on pipe " + param.pipe : "on port " + param.port; Console.WriteLine("Starting the AsyncBaseServer " + where + " with processor TPrototypeProcessorFactory prototype factory " + (param.useBufferedSockets ? " with buffered socket" : "") + (param.useFramed ? " with framed transport" : "") + (param.useEncryption ? " with encryption" : "") + (param.compact ? " with compact protocol" : "") + (param.json ? " with json protocol" : "") + "..."); serverEngine.ServeAsync(CancellationToken.None).GetAwaiter().GetResult(); Console.ReadLine(); } catch (Exception x) { Console.Error.Write(x); return(1); } Console.WriteLine("done."); return(0); }