Beispiel #1
0
        /**
         * Updates the progress for {@link Allocation} atomically relative to the {@code allocation}.
         *
         * <p>For any {@link Allocation}, this method <em>must</em> have been called on all of its parents
         * beforehand.
         *
         * @param allocation the {@link Allocation} to update progress for
         * @param units the units of progress
         * @return {@code true} if the map was updated
         */
        public bool UpdateProgress(Allocation allocation, long units)
        {
            IndexedRemainingUnits newValue = new IndexedRemainingUnits(allocation);
            var finalValue = completionMap.GetOrAdd(allocation, newValue);

            UpdateIndexedRemainingUnits(finalValue, units);
            return(newValue == finalValue || units != 0);
        }
        /**
         * Creates a new {@link ProgressEventDispatcher} and dispatches a new {@link ProgressEvent} with
         * progress 0 for {@code allocation}.
         *
         * @param eventHandlers the {@link EventHandlers}
         * @param allocation the {@link Allocation} to manage
         * @return a new {@link ProgressEventDispatcher}
         */
        private static ProgressEventDispatcher NewProgressEventDispatcher(
            IEventHandlers eventHandlers, Allocation allocation)
        {
            ProgressEventDispatcher progressEventDispatcher =
                new ProgressEventDispatcher(eventHandlers, allocation);

            progressEventDispatcher.DispatchProgress(0);
            return(progressEventDispatcher);
        }
Beispiel #3
0
        public void Accept(ProgressEvent progressEvent)
        {
            progressEvent = progressEvent ?? throw new ArgumentNullException(nameof(progressEvent));
            Allocation allocation         = progressEvent.GetAllocation();
            long       progressUnits      = progressEvent.GetUnits();
            double     allocationFraction = allocation.GetFractionOfRoot();

            if (progressUnits != 0)
            {
                progress.Add(progressUnits * allocationFraction);
            }

            if (completionTracker.UpdateProgress(allocation, progressUnits))
            {
                // Note: Could produce false positives.
                updateNotifier(new Update(progress.Sum(), completionTracker.GetUnfinishedLeafTasks()));
            }
        }
 /**
  * Creates a new {@link ProgressEventDispatcher} with a root {@link Allocation}.
  *
  * @param eventHandlers the {@link EventHandlers}
  * @param description user-facing description of what the allocation represents
  * @param allocationUnits number of allocation units
  * @return a new {@link ProgressEventDispatcher}
  */
 public static ProgressEventDispatcher NewRoot(
     IEventHandlers eventHandlers, string description, long allocationUnits)
 {
     return(NewProgressEventDispatcher(
                eventHandlers, Allocation.NewRoot(description, allocationUnits)));
 }
Beispiel #5
0
 public IndexedRemainingUnits(Allocation allocation)
 {
     this.allocation = allocation;
     remainingUnits  = new AtomicLong(allocation.GetAllocationUnits());
 }