コード例 #1
0
        private static void PlaceOrder(ILog log, OrderClient orderClient)
        {
            var request = new ActorMessageEnvelope <PlaceOrderRequest>()
            {
                Message = new PlaceOrderRequest()
                {
                    Contract = new Order()
                    {
                        OrderID  = Guid.NewGuid().ToString(),
                        ItemID   = "Apple",
                        BuyCount = 100,
                    },
                },
            };

            log.DebugFormat("PlaceOrder, send place order request to server with MessageID[{0}].",
                            request.MessageID);

            var response = orderClient.PlaceOrder(request);

            log.DebugFormat("PlaceOrder, receive place order response from server with MessageID[{0}] and CorrelationID[{1}].",
                            response.MessageID, response.CorrelationID);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: anbgsl1110/Redola
        static void Main(string[] args)
        {
            var localActor = new RpcActor();

            var helloClient = new HelloClient(localActor);
            var calcClient  = new CalcClient(localActor);
            var orderClient = new OrderClient(localActor);

            localActor.RegisterRpcService(helloClient);
            localActor.RegisterRpcService(calcClient);
            localActor.RegisterRpcService(orderClient);

            localActor.Bootup();

            while (true)
            {
                try
                {
                    string text = Console.ReadLine().ToLowerInvariant().Trim();
                    if (text == "quit" || text == "exit")
                    {
                        break;
                    }
                    else if (text == "reconnect")
                    {
                        localActor.Shutdown();
                        localActor.Bootup();
                    }
                    else if (Regex.Match(text, @"^hello(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"^hello(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            Hello(helloClient);
                        }
                    }
                    else if (Regex.Match(text, @"^add(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"^add(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            Add(calcClient);
                        }
                    }
                    else if (Regex.Match(text, @"^order(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"order(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            PlaceOrder(orderClient);
                        }
                    }
                    else if (Regex.Match(text, @"^hello(\d+)x(\d+)$").Success)
                    {
                        var match       = Regex.Match(text, @"^hello(\d+)x(\d+)$");
                        int totalCalls  = int.Parse(match.Groups[1].Value);
                        int threadCount = int.Parse(match.Groups[2].Value);
                        Hello10000MultiThreading(helloClient, totalCalls, threadCount);
                    }
                    else if (Regex.Match(text, @"^add(\d+)x(\d+)$").Success)
                    {
                        var match       = Regex.Match(text, @"^add(\d+)x(\d+)$");
                        int totalCalls  = int.Parse(match.Groups[1].Value);
                        int threadCount = int.Parse(match.Groups[2].Value);
                        Add10000MultiThreading(calcClient, totalCalls, threadCount);
                    }
                    else
                    {
                        _log.WarnFormat("Cannot parse the operation for input [{0}].", text);
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message, ex);
                }
            }

            localActor.Shutdown();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

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

            var actor = new RpcActor();

            var helloClient = new HelloClient(actor);
            var calcClient  = new CalcClient(actor);
            var orderClient = new OrderClient(actor);

            actor.RegisterRpcService(helloClient);
            actor.RegisterRpcService(calcClient);
            actor.RegisterRpcService(orderClient);

            actor.Bootup();

            while (true)
            {
                try
                {
                    string text = Console.ReadLine().ToLowerInvariant();
                    if (text == "quit" || text == "exit")
                    {
                        break;
                    }
                    else if (text == "reconnect")
                    {
                        actor.Shutdown();
                        actor.Bootup();
                    }
                    else if (text == "hello")
                    {
                        Hello(log, helloClient);
                    }
                    else if (text == "hello10000")
                    {
                        Hello10000(log, helloClient);
                    }
                    #region hello10000
                    else if (text == "hello10000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 1);
                    }
                    else if (text == "hello10000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 2);
                    }
                    else if (text == "hello10000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 4);
                    }
                    else if (text == "hello10000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 8);
                    }
                    else if (text == "hello10000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 16);
                    }
                    else if (text == "hello10000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 32);
                    }
                    #endregion
                    #region hello20000
                    else if (text == "hello20000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 1);
                    }
                    else if (text == "hello20000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 2);
                    }
                    else if (text == "hello20000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 4);
                    }
                    else if (text == "hello20000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 8);
                    }
                    else if (text == "hello20000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 16);
                    }
                    else if (text == "hello20000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 32);
                    }
                    #endregion
                    #region hello100000
                    else if (text == "hello100000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 1);
                    }
                    else if (text == "hello100000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 2);
                    }
                    else if (text == "hello100000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 4);
                    }
                    else if (text == "hello100000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 8);
                    }
                    else if (text == "hello100000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 16);
                    }
                    else if (text == "hello100000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 32);
                    }
                    #endregion
                    #region hello300000
                    else if (text == "hello300000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 1);
                    }
                    else if (text == "hello300000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 2);
                    }
                    else if (text == "hello300000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 4);
                    }
                    else if (text == "hello300000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 8);
                    }
                    else if (text == "hello300000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 16);
                    }
                    else if (text == "hello300000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 32);
                    }
                    #endregion
                    #region hello1500000
                    else if (text == "hello1500000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 1);
                    }
                    else if (text == "hello1500000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 2);
                    }
                    else if (text == "hello1500000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 4);
                    }
                    else if (text == "hello1500000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 8);
                    }
                    else if (text == "hello1500000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 16);
                    }
                    else if (text == "hello1500000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 32);
                    }
                    #endregion
                    #region add10000
                    else if (text == "add10000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 1);
                    }
                    else if (text == "add10000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 2);
                    }
                    else if (text == "add10000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 4);
                    }
                    else if (text == "add10000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 8);
                    }
                    else if (text == "add10000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 16);
                    }
                    else if (text == "add10000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 32);
                    }
                    #endregion
                    #region add20000
                    else if (text == "add20000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 1);
                    }
                    else if (text == "add20000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 2);
                    }
                    else if (text == "add20000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 4);
                    }
                    else if (text == "add20000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 8);
                    }
                    else if (text == "add20000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 16);
                    }
                    else if (text == "add20000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 32);
                    }
                    #endregion
                    #region add100000
                    else if (text == "add100000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 1);
                    }
                    else if (text == "add100000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 2);
                    }
                    else if (text == "add100000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 4);
                    }
                    else if (text == "add100000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 8);
                    }
                    else if (text == "add100000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 16);
                    }
                    else if (text == "add100000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 32);
                    }
                    #endregion
                    #region add300000
                    else if (text == "add300000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 1);
                    }
                    else if (text == "add300000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 2);
                    }
                    else if (text == "add300000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 4);
                    }
                    else if (text == "add300000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 8);
                    }
                    else if (text == "add300000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 16);
                    }
                    else if (text == "add300000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 32);
                    }
                    #endregion
                    #region add1500000
                    else if (text == "add1500000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 1);
                    }
                    else if (text == "add1500000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 2);
                    }
                    else if (text == "add1500000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 4);
                    }
                    else if (text == "add1500000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 8);
                    }
                    else if (text == "add1500000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 16);
                    }
                    else if (text == "add1500000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 32);
                    }
                    #endregion
                    else
                    {
                        int times = 0;
                        if (int.TryParse(text, out times))
                        {
                            for (int i = 0; i < times; i++)
                            {
                                PlaceOrder(log, orderClient);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                }
            }

            actor.Shutdown();
        }