Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/3.2/DefaultScheduler.cs @ 3491

Last change on this file since 3491 was 3018, checked in by kgrading, 15 years ago

added Priority and resource restricted scheduling (#907)

File size: 2.3 KB
RevLine 
[3011]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Hive.Server.Core.InternalInterfaces;
6using HeuristicLab.Hive.Contracts.BusinessObjects;
7using HeuristicLab.Hive.Server.DataAccess;
8using System.Threading;
9using HeuristicLab.DataAccess.Interfaces;
10
11namespace HeuristicLab.Hive.Server.Core {
[3018]12  internal class DefaultScheduler : IScheduler {
[3011]13    //private ISessionFactory factory;
14
15    private static Mutex jobLock =
16      new Mutex();
17
18    #region IScheduler Members
19
20    public DefaultScheduler() {
21      //factory = ServiceLocator.GetSessionFactory();
22    }
23
24    public bool ExistsJobForClient(HeuristicLab.Hive.Contracts.BusinessObjects.HeartBeatData hbData) {
[3018]25      List<JobDto> allOfflineJobsForClient =
26        new List<JobDto>(DaoLocator.JobDao.FindFittingJobsForClient(State.offline, hbData.FreeCores, hbData.FreeMemory,
27                                                                    hbData.ClientId));
28      return (allOfflineJobsForClient != null && allOfflineJobsForClient.Count > 0);
29    }
[3011]30
31    public HeuristicLab.Hive.Contracts.BusinessObjects.JobDto GetNextJobForClient(Guid clientId) {
[3018]32      /// Critical section ///
33      jobLock.WaitOne();
[3011]34
[3018]35      ClientDto client = DaoLocator.ClientDao.FindById(clientId);
[3011]36      LinkedList<JobDto> allOfflineJobsForClient =
37        new LinkedList<JobDto>(DaoLocator.JobDao.FindFittingJobsForClient(State.offline, client.NrOfFreeCores,
[3018]38                                                                          client.FreeMemory, client.Id));
[3011]39
[3018]40      JobDto jobToCalculate = null;
41      if (allOfflineJobsForClient != null && allOfflineJobsForClient.Count > 0) {
42        jobToCalculate = allOfflineJobsForClient.First.Value;
43        jobToCalculate.State = State.calculating;
44        jobToCalculate.Client = client;
45        jobToCalculate.Client.State = State.calculating;
46        jobToCalculate.DateCalculated = DateTime.Now;
47        DaoLocator.JobDao.AssignClientToJob(client.Id, jobToCalculate.Id);
48        DaoLocator.JobDao.Update(jobToCalculate);
49        DaoLocator.ClientDao.Update(jobToCalculate.Client);
[3011]50      }
[3018]51      jobLock.ReleaseMutex();
52      /// End Critical section ///
[3011]53
[3018]54      return jobToCalculate;
55    }
56
[3011]57    #endregion
58  }
[3018]59}
Note: See TracBrowser for help on using the repository browser.