Example #1
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            ILog log = Logger.Get <Program>();

            var localActor = new RpcActor();

            var helloService = new HelloService(localActor, new CountableRateLimiter());
            var calcService  = new CalcService(localActor, new CountableRateLimiter());
            var orderService = new OrderService(localActor, new CountableRateLimiter());

            localActor.RegisterRpcService(helloService);
            localActor.RegisterRpcService(calcService);
            localActor.RegisterRpcService(orderService);

            localActor.Bootup();

            while (true)
            {
                try
                {
                    string text = Console.ReadLine().ToLowerInvariant();
                    if (text == "quit" || text == "exit")
                    {
                        break;
                    }
                    else if (text == "reconnect")
                    {
                        localActor.Shutdown();
                        localActor.Bootup();
                    }
                    else if (Regex.Match(text, @"^notify(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"notify(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            NotifyOrderChanged(log, orderService);
                        }
                    }
                    else
                    {
                        log.WarnFormat("Cannot parse the operation for input [{0}].", text);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                }
            }

            localActor.Shutdown();
        }
Example #2
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            ILog log = Logger.Get <Program>();

            var actor = new RpcActor();

            var rateLimiter = new CountableRateLimiter();

            var helloService = new HelloService(actor, rateLimiter);
            var calcService  = new CalcService(actor);
            var orderService = new OrderService(actor, rateLimiter);

            actor.RegisterRpcService(helloService);
            actor.RegisterRpcService(calcService);
            actor.RegisterRpcService(orderService);

            actor.Bootup();

            while (true)
            {
                try
                {
                    string text = Console.ReadLine().ToLowerInvariant();
                    if (text == "quit" || text == "exit")
                    {
                        break;
                    }
                    else
                    {
                        int times = 0;
                        if (int.TryParse(text, out times))
                        {
                            for (int i = 0; i < times; i++)
                            {
                                NotifyOrderChanged(log, orderService);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                }
            }

            actor.Shutdown();
        }