Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/02/11 15:23:59 (14 years ago)
Author:
cneumuel
Message:

#1233

  • changed the way lifecycle methods are called. The new service method TriggerLifecycle checks when the latest cleanup was made and performs one (if necessary). This can also be called by an external program (like a windows task)
  • robustified logging
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs

    r5526 r5593  
    11using System;
    22using System.Linq;
    3 using HeuristicLab.Core;
    43using HeuristicLab.Services.Hive.Common;
    54using HeuristicLab.Services.Hive.Common.DataTransfer;
     
    76namespace HeuristicLab.Services.Hive {
    87  /// <summary>
    9   /// This class holds the state of all recent heartbeats and decides to reschedule jobs and set slaves offline
     8  /// This class offers methods for cleaning up offline slaves and jobs
    109  /// </summary>
    1110  public class LifecycleManager : ILifecycleManager {
     
    1918      get { return ServiceLocator.Instance.AuthorizationManager; }
    2019    }
    21 
    22     private static object locker = new object();
    23 
    24     // Windows-Forms timer is single threaded, so callbacks will be synchron
    25     private System.Windows.Forms.Timer timer;
    26 
    27     public ExecutionState ExecutionState {
    28       get { return timer.Enabled ? ExecutionState.Started : Core.ExecutionState.Stopped; }
     20    private ILogger log {
     21      get { return LogFactory.GetLogger(this.GetType().Namespace); }
    2922    }
    3023
    31     public LifecycleManager() {
    32       this.timer = new System.Windows.Forms.Timer();
    33       this.timer.Tick += new EventHandler(timer_Tick);
    34     }
    35 
    36     public void Start() {
    37       if (ExecutionState == Core.ExecutionState.Stopped) {
    38         // kick off the event immediately
    39         timer_Tick(this, EventArgs.Empty);
    40 
    41         // start the timer
    42         this.timer.Interval = (int)new TimeSpan(0, 0, 30).TotalMilliseconds;
    43         this.timer.Start();
    44       }
    45     }
    46 
    47     public void Stop() {
    48       if (ExecutionState == Core.ExecutionState.Started) {
    49         timer.Stop();
    50       }
    51     }
    52 
    53     /// <summary>
    54     /// This method is supposed to check if slaves are online
    55     /// if not -> set them offline and check if they where calculating a job
    56     /// </summary>
    57     private void timer_Tick(object sender, EventArgs e) {
    58       lock (locker) {
    59         using (trans.OpenTransaction()) {
    60           SetTimeoutSlavesOffline();
    61           FinishParentJobs();
    62         }
    63       }
     24    public void Cleanup() {
     25      log.Log("LifecycleManager.Cleanup()");
     26      SetTimeoutSlavesOffline();
     27      FinishParentJobs();
    6428    }
    6529
     
    10165      }
    10266    }
     67
    10368  }
    10469}
Note: See TracChangeset for help on using the changeset viewer.