Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/09 14:39:22 (16 years ago)
Author:
msteinbi
Message:

Merging defaultscheduler and ischeduler (dummy check in) with correct version (#507)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Scheduler/DefaultScheduler.cs

    r1284 r1334  
    44using System.Text;
    55using HeuristicLab.Hive.Server.Core.InternalInterfaces;
     6using HeuristicLab.Hive.Contracts.BusinessObjects;
     7using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
     8using System.Threading;
    69
    710namespace HeuristicLab.Hive.Server.Scheduler {
    8   class DefaultScheduler : IScheduler {
     11  class DefaultScheduler: IScheduler {
     12
     13    IJobAdapter jobAdapter;
     14    IClientAdapter clientAdapter;
     15
     16    private static Mutex jobLock =
     17      new Mutex();
     18
    919    #region IScheduler Members
    1020
     21    public DefaultScheduler() {
     22      jobAdapter = ServiceLocator.GetJobAdapter();
     23      clientAdapter = ServiceLocator.GetClientAdapter();
     24    }
     25
    1126    public bool ExistsJobForClient(HeuristicLab.Hive.Contracts.BusinessObjects.HeartBeatData hbData) {
    12       throw new NotImplementedException();
     27      List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline));
     28      return (allOfflineJobs.Count > 0);
    1329    }
    1430
    1531    public HeuristicLab.Hive.Contracts.BusinessObjects.Job GetNextJobForClient(Guid clientId) {
    16       throw new NotImplementedException();
     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;
    1752    }
    1853
Note: See TracChangeset for help on using the changeset viewer.