Ignore:
Timestamp:
09/21/15 16:28:38 (7 years ago)
Author:
ascheibe
Message:

#2388 merged r12878, r12879, r12883, r12885, r12913, r12914, r12925, r12932, r12961 into stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Services.Hive

  • stable/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs

    r12009 r12962  
    2323using System.Threading;
    2424using HeuristicLab.Services.Hive.DataAccess;
     25using HeuristicLab.Services.Hive.DataAccess.Interfaces;
    2526
    2627namespace HeuristicLab.Services.Hive {
    2728  public class HiveJanitor {
    2829    private bool stop;
    29     private AutoResetEvent waitHandle;
     30    private AutoResetEvent cleanupWaitHandle;
     31    private AutoResetEvent generateStatisticsWaitHandle;
    3032
    31     private DataAccess.ITransactionManager trans {
    32       get { return ServiceLocator.Instance.TransactionManager; }
     33    private IPersistenceManager PersistenceManager {
     34      get { return ServiceLocator.Instance.PersistenceManager; }
    3335    }
    34 
    35     private IEventManager eventManager {
     36    private IEventManager EventManager {
    3637      get { return ServiceLocator.Instance.EventManager; }
    3738    }
    3839
    39     private IHiveDao dao {
    40       get { return ServiceLocator.Instance.HiveDao; }
     40    private IStatisticsGenerator StatisticsGenerator {
     41      get { return ServiceLocator.Instance.StatisticsGenerator; }
    4142    }
    4243
    4344    public HiveJanitor() {
    4445      stop = false;
    45       waitHandle = new AutoResetEvent(true);
     46      cleanupWaitHandle = new AutoResetEvent(false);
     47      generateStatisticsWaitHandle = new AutoResetEvent(false);
    4648    }
    4749
    4850    public void StopJanitor() {
    4951      stop = true;
    50       waitHandle.Set();
     52      cleanupWaitHandle.Set();
     53      generateStatisticsWaitHandle.Set();
    5154    }
    5255
    53     public void Run() {
     56    public void RunCleanup() {
     57      var pm = PersistenceManager;
    5458      while (!stop) {
    5559        try {
    56           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup");
     60          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup.");
    5761          bool cleanup = false;
    58           trans.UseTransaction(() => {
    59             DateTime lastCleanup = dao.GetLastCleanup();
    60             if (DateTime.Now - lastCleanup > HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval) {
    61               dao.SetLastCleanup(DateTime.Now);
     62
     63          var lifecycleDao = pm.LifecycleDao;
     64          pm.UseTransaction(() => {
     65            var lifecycle = lifecycleDao.GetLastLifecycle();
     66            if (lifecycle == null
     67                || DateTime.Now - lifecycle.LastCleanup > Properties.Settings.Default.CleanupInterval) {
     68              lifecycleDao.UpdateLifecycle();
    6269              cleanup = true;
    6370            }
     71            pm.SubmitChanges();
    6472          }, true);
    6573
    6674          if (cleanup) {
    67             eventManager.Cleanup();
     75            EventManager.Cleanup();
    6876          }
    69           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished");
     77          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished.");
    7078        }
    7179        catch (Exception e) {
    7280          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e.ToString()));
    7381        }
    74         waitHandle.WaitOne(HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval);
     82        cleanupWaitHandle.WaitOne(Properties.Settings.Default.CleanupInterval);
    7583      }
    76       waitHandle.Close();
     84      cleanupWaitHandle.Close();
     85    }
     86
     87    public void RunGenerateStatistics() {
     88      while (!stop) {
     89        try {
     90          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting generate statistics.");
     91          StatisticsGenerator.GenerateStatistics();
     92          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: generate statistics finished.");
     93        }
     94        catch (Exception e) {
     95          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e));
     96        }
     97
     98        generateStatisticsWaitHandle.WaitOne(Properties.Settings.Default.GenerateStatisticsInterval);
     99      }
     100
     101      generateStatisticsWaitHandle.Close();
    77102    }
    78103  }
Note: See TracChangeset for help on using the changeset viewer.