Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/31/09 01:33:37 (16 years ago)
Author:
svonolfe
Message:

Added transaction management (#527)

Location:
trunk/sources/HeuristicLab.Hive.Server.Scheduler
Files:
2 edited

Legend:

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

    r1377 r1468  
    77using HeuristicLab.Hive.Server.DataAccess;
    88using System.Threading;
     9using HeuristicLab.DataAccess.Interfaces;
    910
    1011namespace HeuristicLab.Hive.Server.Scheduler {
    1112  class DefaultScheduler: IScheduler {
    1213
    13     IJobAdapter jobAdapter;
    14     IClientAdapter clientAdapter;
     14    private ISessionFactory factory;
    1515
    1616    private static Mutex jobLock =
     
    2020
    2121    public DefaultScheduler() {
    22       jobAdapter = ServiceLocator.GetJobAdapter();
    23       clientAdapter = ServiceLocator.GetClientAdapter();
     22      factory = ServiceLocator.GetSessionFactory();
    2423    }
    2524
    2625    public bool ExistsJobForClient(HeuristicLab.Hive.Contracts.BusinessObjects.HeartBeatData hbData) {
    27       List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline));
    28       return (allOfflineJobs.Count > 0);
     26      ISession session = factory.GetSessionForCurrentThread();
     27
     28      try {
     29        IJobAdapter jobAdapter =
     30          session.GetDataAdapter<Job, IJobAdapter>();
     31
     32        List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline));
     33        return (allOfflineJobs.Count > 0);
     34      }
     35      finally {
     36        if (session != null)
     37          session.EndSession();
     38      }
    2939    }
    3040
    3141    public HeuristicLab.Hive.Contracts.BusinessObjects.Job GetNextJobForClient(Guid clientId) {
     42      ISession session = factory.GetSessionForCurrentThread();
    3243
    33       /// Critical section ///
    34       jobLock.WaitOne();
     44      try {
     45        IJobAdapter jobAdapter =
     46          session.GetDataAdapter<Job, IJobAdapter>();
    3547
    36       LinkedList<Job> allOfflineJobs = new LinkedList<Job>(jobAdapter.GetJobsByState(State.offline));
     48        IClientAdapter clientAdapter =
     49          session.GetDataAdapter<ClientInfo, IClientAdapter>();
    3750
    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;
     51        /// Critical section ///
     52        jobLock.WaitOne();
    4453
    45         job2Calculate.DateCalculated = DateTime.Now;
    46         jobAdapter.Update(job2Calculate);
     54        LinkedList<Job> allOfflineJobs = new LinkedList<Job>(jobAdapter.GetJobsByState(State.offline));
     55
     56        Job job2Calculate = null;
     57        if (allOfflineJobs != null && allOfflineJobs.Count > 0) {
     58          job2Calculate = allOfflineJobs.First.Value;
     59          job2Calculate.State = State.calculating;
     60          job2Calculate.Client = clientAdapter.GetById(clientId);
     61          job2Calculate.Client.State = State.calculating;
     62
     63          job2Calculate.DateCalculated = DateTime.Now;
     64          jobAdapter.Update(job2Calculate);
     65        }
     66        jobLock.ReleaseMutex();
     67        /// End Critical section ///
     68
     69        return job2Calculate;
    4770      }
    48       jobLock.ReleaseMutex();
    49       /// End Critical section ///
    50 
    51       return job2Calculate;
     71      finally {
     72        if (session != null)
     73          session.EndSession();
     74      }
    5275    }
    5376
  • trunk/sources/HeuristicLab.Hive.Server.Scheduler/HeuristicLab.Hive.Server.Scheduler.csproj

    r1377 r1468  
    7373  </ItemGroup>
    7474  <ItemGroup>
     75    <ProjectReference Include="..\HeuristicLab.DataAccess.ADOHelper\HeuristicLab.DataAccess.ADOHelper.csproj">
     76      <Project>{5CDACE54-5FB2-4344-A21C-963F63CB7C2B}</Project>
     77      <Name>HeuristicLab.DataAccess.ADOHelper</Name>
     78    </ProjectReference>
    7579    <ProjectReference Include="..\HeuristicLab.DataAccess\HeuristicLab.DataAccess.csproj">
    7680      <Project>{9076697B-C151-46CD-95BC-1D059492B478}</Project>
Note: See TracChangeset for help on using the changeset viewer.