internal static void Run() { Console.Title = Environment.MachineName + "-" + handler.GetID(); ReadinessHttpServer.Start(PizzaConfig.ReadinessPorts.PizzaBaker); while (true) { try { Thread.Sleep(100); using (var client = new ThriftClients.PizzeriaCallbackClient(PizzaConfig.Hosts.Pizzeria, PizzaConfig.Ports.Pizzeria)) { ReadinessHttpServer.Status = Readiness.AliveAndReady; while (handler.MakeOnePizza(client)) { /* one more! */; } } } catch (Exception e) { Console.WriteLine(e.Message); Thread.Sleep(1000); // no connection? be patient! } } }
static internal void Run(int port) { // check whether the port is free TServerTransport serverTransport = new TServerSocket(port); serverTransport.Listen(); serverTransport.Close(); serverTransport = new TServerSocket(port); // one processor to rule them all var multiplexProcessor = new TMultiplexedProcessor(); // create protocol factory, default to "framed binary" TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(true, true); TTransportFactory transportFactory = new TFramedTransport.Factory(); // create handler/processor for the public service Handler handler = new Handler(); Pizzeria.Processor pizzeria = new Pizzeria.Processor(handler); multiplexProcessor.RegisterProcessor(typeof(Pizzeria).Name, pizzeria); // create handler/processor for the internal service // handler = same PizzeriaCallback.Processor callback = new PizzeriaCallback.Processor(handler); multiplexProcessor.RegisterProcessor(typeof(PizzeriaCallback).Name, callback); // create handler/processor for the diagnostics service // handler = same Diagnostics.Diagnostics.Processor diagnose = new Diagnostics.Diagnostics.Processor(handler); multiplexProcessor.RegisterProcessor(typeof(Diagnostics.Diagnostics).Name, diagnose); // more processors as needed ... // complete internal setup Console.Title = Environment.MachineName + "-" + port.ToString(); ReadinessHttpServer.Start(PizzaConfig.ReadinessPorts.Pizzeria); try { // return the server instance //var server = new TThreadPoolServer(multiplexProcessor, serverTransport, transportFactory, protocolFactory); var server = new TThreadedServer(multiplexProcessor, serverTransport, transportFactory, protocolFactory); //var server = new TSimpleServer(multiplexProcessor, serverTransport, transportFactory, protocolFactory); ReadinessHttpServer.Status = Readiness.AliveAndReady; server.Serve(); } finally { ReadinessHttpServer.Stop(); } }