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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Hive.Client.ExecutionEngine;
|
---|
27 | using HeuristicLab.Hive.Client.Common;
|
---|
28 | using System.Threading;
|
---|
29 |
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Hive.Client.Core {
|
---|
32 | public class Core {
|
---|
33 |
|
---|
34 | Dictionary<long, Executor> engines = new Dictionary<long, Executor>();
|
---|
35 |
|
---|
36 | public void Start() {
|
---|
37 | Logging.getInstance().Info(this.ToString(), "Info Message");
|
---|
38 | //Logging.getInstance().Error(this.ToString(), "Error Message");
|
---|
39 | //Logging.getInstance().Error(this.ToString(), "Exception Message", new Exception("Exception"));
|
---|
40 |
|
---|
41 | Heartbeat beat = new Heartbeat();
|
---|
42 | beat.Interval = 5000;
|
---|
43 | beat.StartHeartbeat();
|
---|
44 |
|
---|
45 | MessageQueue queue = MessageQueue.GetInstance();
|
---|
46 |
|
---|
47 | JobBase job = new TestJob();
|
---|
48 |
|
---|
49 | ExecutionEngine.Executor engine = new ExecutionEngine.Executor();
|
---|
50 | engine.Job = job;
|
---|
51 | engine.JobId = 1L;
|
---|
52 | engine.Queue = queue;
|
---|
53 | engine.Start();
|
---|
54 | engines.Add(engine.JobId, engine);
|
---|
55 |
|
---|
56 | Thread.Sleep(15000);
|
---|
57 | engine.RequestSnapshot();
|
---|
58 | while (true) {
|
---|
59 | MessageContainer container = queue.GetMessage();
|
---|
60 | Logging.getInstance().Info(this.ToString(), container.Message.ToString());
|
---|
61 | DetermineAction(container);
|
---|
62 |
|
---|
63 |
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | private void DetermineAction(MessageContainer container) {
|
---|
68 | if(container.Message == MessageContainer.MessageType.AbortJob)
|
---|
69 | engines[container.JobId].Abort();
|
---|
70 | else if (container.Message == MessageContainer.MessageType.JobAborted)
|
---|
71 | //kill appdomain
|
---|
72 | Console.WriteLine("tmp");
|
---|
73 | else if (container.Message == MessageContainer.MessageType.RequestSnapshot)
|
---|
74 | engines[container.JobId].RequestSnapshot();
|
---|
75 | else if (container.Message == MessageContainer.MessageType.SnapshotReady)
|
---|
76 | // must be async!
|
---|
77 | engines[container.JobId].GetSnapshot();
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|