- Timestamp:
- 09/02/15 13:16:18 (9 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Services.Hive
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs
r12012 r12931 23 23 using System.Threading; 24 24 using HeuristicLab.Services.Hive.DataAccess; 25 using HeuristicLab.Services.Hive.DataAccess.Interfaces; 25 26 26 27 namespace HeuristicLab.Services.Hive { 27 28 public class HiveJanitor { 28 29 private bool stop; 29 private AutoResetEvent waitHandle; 30 private AutoResetEvent cleanupWaitHandle; 31 private AutoResetEvent generateStatisticsWaitHandle; 30 32 31 private DataAccess.ITransactionManager trans{32 get { return ServiceLocator.Instance. TransactionManager; }33 private IPersistenceManager PersistenceManager { 34 get { return ServiceLocator.Instance.PersistenceManager; } 33 35 } 34 35 private IEventManager eventManager { 36 private IEventManager EventManager { 36 37 get { return ServiceLocator.Instance.EventManager; } 37 38 } 38 39 39 private I HiveDao dao{40 get { return ServiceLocator.Instance. HiveDao; }40 private IStatisticsGenerator StatisticsGenerator { 41 get { return ServiceLocator.Instance.StatisticsGenerator; } 41 42 } 42 43 43 44 public HiveJanitor() { 44 45 stop = false; 45 waitHandle = new AutoResetEvent(true); 46 cleanupWaitHandle = new AutoResetEvent(false); 47 generateStatisticsWaitHandle = new AutoResetEvent(false); 46 48 } 47 49 48 50 public void StopJanitor() { 49 51 stop = true; 50 waitHandle.Set(); 52 cleanupWaitHandle.Set(); 53 generateStatisticsWaitHandle.Set(); 51 54 } 52 55 53 public void Run() { 56 public void RunCleanup() { 57 var pm = PersistenceManager; 54 58 while (!stop) { 55 59 try { 56 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup ");60 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup."); 57 61 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(); 62 69 cleanup = true; 63 70 } 71 pm.SubmitChanges(); 64 72 }, true); 65 73 66 74 if (cleanup) { 67 eventManager.Cleanup();75 EventManager.Cleanup(); 68 76 } 69 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished ");77 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished."); 70 78 } 71 79 catch (Exception e) { 72 80 LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e.ToString())); 73 81 } 74 waitHandle.WaitOne(HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval);82 cleanupWaitHandle.WaitOne(Properties.Settings.Default.CleanupInterval); 75 83 } 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(); 77 102 } 78 103 }
Note: See TracChangeset
for help on using the changeset viewer.