Exemplo n.º 1
0
        public static void StartPool(
            bool dummy,
            TimeSpan workArrivedSchedule,
            TimeSpan producerCheckSchedule,
            int consumers,
            CancellationToken cancellationToken)
        {
            var workAvailableRepo = new WorkAvailableRepo(6);
            var started           = new ManualResetEvent(false);

            var workFactory = GetWorkFactory(dummy, workAvailableRepo);

            var workerPool =
                new WorkPoolBuilder()
                .WithScheduledJob(
                    workArrivedSchedule, token => { workAvailableRepo.Reset(); })
                .WithProducer(
                    ProducerFactoryMethod(producerCheckSchedule, workFactory, started))
                .WithNConsumers(consumers)
                .Build();

            workerPool.Start(cancellationToken);

            started.WaitOne();
        }
Exemplo n.º 2
0
        public static void StartPool(
            bool dummy,
            TimeSpan workArrivedSchedule,
            TimeSpan producerCheckSchedule,
            int consumers,
            CancellationToken cancellationToken)
        {
            var factory    = new WorkerFactory();
            var workerPool = factory.CreatePool();

            var workAvailableRepo = new WorkAvailableRepo(1);

            workerPool.Add(
                factory.CreateScheduledJob(
                    workArrivedSchedule, token => { workAvailableRepo.Reset(); }));

            var started     = new ManualResetEvent(false);
            var workFactory = GetWorkFactory(dummy, workerPool, workAvailableRepo);

            workerPool.Add(factory.CreateProducer(
                               () => new ScheduledProducer(
                                   producerCheckSchedule,
                                   workFactory.Create,
                                   (token) => workFactory.Startup(token, started))));

            workerPool.Add(factory.CreateConsumers(consumers));

            workerPool.Start(cancellationToken);
            started.WaitOne();
        }
Exemplo n.º 3
0
        public static void StartPool(
            bool dummy,
            TimeSpan workArrivedSchedule,
            TimeSpan producerSchedule,
            int consumers,
            int consecutiveBatchesAvailable,
            CancellationToken cancellationToken)
        {
            var workAvailableRepo = new WorkAvailableRepo(consecutiveBatchesAvailable);

            var workItemFactory = GetWorkFactory(dummy, workAvailableRepo);

            using (var startupBarrier = new StartupBarrier())
            {
                var workerPoolBuilder = new WorkerPoolBuilder(startupBarrier)
                                        .WithScheduledProducer(producerSchedule, workItemFactory)
                                        .WithNConsumers(consumers);

                if (dummy)
                {
                    workerPoolBuilder.WithScheduledJob(workArrivedSchedule, token => { workAvailableRepo.Reset(); });
                }

                workerPoolBuilder.Build().Start(cancellationToken);

                startupBarrier.Wait(cancellationToken);
            }
        }
Exemplo n.º 4
0
        private static ISampleWorkFactory GetWorkFactory(bool dummy, WorkAvailableRepo workAvailableRepo)
        {
            if (!dummy)
            {
                return(new ReadFromBlobSampleWorkFactory(workAvailableRepo));
            }

            return(new DummyWorkFactory(workAvailableRepo));
        }
Exemplo n.º 5
0
        private static IBatchedWorkItemFactory GetWorkFactory(
            bool dummy, WorkAvailableRepo workAvailableRepo)
        {
            if (!dummy)
            {
                return(new BlobWatcherWorkItemFactory());
            }

            return(new DummyWorkItemFactory(workAvailableRepo));
        }
Exemplo n.º 6
0
        private static ISampleWorkFactory GetWorkFactory(bool dummy, IWorkerPool workerPool, WorkAvailableRepo workAvailableRepo)
        {
            if (!dummy)
            {
                return(new ReadFromBlobSampleWorkFactory(
                           () => workerPool.IsAlive, workAvailableRepo));
            }

            return(new DummyWorkFactory(workAvailableRepo));
        }