コード例 #1
0
        public static void Main()
        {
            var pubsub = new TopicBasedPubSub();

            var alarmClock = new AlarmClock <RetryCooking>(pubsub);

            pubsub.SubscribeByMessage(alarmClock);
            var waiter = new Waiter(pubsub);

            var cook1   = QueuedHandler.Create(new Cook("Tom", pubsub, Random.Next(0, 1000)), "Cook #1");
            var cook2   = QueuedHandler.Create(new Cook("Jones", pubsub, Random.Next(0, 1000)), "Cook #2");
            var cook3   = QueuedHandler.Create(new Cook("Huck", pubsub, Random.Next(0, 1000)), "Cook #3");
            var kitchen = QueuedHandler.Create(MoreFareDispatcher.Create(cook1, cook2, cook3).WrapWithDropper(), "Kitchen");

            pubsub.SubscribeByMessage(kitchen);

            var manager = QueuedHandler.Create(new Manager(pubsub), "Manager #1");

            pubsub.SubscribeByMessage(manager);

            var cashier = QueuedHandler.Create(new Cashier(pubsub), "Cashier #1");

            pubsub.SubscribeByMessage(cashier);

            var midgetHouse = QueuedHandler.Create(new MidgetHouse(pubsub), "Midgets");

            pubsub.SubscribeByMessage(midgetHouse);

            var printer = new PrintingOrderHandler();
            //pubsub.SubscribeByMessage<OrderPaid>(printer);
            //pubsub.SubscribeByMessage<OrderCooked>(printer);
            //pubsub.SubscribeByMessage<OrderPlaced>(printer);
            //pubsub.SubscribeByMessage<OrderPriced>(printer);

            var startables = new IStartable[] { midgetHouse, kitchen, cook1, cook2, cook3, cashier, manager, alarmClock };
            var queues     = new IQueue[] { midgetHouse, kitchen, cook1, cook2, cook3, cashier, manager };

            foreach (var startable in startables)
            {
                startable.Start();
            }

            StartMonitoring(queues);
            TakeOrders(waiter);
        }
コード例 #2
0
 public MidgetHouse(TopicBasedPubSub pubsub)
 {
     _pubsub = pubsub;
 }