static void Main(string[] args) { var bus = new TopicBasedPubSub(); var orderPrinter = new OrderPrinter(); var cashier = new Cashier(bus); var assitantManager = new QueuedHandle <PriceOrder>("AssistantManager", new AssistantManager(bus)); var db = new ConcurrentDictionary <Guid, OrderDocument>(); var jesse = new QueuedHandle <CookFood>("Cook:Jesse", new Cook("Jesse", 600, db, bus)); var walt = new QueuedHandle <CookFood>("Cook:Walt", new Cook("Walt", 700, db, bus)); var gus = new QueuedHandle <CookFood>("Cook:Gus", new Cook("Gus", 1500, db, bus)); var dispatcher = new MoreFairDispatcher <CookFood>("FairDispatcher", new[] { jesse, walt, gus }); var chaosMonkey = new ChaosMonkey <CookFood>(25, 25, dispatcher); var alarmClock = new AlarmClock(bus); var startables = new List <IStartable> { assitantManager, jesse, walt, gus, dispatcher, alarmClock }; var waiter = new Waiter("Heisenberg", bus); var house = new MinionHouse(bus); bus.Subscribe(chaosMonkey); bus.Subscribe(assitantManager); bus.Subscribe(cashier); bus.Subscribe <OrderPlaced>(house); bus.Subscribe <OrderCompleted>(house); bus.Subscribe(orderPrinter); bus.Subscribe(alarmClock); startables.ForEach(x => x.Start()); for (var i = 0; i < 50; i++) { waiter.PlaceOrder(new LineItem("Crystal Meth", 3)); Console.WriteLine("Order placed"); } Console.WriteLine("Getting outstanding orders"); Task.Run(() => GetOutstandingOrdersAndPay(cashier)); Task.Run(() => StartMonitoringQueueDepthsAsync(startables)); StartMonitoringMinionHouseAsync(house).Wait(); }
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(); }