Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/DefaultScheduler.cs @ 4320

Last change on this file since 4320 was 4285, checked in by cneumuel, 14 years ago
  • changed Hive.Server WCF services to be configurable in app.config
  • changed endpoints to wsHttpBinding
  • changed project type of Hive.Server.Core to WCF Service Library, so that it can be started directly to be able to test the service (and update references) (#1159)
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;
10using System.Transactions;
11using HeuristicLab.Hive.Contracts;
12
13namespace HeuristicLab.Hive.Server.Core {
14  internal class DefaultScheduler : IScheduler {
15
16    private static object jobLock = new object();
17
18    #region IScheduler Members
19
20    public DefaultScheduler() { }
21
22    public bool ExistsJobForSlave(HeartBeatData hbData) {
23      List<JobDto> allOfflineJobsForSlave = new List<JobDto>(DaoLocator.JobDao.FindFittingJobsForSlave(JobState.Offline, hbData.FreeCores, hbData.FreeMemory, hbData.SlaveId));
24      return (allOfflineJobsForSlave != null && allOfflineJobsForSlave.Count > 0);
25    }
26
27    public JobDto GetNextJobForSlave(Guid slaveId) {
28      lock (jobLock) {
29        /// Critical section ///
30        JobDto jobToCalculate = null;
31        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE })) {
32          SlaveDto slave = DaoLocator.SlaveDao.FindById(slaveId);
33          if (slave != null) {
34            LinkedList<JobDto> allOfflineJobsForSlave = new LinkedList<JobDto>(DaoLocator.JobDao.FindFittingJobsForSlave(JobState.Offline, slave.NrOfFreeCores, slave.FreeMemory, slave.Id));
35            if (allOfflineJobsForSlave != null && allOfflineJobsForSlave.Count > 0) {
36              jobToCalculate = allOfflineJobsForSlave.First.Value;
37              jobToCalculate.State = JobState.Calculating;
38              jobToCalculate.Slave = slave;
39              jobToCalculate.Slave.State = SlaveState.Calculating;
40              jobToCalculate.DateCalculated = DateTime.Now;
41              DaoLocator.JobDao.AssignSlaveToJob(slave.Id, jobToCalculate.Id);
42              DaoLocator.JobDao.Update(jobToCalculate);
43              DaoLocator.SlaveDao.Update(jobToCalculate.Slave);
44            }
45          }
46          scope.Complete();
47        }
48        /// End Critical section ///
49
50        return jobToCalculate;
51      }
52    }
53
54    #endregion
55  }
56}
Note: See TracBrowser for help on using the repository browser.