source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.Slave/3.3/SlaveClientCom.cs @ 6989

Last change on this file since 6989 was 6989, checked in by spimming, 11 years ago

#1680:

  • start client communication service optionally
  • make slave client communication interchangeable ('PipeCom', 'TraceCom')
File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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;
23using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
24using HeuristicLab.Clients.Hive.SlaveCore.Properties;
25namespace HeuristicLab.Clients.Hive.SlaveCore {
26
27  public enum ClientComType { Pipe, Trace };
28
29  /// <summary>
30  /// Singleton which encapsulates the SlaveCommunicationService
31  /// </summary>
32  public class SlaveClientCom {
33    private static SlaveClientCom instance;
34    private static IClientCom clientComInstance;
35    public ISlaveCommunication ClientCom { get; set; }
36
37    /// <summary>
38    /// Getter for the Instance of the SlaveClientCom
39    /// </summary>
40    /// <returns>the Instance of the SlaveClientCom class</returns>
41    public static SlaveClientCom Instance {
42      get {
43        if (instance == null) {
44          instance = new SlaveClientCom();
45        }
46        return instance;
47      }
48    }
49
50    public static IClientCom ClientComInstance {
51      get {
52        if (clientComInstance != null) {
53          return clientComInstance;
54        }
55        throw new NullReferenceException("No instance of SlaveClientCom<T>");
56      }
57    }
58
59    private SlaveClientCom() {
60      ClientComType type = Settings.Default.ClientComType;
61      if (type == ClientComType.Pipe) {
62        clientComInstance = new PipeCom();
63      } else if (type == ClientComType.Trace) {
64        clientComInstance = new TraceCom();
65      } else {
66        throw new InvalidStateException("Invalid client communication type");
67      }
68
69      ClientCom = clientComInstance.GetSlaveCom();
70    }
71
72    public static void Close() {
73      ClientComInstance.Close();
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.