Пример #1
0
        /// <summary>
        /// Performs IMRU iterations on map side
        /// </summary>
        /// <param name="memento"></param>
        /// <returns></returns>
        public byte[] Call(byte[] memento)
        {
            MapControlMessage controlMessage = MapControlMessage.AnotherRound;

            while (!_taskCloseCoordinator.ShouldCloseTask() && controlMessage != MapControlMessage.Stop)
            {
                if (_invokeGC)
                {
                    Logger.Log(Level.Verbose, "Calling Garbage Collector");
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }

                using (
                    MapInputWithControlMessage <TMapInput> mapInput = _dataAndMessageReceiver.Receive())
                {
                    controlMessage = mapInput.ControlMessage;
                    if (controlMessage != MapControlMessage.Stop)
                    {
                        _dataReducer.Send(_mapTask.Map(mapInput.Message));
                    }
                }
            }

            _taskCloseCoordinator.SignalTaskStopped();
            return(null);
        }
Пример #2
0
        /// <summary>
        /// Performs IMRU iterations on update side
        /// </summary>
        /// <param name="memento"></param>
        /// <returns></returns>
        public byte[] Call(byte[] memento)
        {
            var updateResult = _updateTask.Initialize();
            int iterNo       = 0;

            while (updateResult.HasMapInput && !_taskCloseCoordinator.ShouldCloseTask())
            {
                iterNo++;

                using (
                    var message = new MapInputWithControlMessage <TMapInput>(updateResult.MapInput,
                                                                             MapControlMessage.AnotherRound))
                {
                    _dataAndControlMessageSender.Send(message);
                }

                var input = _dataReceiver.Reduce();

                if (_invokeGC)
                {
                    Logger.Log(Level.Verbose, "Calling Garbage Collector");
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }

                updateResult = _updateTask.Update(input);

                if (updateResult.HasResult)
                {
                    _resultHandler.HandleResult(updateResult.Result);
                }
            }

            if (!_taskCloseCoordinator.ShouldCloseTask())
            {
                MapInputWithControlMessage <TMapInput> stopMessage =
                    new MapInputWithControlMessage <TMapInput>(MapControlMessage.Stop);
                _dataAndControlMessageSender.Send(stopMessage);
            }

            _resultHandler.Dispose();
            _taskCloseCoordinator.SignalTaskStopped();
            return(null);
        }