示例#1
0
        public ChunkedPhase(
            IStageIdentity stageIdentity,
            IGenerationPhaseIdentity phaseIdentity,
            IReadOnlyLargeCollection <TKey> chunkKeys,
            IAsyncFactory <TKey, IDisposableValue <TChunk> > chunkFactory,
            IChunkProcessor <TChunk> chunkProcessor,
            GenerationOptions options = null)
            : base(options?.CancellationToken ?? DefaultCancellationToken)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(phaseIdentity != null);
            Contracts.Requires.That(chunkKeys != null);
            Contracts.Requires.That(chunkFactory != null);
            Contracts.Requires.That(chunkProcessor != null);

            this.StageIdentity  = stageIdentity;
            this.PhaseIdentity  = phaseIdentity;
            this.chunkKeys      = chunkKeys;
            this.chunkFactory   = chunkFactory;
            this.chunkProcessor = chunkProcessor;

            this.Progress = this.progress.AsObservable();

            var dataflowOptions = new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = options?.MaxDegreeOfParallelism ?? DefaultMaxDegreeOfParallelism,
                CancellationToken      = this.CancellationToken,
            };

            this.processChunks   = new ActionBlock <TKey>(this.ProcessChunk, dataflowOptions);
            this.chunksCompleted = new AsyncLongCountdownEvent(this.ProgressTotalCount);
        }
        public ChunkKeyCollection(
            IStageBounds bounds, Func <Index3D, Index3D, IEnumerable <Index3D> > enumerationOrder)
        {
            Contracts.Requires.That(bounds != null);
            Contracts.Requires.That(enumerationOrder != null);

            var chunkKeys =
                enumerationOrder(bounds.InChunks.LowerBounds, bounds.InChunks.Dimensions)
                .Select(index => new ChunkKey(index));

            this.keys = new ReadOnlyLargeCollection <ChunkKey>(
                chunkKeys, bounds.InChunks.LongLength);
        }
        public ChunkedBatchingPhase(
            IStageIdentity stageIdentity,
            IGenerationPhaseIdentity phaseIdentity,
            IReadOnlyLargeCollection <TKey> chunkKeys,
            IAsyncFactory <TKey, TPersistable> chunkFactory,
            IChunkStore <TKey, TPersistable> chunkStore,
            int maxBatchedChunks,
            BatchGenerationOptions options = null)
            : base(options?.CancellationToken ?? DefaultCancellationToken)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(phaseIdentity != null);
            Contracts.Requires.That(chunkKeys != null);
            Contracts.Requires.That(chunkFactory != null);
            Contracts.Requires.That(chunkStore != null);
            Contracts.Requires.That(maxBatchedChunks > 0);

            this.StageIdentity = stageIdentity;
            this.PhaseIdentity = phaseIdentity;
            this.chunkKeys     = chunkKeys;
            this.chunkFactory  = chunkFactory;
            this.chunkStore    = chunkStore;

            this.Progress = this.progress.AsObservable();

            var dataflowOptions = new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = options?.MaxDegreeOfParallelism ?? DefaultMaxDegreeOfParallelism,
                BoundedCapacity        = maxBatchedChunks,
                CancellationToken      = this.CancellationToken,
            };

            this.generateChunks = new TransformBlock <TKey, TPersistable>(
                chunkIndex => this.chunkFactory.CreateAsync(chunkIndex), dataflowOptions);

            this.saveChunks = BatchActionBlock.Create <TPersistable>(
                this.SaveChunks,
                maxBatchedChunks,
                options?.Batching ?? DefaultBatching,
                dataflowOptions);

            var linkOptions = new DataflowLinkOptions()
            {
                PropagateCompletion = true
            };

            this.generateChunks.LinkTo(this.saveChunks, linkOptions);

            this.chunksCompleted = new AsyncLongCountdownEvent(this.ProgressTotalCount);
        }