Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/05/12 17:39:12 (12 years ago)
Author:
spimming
Message:

#1888:

  • slave worker role initial commit
  • start client communication service optionally
  • make slave client communication interchangeable ('PipeCom', 'TraceCom')
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OaaS/HeuristicLab.Clients.Hive.Slave/3.3/SlaveClientCom.cs

    r7259 r8242  
    2020#endregion
    2121
    22 using System.ServiceModel;
     22using System;
    2323using HeuristicLab.Clients.Hive.SlaveCore.Properties;
    2424using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
    25 using System;
    2625
    2726namespace HeuristicLab.Clients.Hive.SlaveCore {
     27
     28  public enum ClientComType { Pipe, Trace };
    2829
    2930  /// <summary>
     
    3233  public class SlaveClientCom {
    3334    private static SlaveClientCom instance;
    34     private static DuplexChannelFactory<ISlaveCommunication> pipeFactory;
     35    //private static DuplexChannelFactory<ISlaveCommunication> pipeFactory;
     36    private static IClientCom clientComInstance;
    3537    public ISlaveCommunication ClientCom { get; set; }
    3638
     
    4547        }
    4648        return instance;
     49      }
     50    }
     51
     52    public static IClientCom ClientComInstance {
     53      get {
     54        if (clientComInstance != null) {
     55          return clientComInstance;
     56        }
     57        throw new NullReferenceException("No instance of SlaveClientCom<T>");
    4758      }
    4859    }
     
    6778
    6879    private SlaveClientCom() {
    69       SetupClientCom();
    70     }
     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");
     87      }
    7188
    72     private void SetupClientCom() {
    73       DummyListener dummy = new DummyListener();
    74       try {
    75         pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, Settings.Default.SlaveCommunicationServiceEndpoint);
    76       }
    77       catch {
    78         EventLogManager.LogMessage("Couldn't create pipe for SlaveClientCom with config!");
    79 
    80         try {
    81           pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/HeuristicLabSlaveCom"));
    82         }
    83         catch {
    84           EventLogManager.LogMessage("Couldn't create pipe for SlaveClientCom with fixed addresse!");
    85           return;
    86         }
    87       }
    88       pipeFactory.Faulted += new System.EventHandler(pipeFactory_Faulted);
    89 
    90       ISlaveCommunication pipeProxy = pipeFactory.CreateChannel();
    91       ClientCom = pipeProxy;
    92     }
    93 
    94     void pipeFactory_Faulted(object sender, System.EventArgs e) {
    95       EventLogManager.LogMessage("SlaveClientCom just faulted. Trying to repair it...");
    96 
    97       try {
    98         pipeFactory.Faulted -= new System.EventHandler(pipeFactory_Faulted);
    99         SetupClientCom();
    100       }
    101       catch { }
     89      ClientCom = clientComInstance.GetSlaveCom();
    10290    }
    10391
    10492    public static void Close() {
    105       if (pipeFactory.State != CommunicationState.Closed && pipeFactory.State != CommunicationState.Faulted)
    106         pipeFactory.Close();
     93      ClientComInstance.Close();
    10794    }
    10895  }
Note: See TracChangeset for help on using the changeset viewer.