示例#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
        public TcpWriter(ActorId id, ActorsSystem system, IMailBox mailBox) : base(id, system, mailBox)
        {
            var serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3000);

            _client = new TcpClient();
            _client.Connect(serverEndPoint);
            _clientStream = _client.GetStream();
        }
示例#3
0
        public void should_send_message_to_the_actor_via_system_in_memory()
        {
            var testActorId = ActorId.GenerateNew();
            var testActor   = new MyTestActor(testActorId);

            using (var system = ActorsSystem.WithoutQueues(null, testActor))
            {
                var messageToSend = new MyTestMessage1(destinationId: testActorId);
                system.Send(messageToSend);

                Check.That(testActor.HandledMessages).Contains(messageToSend);
            }
        }
示例#4
0
        public void should_send_message_to_the_actor_via_system_with_queues()
        {
            var testActorId = ActorId.GenerateNew();
            var testActor   = new MyTestActor(testActorId);

            using (var system = ActorsSystem.WithQueues(null, testActor))
            {
                var messageToSend = new MyTestMessage1(destinationId: testActorId);
                system.Send(messageToSend);

                Thread.Sleep(500); //that's because of queues usage. use in memory system to avoid dependency from time
                Check.That(testActor.HandledMessages).Contains(messageToSend);
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            using (var system = new ActorsSystem())
            {
                var trader = QueuedActor.Of(new StopLossTrader(Addresses.TraderAddress, system));
                system.SubscribeByAddress(trader);

                var orderProcessor = QueuedActor.Of(new OrderProcessor(Addresses.OrderProcessorAddress, system));
                system.SubscribeByAddress(orderProcessor);

                var market = QueuedActor.Of(new Market(ActorId.GenerateNew(), system));
                system.SubscribeByAddress(market);

                Console.WriteLine("Press any key to stop");
                Console.ReadLine();
            }
        }
示例#6
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));
            }
        }
示例#7
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);
            }
        }
示例#8
0
 public StopLossTrader(ActorId id, ActorsSystem system) : base(id, system)
 {
 }
示例#9
0
 public ClientConnectionWorker(ActorsSystem system, IMailBox mailBox)
     : base(ActorId.GenerateNew(), system, mailBox)
 {
 }
示例#10
0
 public OrderProcessor(ActorId id, ActorsSystem system) : base(id, system)
 {
 }
示例#11
0
 public Market(ActorId id, ActorsSystem system) : base(id, system)
 {
     _timeIntervalRandomizer = new Random();
     _pricesRandomizer       = new Random();
     GenerateNewPrices();
 }
示例#12
0
 public Generator(ActorId id, ActorsSystem system) : base(id, system)
 {
 }
示例#13
0
 public ConnectionListener(ActorId id, ActorsSystem system) : base(id, system)
 {
 }