コード例 #1
0
        public static TService ProxyFor <TService>(this RpcActor localActor, string service)
        {
            var remoteService = RpcServiceProxyGenerator.CreateServiceProxy <TService>(localActor, service);

            localActor.RegisterRpcService(remoteService as RpcService);
            return(remoteService);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: anbgsl1110/Redola
        static void Main(string[] args)
        {
            var localXmlFilePath = Environment.CurrentDirectory + @"\\XmlConfiguration\\ActorConfiguration.xml";
            var localXmlFileActorConfiguration = LocalXmlFileActorConfiguration.Load(localXmlFilePath);
            var localXmlFileActorDirectory     = new LocalXmlFileActorDirectory(localXmlFileActorConfiguration);

            var localActor = new RpcActor(localXmlFileActorConfiguration);

            var helloClient = RpcServiceProxyGenerator.CreateServiceProxy <IHelloService>(localActor, "server");
            var calcClient  = RpcServiceProxyGenerator.CreateServiceProxy <ICalcService>(localActor, "server");

            localActor.RegisterRpcService(helloClient as RpcService);
            localActor.RegisterRpcService(calcClient as RpcService);

            localActor.Bootup(localXmlFileActorDirectory);

            var container = new TestContainer();

            container.AddModule(new TestModule(helloClient, calcClient));

            var bootstrapper = new Bootstrapper();
            var engine       = bootstrapper.BootWith(container);

            string uri  = "http://localhost:3202/";
            var    host = new SelfHost(engine, new Uri(uri));

            host.Start();
            Console.WriteLine("Server is listening on [{0}].", uri);

            Console.WriteLine("Type something to stop ...");
            Console.ReadKey();

            host.Stop();
            Console.WriteLine("Stopped. Goodbye!");
        }
コード例 #3
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

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

            var localActor = new RpcActor();

            var helloClient = RpcServiceProxyGenerator.CreateServiceProxy <IHelloService>(localActor, "server");
            var calcClient  = RpcServiceProxyGenerator.CreateServiceProxy <ICalcService>(localActor, "server");
            var orderClient = RpcServiceProxyGenerator.CreateServiceProxy <IOrderService>(localActor, "server");

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

            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(log, 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(log, 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(log, 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(log, 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(log, calcClient, totalCalls, threadCount);
                    }
                    else
                    {
                        log.WarnFormat("Cannot parse the operation for input [{0}].", text);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                }
            }

            localActor.Shutdown();
        }