Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
                myServerId = args[0];
                Console.WriteLine($"ServerId: {myServerId}");
                string[] protocolAndHostnameAndPort = args[1].Split("://");
                string[] hotnameAndPort             = protocolAndHostnameAndPort[1].Split(":");
                int      port     = int.Parse(hotnameAndPort[1]);
                int      minDelay = int.Parse(args[2]);
                int      maxDelay = int.Parse(args[3]);

                ConnectionManager connectionManager = CreateServerConnectionManager(args[4]);
                GStore            gStore            = new GStore(connectionManager);
                connectionManager.AddGStore(gStore);
                Console.WriteLine(connectionManager);

                ManualResetEventSlim freezeLock         = new ManualResetEventSlim(true);
                RequestInterceptor   requestInterceptor = new RequestInterceptor(freezeLock, minDelay, maxDelay);

                Grpc.Core.Server server = new Grpc.Core.Server
                {
                    Services =
                    {
                        GStoreService.BindService(new ServerServiceImpl(gStore)).Intercept(requestInterceptor),
                        MasterReplicaService.BindService(new MasterReplicaServiceImpl(gStore)).Intercept(requestInterceptor),
                        PuppetMasterServerService.BindService(new PuppetMasterServerServiceImpl(freezeLock, connectionManager))
                    },
                    Ports = { new ServerPort(hotnameAndPort[0], port, ServerCredentials.Insecure) }
                };

                server.Start();
                Console.WriteLine("GStore server listening on port " + port);
                Console.WriteLine("Press any key to stop the server...");

                PressToExit();
                Console.WriteLine("\nShutting down...");
                server.ShutdownAsync().Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                PressToExit();
            }
        }