Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Clients.Hive.Slave/3.3/PipeCom.cs @ 10180

Last change on this file since 10180 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: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.ServiceModel;
23using HeuristicLab.Clients.Hive.SlaveCore.Properties;
24using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
25
26namespace HeuristicLab.Clients.Hive.SlaveCore {
27  public class PipeCom : IClientCom {
28    private static DuplexChannelFactory<ISlaveCommunication> pipeFactory;
29    private ISlaveCommunication clientCom;
30
31    public PipeCom() {
32      SetupClientCom();
33    }
34
35    public ISlaveCommunication GetSlaveCom() {
36      return clientCom;
37    }
38
39    private void SetupClientCom() {
40      DummyListener dummy = new DummyListener();
41      try {
42        pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, Settings.Default.SlaveCommunicationServiceEndpoint);
43
44      }
45      catch {
46        EventLogManager.LogMessage("Couldn't create pipe for SlaveClientCom with config!");
47
48        try {
49          pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/HeuristicLabSlaveCom"));
50        }
51        catch {
52          EventLogManager.LogMessage("Couldn't create pipe for SlaveClientCom with fixed addresse!");
53          return;
54        }
55      }
56      pipeFactory.Faulted += new System.EventHandler(pipeFactory_Faulted);
57
58      ISlaveCommunication pipeProxy = pipeFactory.CreateChannel();
59      clientCom = pipeProxy;
60    }
61
62    void pipeFactory_Faulted(object sender, System.EventArgs e) {
63      EventLogManager.LogMessage("SlaveClientCom just faulted. Trying to repair it...");
64
65      try {
66        pipeFactory.Faulted -= new System.EventHandler(pipeFactory_Faulted);
67        SetupClientCom();
68      }
69      catch { }
70    }
71
72    public void Close() {
73      if (pipeFactory.State != CommunicationState.Closed && pipeFactory.State != CommunicationState.Faulted)
74        pipeFactory.Close();
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.