Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server/3.3/HeuristicLabHiveServerApplication.cs @ 4423

Last change on this file since 4423 was 4423, checked in by cneumuel, 14 years ago
  • Refactored HL.Hive.Experiment. JobItems are not called HiveJobs and OptimizerJobs do not contain a hierarchy anymore.
  • Dynamic generation of jobs on a slave are not reflected on the client user interface.
  • Optimizer-Trees are now strictly synchronized with the HiveJob-Trees (also the ComputeInParallel property is taken into account when the Child HiveJobs are created)
  • Improved the way a class can report progress and lock the UI (IProgressReporter, IProgress, Progress, ProgressView)
  • Changes were made to the config-files, so that server and clients work with blade12.hpc.fh-hagenberg.at
  • Lots of small changes and bugfixes
File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.Linq;
25using System.Net;
26using System.ServiceModel;
27using System.ServiceModel.Description;
28using System.Windows.Forms;
29using HeuristicLab.Hive.Contracts;
30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.PluginInfrastructure;
32using HeuristicLab.Hive.Server.Core;
33
34namespace HeuristicLab.Hive.Server {
35  [Application("Hive Server", "Server application for the distributed hive engine.", false)]
36  public class HeuristicLabHiveServerApplication : ApplicationBase {
37    private IDictionary<string, ServiceHost> serviceHosts = new Dictionary<string, ServiceHost>();
38    ILifecycleManager lifecycleManager = null;
39
40    public override void Run() {
41      try {
42        CreateAndOpenServiceHost(typeof(ISlaveFacade), WcfSettings.SlaveServiceName);
43        CreateAndOpenServiceHost(typeof(IServerConsoleFacade), WcfSettings.ServerConsoleServiceName);
44        CreateAndOpenServiceHost(typeof(IClientFacade), WcfSettings.ClientServiceName);
45
46        lifecycleManager = ServiceLocator.GetLifecycleManager();
47        lifecycleManager.Start();
48
49        Form mainForm = new MainForm(GetBaseAddresses());
50        Application.Run();
51       
52      } finally {
53        foreach (ServiceHost host in serviceHosts.Values) {
54          if (host.State == CommunicationState.Opened)
55            host.Close();
56        }
57        if (lifecycleManager != null)
58          lifecycleManager.Stop();
59      }
60    }
61
62    private ServiceHost CreateAndOpenServiceHost(Type serviceInterfaceType, string serviceName) {
63      try {
64        ServiceHost host = new ServiceHost(ApplicationManager.Manager.GetTypes(serviceInterfaceType).First());
65        host.Open();
66        serviceHosts.Add(serviceName, host);
67        return host;
68      }
69      catch (AddressAccessDeniedException ex) {
70        throw new Exception("Unable to start WCF-Services due to missing rights. Run the following command as administrator: \"netsh http add urlacl url=http://+:" + WcfSettings.DefaultPort + "/ user=MYMACHINE\\UserName\". See inner exception for more details.", ex);
71      }
72    }
73
74    private IEnumerable<Uri> GetBaseAddresses() {
75      List<Uri> list = new List<Uri>();
76      foreach (KeyValuePair<string, ServiceHost> host in serviceHosts) {
77        foreach (var addr in host.Value.BaseAddresses) {
78          list.Add(addr);
79        }
80      }
81      return list;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.