Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveCommunicationService.cs @ 5826

Last change on this file since 5826 was 5826, checked in by ascheibe, 13 years ago

#1233 slave ui now receives status information and displays it in doughnut chart

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Collections.Generic;
23using System.ServiceModel;
24using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
25
26
27namespace HeuristicLab.Clients.Hive.SlaveCore {
28
29  public class SlaveCommunicationService : ISlaveCommunication {
30    private static List<ISlaveCommunicationCallbacks> subscribers = new List<ISlaveCommunicationCallbacks>();
31
32    public bool Subscribe() {
33      try {
34        ISlaveCommunicationCallbacks callback = OperationContext.Current.GetCallbackChannel<ISlaveCommunicationCallbacks>();
35        if (!subscribers.Contains(callback)) {
36          subscribers.Add(callback);
37        }
38        return true;
39      }
40      catch {
41        return false;
42      }
43    }
44
45    public bool Unsubscribe() {
46      try {
47        ISlaveCommunicationCallbacks callback = OperationContext.Current.GetCallbackChannel<ISlaveCommunicationCallbacks>();
48        if (subscribers.Contains(callback))
49          subscribers.Remove(callback);
50        return true;
51      }
52      catch {
53        return false;
54      }
55    }
56
57    public void LogMessage(string message) {
58      subscribers.ForEach(delegate(ISlaveCommunicationCallbacks callback) {
59        if (((ICommunicationObject)callback).State == CommunicationState.Opened) {
60          callback.OnMessageLogged(message);
61        } else {
62          subscribers.Remove(callback);
63        }
64      });
65    }
66
67    public void StatusChanged(SlaveCore.StatusCommons status) {
68      subscribers.ForEach(delegate(ISlaveCommunicationCallbacks callback) {
69        if (((ICommunicationObject)callback).State == CommunicationState.Opened) {
70          callback.OnStatusChanged(status);
71        } else {
72          subscribers.Remove(callback);
73        }
74      });
75    }
76
77    public void Shutdown() {
78      subscribers.ForEach(delegate(ISlaveCommunicationCallbacks callback) {
79        if (((ICommunicationObject)callback).State == CommunicationState.Opened) {
80          callback.OnShutdown();
81        } else {
82          subscribers.Remove(callback);
83        }
84      });
85    }
86
87    public void Restart() {
88      MessageContainer mc = new MessageContainer(MessageContainer.MessageType.Restart);
89      MessageQueue.GetInstance().AddMessage(mc);
90    }
91
92    public void PauseAll() {
93      MessageContainer mc = new MessageContainer(MessageContainer.MessageType.PauseAll);
94      MessageQueue.GetInstance().AddMessage(mc);
95    }
96
97    public void StopAll() {
98      MessageContainer mc = new MessageContainer(MessageContainer.MessageType.StopAll);
99      MessageQueue.GetInstance().AddMessage(mc);
100    }
101
102    public void AbortAll() {
103      MessageContainer mc = new MessageContainer(MessageContainer.MessageType.AbortAll);
104      MessageQueue.GetInstance().AddMessage(mc);
105    }
106
107    public void Sleep() {
108      MessageContainer mc = new MessageContainer(MessageContainer.MessageType.Sleep);
109      MessageQueue.GetInstance().AddMessage(mc);
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.