Example #1
0
 public AsyncBaseServer(ITProcessorFactory itProcessorFactory, TServerTransport serverTransport,
     TTransportFactory inputTransportFactory, TTransportFactory outputTransportFactory,
     ITProtocolFactory inputProtocolFactory, ITProtocolFactory outputProtocolFactory,
     ILogger logger, int clientWaitingDelay = 10)
     : base(itProcessorFactory, serverTransport, inputTransportFactory, outputTransportFactory,
         inputProtocolFactory, outputProtocolFactory, logger)
 {
     _clientWaitingDelay = clientWaitingDelay;
 }
Example #2
0
        protected TBaseServer(ITProcessorFactory itProcessorFactory, TServerTransport serverTransport,
            TTransportFactory inputTransportFactory, TTransportFactory outputTransportFactory,
            ITProtocolFactory inputProtocolFactory, ITProtocolFactory outputProtocolFactory,
            ILogger logger)
        {
            if (itProcessorFactory == null) throw new ArgumentNullException(nameof(itProcessorFactory));
            if (inputTransportFactory == null) throw new ArgumentNullException(nameof(inputTransportFactory));
            if (outputTransportFactory == null) throw new ArgumentNullException(nameof(outputTransportFactory));
            if (inputProtocolFactory == null) throw new ArgumentNullException(nameof(inputProtocolFactory));
            if (outputProtocolFactory == null) throw new ArgumentNullException(nameof(outputProtocolFactory));
            if (logger == null) throw new ArgumentNullException(nameof(logger));

            ItProcessorFactory = itProcessorFactory;
            ServerTransport = serverTransport;
            InputTransportFactory = inputTransportFactory;
            OutputTransportFactory = outputTransportFactory;
            InputProtocolFactory = inputProtocolFactory;
            OutputProtocolFactory = outputProtocolFactory;
            Logger = logger;
        }
Example #3
0
        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.Tls12);
                    }
                    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;
        }