Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/18/13 10:34:23 (11 years ago)
Author:
ascheibe
Message:

#2005 merged Hive Job Unloading branch back into trunk

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Clients.Hive/3.3/ConcurrentTaskDownloader.cs

    r7259 r9219  
    3030  /// Downloads and deserializes jobs. It avoids too many jobs beeing downloaded or deserialized at the same time to avoid memory problems
    3131  /// </summary>
    32   public class ConcurrentTaskDownloader<T> where T : class, ITask {
     32  public class ConcurrentTaskDownloader<T> : IDisposable where T : class, ITask {
    3333    private bool abort = false;
    3434    // use semaphore to ensure only few concurrenct connections and few SerializedJob objects in memory
     
    3939      downloadSemaphore = new Semaphore(concurrentDownloads, concurrentDownloads);
    4040      deserializeSemaphore = new Semaphore(concurrentDeserializations, concurrentDeserializations);
    41       TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);
    4241    }
    4342
     
    6968
    7069    private Task DownloadTask(object taskId) {
    71       return HiveServiceLocator.Instance.CallHiveService(s => s.GetTask((Guid)taskId));
     70      Task t = null;
     71      HiveClient.TryAndRepeat(() => {
     72        t = HiveServiceLocator.Instance.CallHiveService(s => s.GetTask((Guid)taskId));
     73      }, Settings.Default.MaxRepeatServiceCalls, "Failed to download task.");
     74      return t;
    7275    }
    7376
     
    7881    protected Tuple<Task, TaskData> DownloadTaskData(Task task) {
    7982      downloadSemaphore.WaitOne();
    80       TaskData result;
     83      TaskData result = null;
    8184      try {
    8285        if (abort) return null;
    83         result = HiveServiceLocator.Instance.CallHiveService(s => s.GetTaskData(task.Id));
    84       } finally {
     86        HiveClient.TryAndRepeat(() => {
     87          result = HiveServiceLocator.Instance.CallHiveService(s => s.GetTaskData(task.Id));
     88        }, Settings.Default.MaxRepeatServiceCalls, "Failed to download task data.");
     89      }
     90      finally {
    8591        downloadSemaphore.Release();
    8692      }
     
    95101        taskData.Item2.Data = null; // reduce memory consumption.
    96102        return new Tuple<Task, T>(taskData.Item1, deserializedJob);
    97       } finally {
     103      }
     104      finally {
    98105        deserializeSemaphore.Release();
    99106      }
    100     }
    101 
    102     private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) {
    103       e.SetObserved(); // avoid crash of process because task crashes. first exception found is handled in Results property
    104       OnExceptionOccured(new HiveException("Unobserved Exception in ConcurrentTaskDownloader", e.Exception));
    105107    }
    106108
     
    110112      if (handler != null) handler(this, new EventArgs<Exception>(exception));
    111113    }
     114
     115    #region IDisposable Members
     116    public void Dispose() {
     117      deserializeSemaphore.Dispose();
     118      downloadSemaphore.Dispose();
     119    }
     120    #endregion
    112121  }
    113122}
Note: See TracChangeset for help on using the changeset viewer.