Ejemplo n.º 1
0
        /// <summary>
        /// Creates a set of tasks for each sub grid in the integrated sub grid tree and executes them concurrently
        /// </summary>
        public bool IntegrateSubGridTreeParallelisedTasks(SubGridTreeIntegrationMode integrationMode,
                                                          Action <int, int> subGridChangeNotifier)
        {
            void ProcessSubGrid(IServerLeafSubGrid sourceSubGrid,
                                SubGridTreeIntegrationMode integrationModeLocal,
                                Action <int, int> subGridChangeNotifierLocal)
            {
                try
                {
                    IntegrateSubGrid(sourceSubGrid, integrationModeLocal, subGridChangeNotifierLocal, new SubGridSegmentIterator(null, _storageProxySubGridSegments));
                }
                catch (Exception e)
                {
                    // Log the exception as this code is being run within a Task
                    _log.LogError(e, "Error occurred during Task based execution of data integration");
                }
            }

            // Iterate over the sub grids in source and merge the cell passes from source
            // into the sub grids in this sub grid tree;

            var iterator = new SubGridTreeIterator(_storageProxySubGrids, false)
            {
                Grid = _source
            };

            var tasks = new List <Task>();

            while (iterator.MoveToNextSubGrid())
            {
                var subGrid = iterator.CurrentSubGrid as IServerLeafSubGrid;
                tasks.Add(Task.Run(() => ProcessSubGrid(subGrid, integrationMode, subGridChangeNotifier)));
            }

            try
            {
                var completionTask = Task.WhenAll(tasks);
                completionTask.Wait();
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception integrating sub grids via parallelised tasks");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool IntegrateSubGridTree(SubGridTreeIntegrationMode integrationMode,
                                         Action <int, int> subGridChangeNotifier)
        {
            // Iterate over the sub grids in source and merge the cell passes from source
            // into the sub grids in this sub grid tree;

            var iterator = new SubGridTreeIterator(_storageProxySubGrids, false)
            {
                Grid = _source
            };
            var segmentIterator = new SubGridSegmentIterator(null, _storageProxySubGridSegments)
            {
                IterationDirection = IterationDirection.Forwards
            };

            while (iterator.MoveToNextSubGrid())
            {
                var sourceSubGrid = iterator.CurrentSubGrid as IServerLeafSubGrid;

                /*
                 * // TODO: Terminated check for integration processing
                 * if (Terminated)
                 * {
                 *  // Service has been shutdown. Abort integration of changes and flag the
                 *  // operation as failed. The TAG file will be reprocessed when the service restarts
                 *  return false;
                 * }
                 */

                IntegrateSubGrid(sourceSubGrid, integrationMode, subGridChangeNotifier, segmentIterator);

                // Release the resources used by SourceSubGrid as this is the last point it is needed
                sourceSubGrid?.DeAllocateLeafFullPassStacks();
                sourceSubGrid?.DeAllocateLeafLatestPassGrid();
            }

            return(true);
        }