Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Jobs/EngineJob.cs @ 6419

Last change on this file since 6419 was 6419, checked in by cneumuel, 13 years ago

#1233

  • created events when statelog changed
  • fixed memory leak in hiveengine
  • extended timeout for long running transactions and database contexts (when jobdata is stored)
  • replaced random guids in database with sequential guids for performance reasons
  • minor fixes and cleanups
File size: 4.2 KB
Line 
1using System;
2using System.Drawing;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace HeuristicLab.Clients.Hive {
8  [StorableClass]
9  public class EngineJob : ItemJob {
10    [Storable]
11    protected IOperation initialOperation;
12    public IOperation InitialOperation {
13      get { return initialOperation; }
14      set { initialOperation = value; }
15    }
16
17    public new IEngine Item {
18      get { return (IEngine)base.Item; }
19      set { base.Item = value; }
20    }
21
22    public override TimeSpan ExecutionTime {
23      get { return Item.ExecutionTime; }
24    }
25
26    public override ExecutionState ExecutionState {
27      get { return Item.ExecutionState; }
28    }
29
30    #region constructors and cloning
31    public EngineJob() { }
32    public EngineJob(IOperation initialOperation, IEngine engine) {
33      this.initialOperation = initialOperation;
34      this.Item = engine;
35    }
36
37    [StorableConstructor]
38    protected EngineJob(bool deserializing) : base(deserializing) { }
39    protected EngineJob(EngineJob original, Cloner cloner)
40      : base(original, cloner) {
41      this.initialOperation = cloner.Clone(original.initialOperation);
42    }
43    public override IDeepCloneable Clone(Cloner cloner) {
44      return new EngineJob(this, cloner);
45    }
46    #endregion
47
48    public override bool IsParallelizable {
49      get { return false; }
50    }
51
52    public override void Prepare() { }
53
54    public override void Start() {
55      Item.Prepare(initialOperation);
56      Item.Start();
57    }
58   
59    public override void Pause() {
60      Item.Pause();
61    }
62
63    public override void Stop() {
64      Item.Stop();
65    }
66
67    protected override void RegisterItemEvents() {
68      base.RegisterItemEvents();
69      Item.Stopped += new EventHandler(engine_Stopped);
70      Item.Paused += new EventHandler(Item_Paused);
71      Item.Started += new EventHandler(Item_Started);
72      Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
73      Item.ExecutionStateChanged += new EventHandler(Item_ExecutionStateChanged);
74      Item.ExecutionTimeChanged += new EventHandler(Item_ExecutionTimeChanged);
75    }
76
77    protected override void DeregisterItemEvents() {
78      Item.Stopped -= new EventHandler(engine_Stopped);
79      Item.Paused -= new EventHandler(Item_Paused);
80      Item.Started -= new EventHandler(Item_Started);
81      Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
82      Item.ExecutionStateChanged -= new EventHandler(Item_ExecutionStateChanged);
83      Item.ExecutionTimeChanged -= new EventHandler(Item_ExecutionTimeChanged);
84      base.DeregisterItemEvents();
85    }
86
87    private void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
88      OnJobFailed(e);
89    }
90
91    private void engine_Stopped(object sender, EventArgs e) {
92      OnJobStopped();
93    }
94
95    private void Item_Paused(object sender, EventArgs e) {
96      OnJobPaused();
97    }
98
99    private void Item_ExecutionTimeChanged(object sender, EventArgs e) {
100      OnExecutionTimeChanged();
101    }
102
103    private void Item_ExecutionStateChanged(object sender, EventArgs e) {
104      OnExecutionStateChanged();
105    }
106
107    private void Item_Started(object sender, EventArgs e) {
108      OnJobStarted();
109    }
110
111    public override bool CanChangeDescription {
112      get { return false; }
113    }
114
115    public override bool CanChangeName {
116      get { return false; }
117    }
118
119    public override string Description {
120      get { return string.Empty; }
121      set { throw new NotSupportedException(); }
122    }
123
124    public override string Name {
125      get { return Item != null ? Item.ToString() : null; }
126      set { throw new NotSupportedException(); }
127    }
128
129    public override string ItemDescription {
130      get { return Description; }
131    }
132
133    public override Image ItemImage {
134      get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; }
135    }
136   
137    public override string ItemName {
138      get { return "EngineJob"; }
139    }
140
141    public override Version ItemVersion {
142      get { return null; }
143    }
144  }
145}
Note: See TracBrowser for help on using the repository browser.