Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/LifecycleManager.cs @ 4423

Last change on this file since 4423 was 4423, checked in by cneumuel, 14 years ago
  • Refactored HL.Hive.Experiment. JobItems are not called HiveJobs and OptimizerJobs do not contain a hierarchy anymore.
  • Dynamic generation of jobs on a slave are not reflected on the client user interface.
  • Optimizer-Trees are now strictly synchronized with the HiveJob-Trees (also the ComputeInParallel property is taken into account when the Child HiveJobs are created)
  • Improved the way a class can report progress and lock the UI (IProgressReporter, IProgress, Progress, ProgressView)
  • Changes were made to the config-files, so that server and clients work with blade12.hpc.fh-hagenberg.at
  • Lots of small changes and bugfixes
File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.Interfaces;
27using HeuristicLab.Hive.Server.DataAccess;
28using System.Timers;
29using HeuristicLab.DataAccess.Interfaces;
30using HeuristicLab.Tracing;
31using System.Threading;
32
33namespace HeuristicLab.Hive.Server.Core {
34  class LifecycleManager : ILifecycleManager {
35    private AutoResetEvent waitHandle;
36    private Thread thread;
37    private bool shutdownRequested;
38
39    private TimeSpan interval = new TimeSpan(0, 0, 10);
40    public TimeSpan Interval {
41      get { return interval; }
42      set { interval = value; }
43    }
44
45    private int jobsCurrentlyTransfering = 0;
46    public int JobsCurrentlyTransferring {
47      get { return jobsCurrentlyTransfering; }
48      set {
49        if (jobsCurrentlyTransfering != value) {
50          jobsCurrentlyTransfering = value;
51          Logger.Info("JobsCurrentlyTransfering: " + jobsCurrentlyTransfering);
52        }
53      }
54    }
55
56    #region ILifecycleManager Members
57
58    public void Start() {
59      Thread thread = new Thread(RunHeartbeatThread);
60      thread.Start();
61      using (ServiceLocator.GetContextFactory().GetContext()) {
62        OnStarted();
63      }
64    }
65
66    private void RunHeartbeatThread() {
67      waitHandle = new AutoResetEvent(false);
68      shutdownRequested = false;
69      while (!shutdownRequested) {
70        using (ServiceLocator.GetContextFactory().GetContext(false)) {
71          OnServerHeartbeat();
72        }
73        waitHandle.WaitOne(this.Interval);
74      }
75      waitHandle.Close();
76      using (ServiceLocator.GetContextFactory().GetContext()) {
77        OnStopped();
78      }
79    }
80
81    public void Stop() {
82      shutdownRequested = true;
83      if (waitHandle != null) waitHandle.Set();
84      if (thread != null) thread.Join();
85      thread = null;
86    }
87
88    public event EventHandler ServerHeartbeat;
89    private void OnServerHeartbeat() {
90      var handler = ServerHeartbeat;
91      if (handler != null) handler(this, EventArgs.Empty);
92    }
93
94    public event EventHandler Started;
95    private void OnStarted() {
96      var handler = Started;
97      if (handler != null) handler(this, EventArgs.Empty);
98    }
99
100    public event EventHandler Stopped;
101    private void OnStopped() {
102      var handler = Stopped;
103      if (handler != null) handler(this, EventArgs.Empty);
104    }
105
106    #endregion
107  }
108}
Note: See TracBrowser for help on using the repository browser.