Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Engine/3.2/Job.cs @ 1655

Last change on this file since 1655 was 1655, checked in by kgrading, 15 years ago

added proper exception handling (#601)

File size: 3.1 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.Text;
25using HeuristicLab.Core;
26using System.Threading;
27using HeuristicLab.Hive.JobBase;
28using System.Xml;
29
30namespace HeuristicLab.Hive.Engine {
31  /// <summary>
32  /// Represents an job that wraps an engine that should be executed in the hive.
33  /// </summary>
34  public class Job : StorableBase, IJob {
35    private IEngine engine;
36    public IEngine Engine {
37      get { return engine; }
38    }
39
40    public Job()
41      : base() {
42      engine = new SequentialEngine.SequentialEngine();
43      RegisterEvents();
44    }
45
46    private void RegisterEvents() {
47      engine.Finished += new EventHandler(engine_Finished);
48    }
49
50    private void DeregisterEvents() {
51      engine.Finished -= new EventHandler(engine_Finished);
52    }
53
54    void engine_Finished(object sender, EventArgs e) {
55      if (JobStopped != null)
56        JobStopped(this, new EventArgs());
57    }
58
59    #region IJob Members
60
61    public event EventHandler JobStopped;
62    public event EventHandler JobFailed;
63
64    public long JobId {
65      get;
66      set;
67    }
68
69    public double Progress {
70      get { return 0.0; }
71      set { throw new NotSupportedException(); }
72    }
73
74    public bool Running {
75      get {
76        return Engine.Running;
77      }
78      set {
79        throw new NotSupportedException();
80      }
81    }
82
83    public void Run() {
84      throw new NotSupportedException();
85    }
86
87    public void Start() {
88      Engine.Execute();
89    }
90
91    public void Stop() {
92      Engine.Abort();
93    }
94
95    #endregion
96
97    public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
98      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
99      node.AppendChild(PersistenceManager.Persist("Engine", Engine, document, persistedObjects));
100      return node;
101    }
102    public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
103      base.Populate(node, restoredObjects);
104      DeregisterEvents();
105      engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);
106      RegisterEvents();
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.