Last change
on this file since 1360 was
1334,
checked in by msteinbi, 16 years ago
|
Merging defaultscheduler and ischeduler (dummy check in) with correct version (#507)
|
File size:
1.7 KB
|
Rev | Line | |
---|
[1284] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Hive.Server.Core.InternalInterfaces;
|
---|
[1334] | 6 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
| 7 | using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
|
---|
| 8 | using System.Threading;
|
---|
[1284] | 9 |
|
---|
| 10 | namespace HeuristicLab.Hive.Server.Scheduler {
|
---|
[1334] | 11 | class DefaultScheduler: IScheduler {
|
---|
| 12 |
|
---|
| 13 | IJobAdapter jobAdapter;
|
---|
| 14 | IClientAdapter clientAdapter;
|
---|
| 15 |
|
---|
| 16 | private static Mutex jobLock =
|
---|
| 17 | new Mutex();
|
---|
| 18 |
|
---|
[1284] | 19 | #region IScheduler Members
|
---|
| 20 |
|
---|
[1334] | 21 | public DefaultScheduler() {
|
---|
| 22 | jobAdapter = ServiceLocator.GetJobAdapter();
|
---|
| 23 | clientAdapter = ServiceLocator.GetClientAdapter();
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[1284] | 26 | public bool ExistsJobForClient(HeuristicLab.Hive.Contracts.BusinessObjects.HeartBeatData hbData) {
|
---|
[1334] | 27 | List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline));
|
---|
| 28 | return (allOfflineJobs.Count > 0);
|
---|
[1284] | 29 | }
|
---|
| 30 |
|
---|
| 31 | public HeuristicLab.Hive.Contracts.BusinessObjects.Job GetNextJobForClient(Guid clientId) {
|
---|
[1334] | 32 |
|
---|
| 33 | /// Critical section ///
|
---|
| 34 | jobLock.WaitOne();
|
---|
| 35 |
|
---|
| 36 | LinkedList<Job> allOfflineJobs = new LinkedList<Job>(jobAdapter.GetJobsByState(State.offline));
|
---|
| 37 |
|
---|
| 38 | Job job2Calculate = null;
|
---|
| 39 | if (allOfflineJobs != null && allOfflineJobs.Count > 0) {
|
---|
| 40 | job2Calculate = allOfflineJobs.First.Value;
|
---|
| 41 | job2Calculate.State = State.calculating;
|
---|
| 42 | job2Calculate.Client = clientAdapter.GetById(clientId);
|
---|
| 43 | job2Calculate.Client.State = State.calculating;
|
---|
| 44 |
|
---|
| 45 | job2Calculate.DateCalculated = DateTime.Now;
|
---|
| 46 | jobAdapter.Update(job2Calculate);
|
---|
| 47 | }
|
---|
| 48 | jobLock.ReleaseMutex();
|
---|
| 49 | /// End Critical section ///
|
---|
| 50 |
|
---|
| 51 | return job2Calculate;
|
---|
[1284] | 52 | }
|
---|
| 53 |
|
---|
| 54 | #endregion
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.