Пример #1
0
        static void Main()
        {
            Console.WriteLine("Starting server...");

            using (var system = new ActorsSystem())
                using (StatsService.Run(system.Monitor))
                {
                    var listener = QueuedActor.Of(new ConnectionListener(Addresses.Listener, system));
                    system.SubscribeByAddress(listener);

                    var connectionWorkers = QueuedActor.Of(mailbox1 => new RoundRobinActor(
                                                               id: Addresses.ConnectionWorkers,
                                                               workerFactory: () => QueuedActor.Of(mailbox2 => new ClientConnectionWorker(system, mailbox2), system.Monitor),
                                                               degreeOfParallelism: 2, system: system, mailBox: mailbox1));
                    system.SubscribeByAddress(connectionWorkers);
                    system.Monitor.MonitorActor(connectionWorkers);

                    system.Send(new StartListening());

                    Console.WriteLine("Server started");
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadLine();
                }

            Console.WriteLine("Finished");
        }
Пример #2
0
        private static void Main(string[] args)
        {
            Console.ReadLine();

            using (var system = new ActorsSystem())
            {
                var generator = new Generator(ActorId.GenerateNew(), system);
                system.SubscribeByAddress(generator);

                var connectionWorkers = QueuedActor.Of(mailbox1 => new RoundRobinActor(
                                                           id: Addresses.TcpWritersDispatcher,
                                                           workerFactory:
                                                           () => QueuedActor.Of(mailbox2 => new TcpWriter(ActorId.GenerateNew(), system, mailbox2), system.Monitor),
                                                           degreeOfParallelism: 5,
                                                           system: system,
                                                           mailBox: mailbox1));

                system.SubscribeByAddress(connectionWorkers);
                system.Monitor.MonitorActor(connectionWorkers);

                var diskWriter       = new DiskWriter(Addresses.DiskWriter);
                var queuedDiskWriter = QueuedActor.Of(diskWriter);
                system.SubscribeByAddress(queuedDiskWriter);
                system.Monitor.MonitorActor(queuedDiskWriter);


                var stopwatch = new Stopwatch();
                stopwatch.Start();
                system.Send(new GenerateNextMessage(generator.Id));

                Console.WriteLine("Stresser running");
                //Console.WriteLine("Press any key to stop...");
                //Console.ReadLine();

                diskWriter.AllJobDone.Wait();
                stopwatch.Stop();
                Console.WriteLine("Speed: {0} msg/sec", ((float)diskWriter.TotalMessagesProcessed) / stopwatch.ElapsedMilliseconds * 1000);
            }
        }
Пример #3
0
        public void when_prices_start_going_below_threshold_trader_sells_position()
        {
            var schedulerMock = new SchedulerMock();

            using (var system = new ActorsSystem(schedulerMock))
            {
                var trader = new StopLossTrader(ActorId.GenerateNew(), system);
                system.SubscribeByAddress(trader);

                system.Send(new PriceChanged(trader.Id, 100m, Guid.Parse("00000000-0000-0000-0000-000000000001")));
                system.Send(new PriceChanged(trader.Id, 110m, Guid.Parse("00000000-0000-0000-0000-000000000002")));
                system.Send(new RemoveFrom15(trader.Id, Guid.Parse("00000000-0000-0000-0000-000000000001")));

                system.Send(new PriceChanged(trader.Id, 90m, Guid.Parse("00000000-0000-0000-0000-000000000003")));
                system.Send(new RemoveFrom30(trader.Id, Guid.Parse("00000000-0000-0000-0000-000000000001")));
                system.Send(new RemoveFrom15(trader.Id, Guid.Parse("00000000-0000-0000-0000-000000000001")));
                system.Send(new RemoveFrom30(trader.Id, Guid.Parse("00000000-0000-0000-0000-000000000002")));

                Check.That(system.DeadSink).Contains(new Sell(Addresses.OrderProcessorAddress, trader.Id.Value, 90m));
            }
        }