Last change
on this file since 5511 was
5093,
checked in by cneumuel, 14 years ago
|
#1260
- moved all state-information into lifecycleManager
- changed isolation level for transactions to ReadCommited
- made currentlyFetching-status on slave more rubust
- made LogServiceReader more rubust
|
File size:
1.8 KB
|
Rev | Line | |
---|
[4772] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows.Forms;
|
---|
| 6 | using HeuristicLab.Core;
|
---|
[4810] | 7 | using HeuristicLab.Hive.Slave.Console.SlaveConsoleService;
|
---|
[5093] | 8 | using HeuristicLab.Clients.Common;
|
---|
[4772] | 9 |
|
---|
| 10 | namespace HeuristicLab.Hive.Slave.Console {
|
---|
| 11 | internal class LogServiceReader : ILogReader {
|
---|
| 12 |
|
---|
| 13 | private Timer timer;
|
---|
| 14 | private int messageCount = 0;
|
---|
| 15 |
|
---|
[4810] | 16 | public LogServiceReader() {
|
---|
[4772] | 17 | }
|
---|
| 18 |
|
---|
| 19 | public void Start() {
|
---|
| 20 | timer = new Timer();
|
---|
| 21 | timer.Interval = 2000;
|
---|
| 22 | timer.Tick += new EventHandler(timer_Tick);
|
---|
| 23 | timer.Start();
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | void timer_Tick(object sender, EventArgs e) {
|
---|
| 27 | try {
|
---|
[5093] | 28 | using (var slaveClient = ClientFactory.CreateClient<ISlaveConsoleCommunicator>("SlaveConsoleTcpEndpointClient")) {
|
---|
| 29 | try {
|
---|
| 30 | var messages = slaveClient.Obj.GetLogMessages();
|
---|
| 31 | if (messages.Count < messageCount) {
|
---|
| 32 | messageCount = 0; // log got cleared
|
---|
| 33 | }
|
---|
| 34 | var newMessages = messages.GetRange(messageCount, messages.Count - messageCount);
|
---|
| 35 | messageCount = messages.Count;
|
---|
| 36 | OnMoreData(newMessages);
|
---|
| 37 |
|
---|
[4810] | 38 | }
|
---|
[5093] | 39 | catch (Exception ex) {
|
---|
| 40 | OnMoreData(new List<string> { "Error fetching log: " + ex.ToString() });
|
---|
| 41 | }
|
---|
[4810] | 42 | }
|
---|
[4772] | 43 | }
|
---|
[5037] | 44 | catch (Exception ex) {
|
---|
[5093] | 45 | OnMoreData(new List<string> { "Error in slave-communication: " + ex.ToString() });
|
---|
[5037] | 46 | }
|
---|
[4772] | 47 | }
|
---|
| 48 |
|
---|
| 49 | public void Stop() {
|
---|
| 50 | timer.Stop();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public event MoreDataHandler MoreData;
|
---|
| 54 | private void OnMoreData(IEnumerable<string> newMessages) {
|
---|
| 55 | var handler = MoreData;
|
---|
| 56 | var newData = string.Join(Environment.NewLine, newMessages.ToArray());
|
---|
[5093] | 57 | if (newMessages.Count() > 0) newData += Environment.NewLine;
|
---|
[4772] | 58 | if (handler != null) MoreData(this, newData);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.