Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Communication/3.3/ServiceLocator.cs @ 4337

Last change on this file since 4337 was 4337, checked in by cneumuel, 14 years ago

changed Slave.Core WCF-Proxy to stateless object

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Hive.Slave.Communication.SlaveService;
6using HeuristicLab.Hive.Contracts;
7using System.ServiceModel;
8using HeuristicLab.Hive.Slave.Communication.Properties;
9using HeuristicLab.Tracing;
10
11namespace HeuristicLab.Hive.Slave.Communication {
12  internal static class ServiceLocator {
13    /// <summary>
14    /// Cache of SlaveFacadeClients, to check if all get disposed
15    /// </summary>
16    private static List<ISlaveFacade> clientCache = new List<ISlaveFacade>();
17
18    internal static ISlaveFacade CreateSlaveFacade(string hostAddress) {
19      SlaveFacadeClient client = new SlaveFacadeClient("SlaveHttpEndpoint");
20      WcfSettings.SetEndpointAddress(client.Endpoint, hostAddress);
21      SetCredentials(client);
22      client.Open();
23      clientCache.Add(client);
24      Logger.Debug("Created SlaveFacadeClients. Currently existing SlaveFacadeClients: " + clientCache.Count);
25      return client;
26    }
27
28    internal static ISlaveFacade CreateStreamedSlaveFacade(string hostAddress) {
29      SlaveFacadeClient client = new SlaveFacadeClient("SlaveTcpStreamedEndpoint");
30      WcfSettings.SetEndpointAddress(client.Endpoint, hostAddress);
31      SetCredentials(client);
32      client.Open();
33      clientCache.Add(client);
34      Logger.Debug("Created SlaveFacadeClients. Currently existing SlaveFacadeClients: " + clientCache.Count);
35      return client;
36    }
37
38    private static void SetCredentials(SlaveFacadeClient client) {
39      client.ClientCredentials.UserName.UserName = Settings.Default.HiveUsername;
40      client.ClientCredentials.UserName.Password = Settings.Default.HivePassword;
41    }
42
43    public static void DisposeSlaveClient(ISlaveFacade slaveFacade) {
44      WcfSettings.DisposeWcfClient((ICommunicationObject)slaveFacade);
45      clientCache.Remove(slaveFacade);
46      Logger.Debug("Disposing SlaveFacadeClients. Currently existing SlaveFacadeClients: " + clientCache.Count);
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.