Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/21/09 16:22:25 (15 years ago)
Author:
msteinbi
Message:

Implementing Lifecycle Management (#453)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r1158 r1160  
    8080    void lifecycleManager_OnServerHeartbeat(object sender, EventArgs e) {
    8181      List<ClientInfo> allClients = new List<ClientInfo>(clientAdapter.GetAll());
    82       List<Job> allJobs = new List<Job>(jobAdapter.GetAll());
    8382
    8483      foreach (ClientInfo client in allClients) {
     
    8988            client.State = State.offline;
    9089            clientAdapter.Update(client);
     90            foreach (Job job in jobAdapter.GetJobsOf(client)) {
     91              jobManager.ResetJobsDependingOnResults(job);
     92            }
    9193          } else {
    9294            DateTime lastHbOfClient = lastHeartbeats[client.ClientId];
     
    98100              if (client.State == State.calculating) {
    99101                // check wich job the client was calculating and reset it
    100                 foreach (Job job in allJobs) {
    101                   if (job.Client.ClientId == client.ClientId) {
    102                     jobManager.ResetJobsDependingOnResults(job);
    103                   }
     102                foreach (Job job in jobAdapter.GetJobsOf(client)) {
     103                  jobManager.ResetJobsDependingOnResults(job);
    104104                }
    105105              }
     
    195195
    196196      if (hbData.jobProgress != null) {
     197        List<Job> jobsOfClient = new List<Job>(jobAdapter.GetJobsOf(clientAdapter.GetById(hbData.ClientId)));
     198        if (jobsOfClient == null || jobsOfClient.Count == 0) {
     199          response.Success = false;
     200          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
     201          return response;
     202        }
     203
    197204        foreach (KeyValuePair<long, double> jobProgress in hbData.jobProgress) {
    198205          Job curJob = jobAdapter.GetById(jobProgress.Key);
    199           curJob.Percentage = jobProgress.Value;
    200           jobAdapter.Update(curJob);
     206          if (curJob.Client == null || curJob.Client.ClientId != hbData.ClientId) {
     207            response.Success = false;
     208            response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
     209          } else {
     210            curJob.Percentage = jobProgress.Value;
     211            jobAdapter.Update(curJob);
     212          }
    201213        }
    202214      }
     
    228240        response.Success = true;
    229241        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_PULLED;
    230         return response;
     242      } else {
     243        response.Success = true;
     244        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT;
    231245      }
    232246
    233247      jobLock.ReleaseMutex();
    234 
    235       response.Success = true;
    236       response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT;
     248      /// End Critical section ///
     249
    237250      return response;
    238251    }
Note: See TracChangeset for help on using the changeset viewer.