/// <summary> /// Dispose resultHandler /// </summary> protected override void FinallyBlock() { try { _resultHandler.Dispose(); } catch (Exception e) { Logger.Log(Level.Error, "Exception in dispose result handler.", e); //// TODO throw proper exceptions JIRA REEF-1492 } }
public override void Dispose() { if (Interlocked.Exchange(ref _disposed, 1) == 0) { _resultHandler.Dispose(); _groupCommunicationsClient.Dispose(); var disposableTask = _updateTask as IDisposable; if (disposableTask != null) { disposableTask.Dispose(); } } }
/// <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); }
/// <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); }