Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Clients.Hive.Slave/3.3/SlaveClientCom.cs @ 13401

Last change on this file since 13401 was 8242, checked in by spimming, 12 years ago

#1888:

  • slave worker role initial commit
  • start client communication service optionally
  • make slave client communication interchangeable ('PipeCom', 'TraceCom')
File size: 3.0 KB
RevLine 
[6983]1#region License Information
2/* HeuristicLab
[7259]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6983]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
[8242]22using System;
[6983]23using HeuristicLab.Clients.Hive.SlaveCore.Properties;
24using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
25
26namespace HeuristicLab.Clients.Hive.SlaveCore {
27
[8242]28  public enum ClientComType { Pipe, Trace };
29
[6983]30  /// <summary>
31  /// Singleton which encapsulates the SlaveCommunicationService
32  /// </summary>
33  public class SlaveClientCom {
34    private static SlaveClientCom instance;
[8242]35    //private static DuplexChannelFactory<ISlaveCommunication> pipeFactory;
36    private static IClientCom clientComInstance;
[6983]37    public ISlaveCommunication ClientCom { get; set; }
38
39    /// <summary>
40    /// Getter for the Instance of the SlaveClientCom
41    /// </summary>
42    /// <returns>the Instance of the SlaveClientCom class</returns>
43    public static SlaveClientCom Instance {
44      get {
45        if (instance == null) {
46          instance = new SlaveClientCom();
47        }
48        return instance;
49      }
50    }
51
[8242]52    public static IClientCom ClientComInstance {
53      get {
54        if (clientComInstance != null) {
55          return clientComInstance;
56        }
57        throw new NullReferenceException("No instance of SlaveClientCom<T>");
58      }
59    }
60
[7171]61    public void LogMessage(string message) {
62      try {
63        ClientCom.LogMessage(message);
64      }
65      catch (Exception ex) {
66        EventLogManager.LogMessage("Exception on LogMessage: " + ex.ToString() + Environment.NewLine + "Orginal message was: " + message);
67      }
68    }
69
70    public void StatusChanged(StatusCommons status) {
71      try {
72        ClientCom.StatusChanged(status);
73      }
74      catch (Exception ex) {
75        EventLogManager.LogMessage("Exception on StatusChanged: " + ex.ToString());
76      }
77    }
78
[6983]79    private SlaveClientCom() {
[8242]80      ClientComType type = Settings.Default.ClientComType;
81      if (type == ClientComType.Pipe) {
82        clientComInstance = new PipeCom();
83      } else if (type == ClientComType.Trace) {
84        clientComInstance = new TraceCom();
85      } else {
86        throw new InvalidStateException("Invalid client communication type");
[6983]87      }
88
[8242]89      ClientCom = clientComInstance.GetSlaveCom();
[6983]90    }
91
92    public static void Close() {
[8242]93      ClientComInstance.Close();
[6983]94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.