コード例 #1
0
 public ThrottlingHandler(QueuedHandler <T> handler)
 {
     this.handler = handler;
 }
コード例 #2
0
        public static void Main(string[] args)
        {
            var dispatcher = new Dispatcher();

            var cooks = new[]
            {
                new QueuedHandler <Messages.PrepareFood>(
                    new Chef(dispatcher, "Joe Bastianich", 1)),
                new QueuedHandler <Messages.PrepareFood>(
                    new Chef(dispatcher, "Gordon Ramsay", 3)),
                new QueuedHandler <Messages.PrepareFood>(
                    new KitchenNightmare(new Chef(dispatcher, "Amy's Baking Company", .5)))
            };
            var kitchenQueue = new QueuedHandler <Messages.PrepareFood>(
                new TimeToLiveHandler <Messages.PrepareFood>(
                    new ShortestQueueDispatcher <Messages.PrepareFood>(cooks)));

            kitchenQueue.Start();

            var kitchen = new ThrottlingHandler <Messages.PrepareFood>(kitchenQueue);

            var assistantManager = new AssistantManager(dispatcher);

            var cashier = new Cashier(dispatcher);

            var reporting = new EnterpriseExcel();


            var alarmClock = new AlarmClock(dispatcher);

            alarmClock.Start();

            var storage = new RestaurantProcessStorage(kitchen, assistantManager, cashier, reporting, alarmClock);
            var waiter  = new Waiter("July M.", dispatcher);


            dispatcher.Subscribe(Log <Messages.OrderPlaced>(dispatcher));
            dispatcher.Subscribe(Log <Messages.SuspectOrderPlaced>(dispatcher));

            dispatcher.Subscribe <Messages.OrderPlaced>(storage);
            dispatcher.Subscribe <Messages.SuspectOrderPlaced>(storage);
            dispatcher.Subscribe <Messages.PrepareFood>(storage);
            dispatcher.Subscribe <Messages.FoodPrepared>(storage);
            dispatcher.Subscribe <Messages.TotalOrder>(storage);
            dispatcher.Subscribe <Messages.OrderTotalled>(storage);
            dispatcher.Subscribe <Messages.OrderPaid>(storage);
            dispatcher.Subscribe <Messages.ProcessCompleted>(storage);
            dispatcher.Subscribe <Messages.Timeout <Message> >(alarmClock);

            new Thread(
                _ => PayLoop(cashier)).Start();

            cooks.ForEach(x => x.Start());
            var plates = new[] { "Pizza", "Chicharron", "Miguitas" };

            for (var i = 0; i < 100000; i++)
            {
                waiter.PlaceOrder(i, 1, new Order.Item(plates[i % 3], 1));
            }

            Console.ReadLine();
        }