Free cookie consent management tool by TermsFeed Policy Generator

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

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

added Priority and resource restricted scheduling (#907)

File size: 2.3 KB
Line 
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 {
12  internal class DefaultScheduler : IScheduler {
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) {
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    }
30
31    public HeuristicLab.Hive.Contracts.BusinessObjects.JobDto GetNextJobForClient(Guid clientId) {
32      /// Critical section ///
33      jobLock.WaitOne();
34
35      ClientDto client = DaoLocator.ClientDao.FindById(clientId);
36      LinkedList<JobDto> allOfflineJobsForClient =
37        new LinkedList<JobDto>(DaoLocator.JobDao.FindFittingJobsForClient(State.offline, client.NrOfFreeCores,
38                                                                          client.FreeMemory, client.Id));
39
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);
50      }
51      jobLock.ReleaseMutex();
52      /// End Critical section ///
53
54      return jobToCalculate;
55    }
56
57    #endregion
58  }
59}
Note: See TracBrowser for help on using the repository browser.