private static void Main() { var publisher = new TopicBasedPubSub(); var alarmClock = new AlarmClock(publisher); var midgetHouse = new MidgetHouse(publisher); var midgetHouseHandler = new QueuedHandler <Message>("MidgetHouse", midgetHouse); midgetHouse.QueuedHandler = midgetHouseHandler; var cashier = new Cashier(publisher); var cashierQueue = new QueuedHandler <TakePayment>("Cashier", cashier); var assistantManager = new QueuedHandler <PriceOrdered>("AssistantManager", new FuzzyHandler <PriceOrdered>(new AssistantManager(publisher), 0, 20)); var seed = new Random(DateTime.Now.Millisecond); var cook1 = new QueuedHandler <CookFood>( "BogdanQueue", new TTLHandler <CookFood>(new FuzzyHandler <CookFood>(new Cook(seed.Next(1000), publisher), 10, 10))); var cook2 = new QueuedHandler <CookFood>( "RomanQueue", new TTLHandler <CookFood>(new FuzzyHandler <CookFood>(new Cook(seed.Next(1000), publisher), 95, 50))); var cook3 = new QueuedHandler <CookFood>( "WaclawQueue", new TTLHandler <CookFood>(new FuzzyHandler <CookFood>(new Cook(seed.Next(1000), publisher), 10, 20))); var dispatcher = new QueuedHandler <CookFood>( "MFDispatcher", new TTLHandler <CookFood>( new MFDispatcher <CookFood>( new List <QueuedHandler <CookFood> > { cook1, cook2, cook3 }))); StartQueues( new List <IStartable> { assistantManager, cashierQueue, dispatcher, cook1, cook2, cook3, midgetHouseHandler, alarmClock }); StartQueuePrinter( new List <IPrintable> { assistantManager, cashierQueue, dispatcher, cook1, cook2, cook3, midgetHouseHandler }); var waiter = new Waiter(publisher); publisher.Subscribe(dispatcher); publisher.Subscribe(assistantManager); publisher.Subscribe(cashier); publisher.Subscribe(alarmClock); publisher.Subscribe <OrderPlaced>(midgetHouse); PlaceOrders(waiter); HandlePays(cashier); Console.ReadKey(); }
static void Main(string[] args) { var es = new AtomDispatcher(); es.Start("az"); // es.PostMessage(new OrderPlaced(order), "az"); QueuedHandler printOrderHandler = new QueuedHandler(new PrintOrderHandler()); IEventHandler <IEvent> cashier = new Cashier(); QueuedHandler cashierProxy = new QueuedHandler(cashier); var assistingManager = new QueuedHandler(new AssistingManager("Diana")); var cook1 = new QueuedHandler(new TimeToLiveHandler(new Cook("John"))); var cook2 = new QueuedHandler(new TimeToLiveHandler(new Cook("Peter"))); var cook3 = new QueuedHandler(new TimeToLiveHandler(new Cook("Gregory"))); var betterHandler = new QueuedHandler(new Dropper(new TimeToLiveHandler(new BetterDispatcher(new[] { cook1, cook2, cook3 })))); TelephoneOperator telephoneOperator = new TelephoneOperator("PhoneMan"); Waiter waiter = new Waiter("Georgie"); var house = new MidgetHouse(Dispatcher.Instance); var houseQueue = new QueuedHandler(house); var clock = new AlarmClock(); Dispatcher.Instance.Subscribe(typeof(OrderPlaced), houseQueue); Dispatcher.Instance.Subscribe(typeof(FoodCooked), houseQueue); Dispatcher.Instance.Subscribe(typeof(OrderPriced), houseQueue); Dispatcher.Instance.Subscribe(typeof(PaymentTaken), houseQueue); Dispatcher.Instance.Subscribe(typeof(FirstCookRetry), houseQueue); Dispatcher.Instance.Subscribe(typeof(SecondCookRetry), houseQueue); Dispatcher.Instance.Subscribe(typeof(CookFood), betterHandler); Dispatcher.Instance.Subscribe(typeof(PriceOrder), assistingManager); Dispatcher.Instance.Subscribe(typeof(TakePayment), cashierProxy); Dispatcher.Instance.Subscribe(typeof(PrintOrder), printOrderHandler); Dispatcher.Instance.Subscribe(typeof(SendToMeIn), clock); IEnumerable <QueuedHandler> allHandlers = new List <QueuedHandler> { houseQueue, betterHandler, cashierProxy, assistingManager, cook1, cook2, cook3, printOrderHandler }; Monitor monitor = new Monitor(allHandlers, new [] { house }); monitor.Start(); foreach (IStartable handler in allHandlers) { handler.Start(); } clock.Start(); //waiter.PlaceOrder(new List<int> { 1, 2 }); //telephoneOperator.PlaceOrder(new List<int> { 1, 2 }); return; for (int i = 0; i < 1000; i++) { waiter.PlaceOrder(new List <int> { 1, 2 }); if (i % 3 == 0) { Thread.Sleep(50); telephoneOperator.PlaceOrder(new List <int> { 1, 2 }); } Thread.Sleep(50); } while (true) { foreach (string orderId in ((Cashier)cashier).GetOutstandingOrders()) { Console.WriteLine("Got outstanding order to pay, id " + orderId); ((Cashier)cashier).Pay(orderId, "123456"); } Thread.Sleep(1); } //Console.ReadLine(); }