Exemple #1
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();
        }
Exemple #2
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();
        }
Exemple #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);
            }
        }