Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/WcfServicePool.cs @ 5153

Last change on this file since 5153 was 5153, checked in by cneumuel, 13 years ago

#1260

  • increased timeouts for sent jobs (which are needed if the jobs take long time to deserialize on slave)
  • added DeleteJob to ClientService
  • made optimizer actually Pause instead of Stop when stop is called explicitly (so they can be resumed later)
  • temporarily disabled job-abortion from server because it aborted jobs which took too long to deserialize on slaves (this issue needs to be investigated)
  • reduced locking of engines on slave so that the deserialization does not block heartbeats

#1347

  • worked on HiveEngine
  • added test project for HiveEngine
File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 System.ServiceModel;
24using HeuristicLab.Common;
25using HeuristicLab.Hive.Tracing;
26using HeuristicLab.Clients.Common;
27using HeuristicLab.Hive.Contracts.Interfaces;
28
29namespace HeuristicLab.Hive.Contracts {
30  public class WcfServicePool<T> where T : class {
31    private static object locker = new object();
32
33    private string hostAddress;
34    public string HostAddress {
35      get { return hostAddress; }
36      set { hostAddress = value; }
37    }
38    private string userName;
39    public string UserName {
40      get { return userName; }
41      set { userName = value; }
42    }
43    private string password;
44    public string Password {
45      get { return password; }
46      set { password = value; }
47    }
48
49    private string endpointName;
50
51    public WcfServicePool(string endpointName) {
52      this.endpointName = endpointName;
53    }
54    public WcfServicePool(string hostAddress, string endpointName) : this(endpointName) {
55      this.hostAddress = hostAddress;
56    }
57    public WcfServicePool(string endpointName, string userName, string password) : this(endpointName) {
58      this.userName = userName;
59      this.password = password;
60    }
61
62    public Disposable<T> GetService() {
63      try {
64        if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) {
65          return ClientFactory.CreateClient<T>(endpointName, hostAddress, userName, password);
66        } else {
67          return ClientFactory.CreateClient<T>(endpointName, hostAddress);
68        }
69      }
70      catch (EndpointNotFoundException ex) {
71        OnExceptionOccured(ex);
72      }
73      return null;
74    }
75
76    public event EventHandler<EventArgs<Exception>> ExceptionOccured;
77    private void OnExceptionOccured(Exception e) {
78      lock (locker) {
79        var handler = ExceptionOccured;
80        if (handler != null) handler(this, new EventArgs<Exception>(e));
81      }
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.