Exemple #1
0
 /// <summary>
 /// Handle the exceptions in the Call() method
 /// Default to IMRUSystemException to make it recoverable
 /// </summary>
 public byte[] Call(byte[] memento)
 {
     Logger.Log(Level.Info, "Entering {0} Call().", TaskHostName);
     try
     {
         _groupCommunicationsClient.Initialize(_cancellationSource);
         return(TaskBody(memento));
     }
     catch (Exception e)
     {
         if (e is IMRUTaskAppException)
         {
             throw;
         }
         if (IsCommunicationException(e))
         {
             HandleCommunicationException(e);
         }
         else
         {
             HandleSystemException(e);
         }
     }
     finally
     {
         _taskCloseCoordinator.SignalTaskStopped();
     }
     Logger.Log(Level.Info, "{0} returned with cancellation token:{1}.", TaskHostName, _cancellationSource.IsCancellationRequested);
     return(null);
 }
Exemple #2
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);
        }
Exemple #3
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 (!_cancellationSource.IsCancellationRequested && controlMessage != MapControlMessage.Stop)
            {
                if (_invokeGC)
                {
                    Logger.Log(Level.Verbose, "Calling Garbage Collector");
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }

                try
                {
                    using (
                        MapInputWithControlMessage <TMapInput> mapInput = _dataAndMessageReceiver.Receive(_cancellationSource))
                    {
                        controlMessage = mapInput.ControlMessage;
                        if (controlMessage != MapControlMessage.Stop)
                        {
                            _dataReducer.Send(_mapTask.Map(mapInput.Message), _cancellationSource);
                        }
                    }
                }
                catch (OperationCanceledException e)
                {
                    Logger.Log(Level.Warning, "Received OperationCanceledException in MapTaskHost with message: {0}.", e.Message);
                    break;
                }
                catch (IOException e)
                {
                    Logger.Log(Level.Error, "Received IOException in MapTaskHost with message: {0}.", e.Message);
                    if (!_cancellationSource.IsCancellationRequested)
                    {
                        throw new IMRUTaskGroupCommunicationException(TaskManager.TaskGroupCommunicationError);
                    }
                    break;
                }
                catch (TcpClientConnectionException e)
                {
                    Logger.Log(Level.Error, "Received TcpClientConnectionException in MapTaskHost with message: {0}.", e.Message);
                    if (!_cancellationSource.IsCancellationRequested)
                    {
                        throw new IMRUTaskGroupCommunicationException(TaskManager.TaskGroupCommunicationError);
                    }
                    break;
                }
            }

            _taskCloseCoordinator.SignalTaskStopped();
            Logger.Log(Level.Info, "MapTaskHost returned with cancellation token:{0}.", _cancellationSource.IsCancellationRequested);
            return(null);
        }
Exemple #4
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);
        }
Exemple #5
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;

            try
            {
                while (updateResult.HasMapInput && !_cancellationSource.IsCancellationRequested)
                {
                    iterNo++;

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

                    var input = _dataReceiver.Reduce(_cancellationSource);

                    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 (!_cancellationSource.IsCancellationRequested)
                {
                    MapInputWithControlMessage <TMapInput> stopMessage =
                        new MapInputWithControlMessage <TMapInput>(MapControlMessage.Stop);
                    _dataAndControlMessageSender.Send(stopMessage);
                }
            }
            catch (OperationCanceledException e)
            {
                Logger.Log(Level.Warning,
                           "Received OperationCanceledException in UpdateTaskHost with message: {0}.",
                           e.Message);
            }
            catch (IOException e)
            {
                Logger.Log(Level.Error, "Received IOException in UpdateTaskHost with message: {0}.", e.Message);
                if (!_cancellationSource.IsCancellationRequested)
                {
                    throw new IMRUTaskGroupCommunicationException(TaskManager.TaskGroupCommunicationError);
                }
            }
            catch (TcpClientConnectionException e)
            {
                Logger.Log(Level.Error,
                           "Received TcpClientConnectionException in UpdateTaskHost with message: {0}.",
                           e.Message);
                if (!_cancellationSource.IsCancellationRequested)
                {
                    throw new IMRUTaskGroupCommunicationException(TaskManager.TaskGroupCommunicationError);
                }
            }
            _resultHandler.Dispose();
            _taskCloseCoordinator.SignalTaskStopped();
            Logger.Log(Level.Info, "UpdateTaskHost returned with cancellation token {0}.", _cancellationSource.IsCancellationRequested);
            return(null);
        }