Exemplo n.º 1
0
        public ThreadBoundary <TEvent> Wrap <TEvent>(IHandler <TEvent> handler)
        {
            var tb = new ThreadBoundary <TEvent>(handler);

            _cache.Add(tb);
            return(tb);
        }
Exemplo n.º 2
0
        private static void BackPressureTest()
        {
            var topicDispatcher       = new TopicDispatcher();
            var threadBoundaryMonitor = new ThreadBoundaryMonitor();

            ThreadBoundary <Report> reporting = threadBoundaryMonitor.Wrap(new ReportingSystem(topicDispatcher));
            var cashierInner = new Cashier(topicDispatcher);
            ThreadBoundary <QueueOrderForPayment> cashier    = threadBoundaryMonitor.Wrap(cashierInner);
            ThreadBoundary <PriceFood>            assManager = threadBoundaryMonitor.Wrap(new AssistantManager(topicDispatcher));
            var cooks = new[]
            {
                threadBoundaryMonitor.Wrap(new Cook(topicDispatcher, 20)),
                threadBoundaryMonitor.Wrap(new Cook(topicDispatcher, 50)),
                threadBoundaryMonitor.Wrap(new Cook(topicDispatcher, 90))
            };
            TTLSettingHandler <CookFood> cookDispatcher =
                TTLSettingHandler.Wrap(
                    threadBoundaryMonitor.Wrap(
                        RetryDispatcher.Wrap(
                            TTLFilteringHandler.Wrap(
                                SmartDispatcher.Wrap(cooks, 15)))),
                    10);

            var waiter = new Waiter("Neil", topicDispatcher);

            topicDispatcher.Subscribe(cashier);
            topicDispatcher.Subscribe(cookDispatcher);
            topicDispatcher.Subscribe(assManager);
            topicDispatcher.Subscribe(reporting);
            topicDispatcher.Subscribe(threadBoundaryMonitor.Wrap(new Logger()));

            topicDispatcher.Subscribe(new SelfUnsubscribingOrderSampler(topicDispatcher));

            topicDispatcher.Subscribe(threadBoundaryMonitor.Wrap <OrderTaken>(new OrderFulfillmentCoordinator(topicDispatcher)));
            threadBoundaryMonitor.Start();

            RunTest(waiter, cashierInner, 5000);
        }