Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Clients.Hive.Slave.AzureClient/3.3/WorkerRole.cs @ 8251

Last change on this file since 8251 was 8251, checked in by spimming, 12 years ago

#1888:

  • Change hive server from service configuration file
  • Created service configuration settings for server address and certificate
  • Added HeuristicLab.Clients.Hive-3.3 project to solution
File size: 3.1 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;
23using System.Net;
24using System.Threading;
25using HeuristicLab.Clients.Hive.SlaveCore;
26using Microsoft.WindowsAzure.Diagnostics;
27using Microsoft.WindowsAzure.ServiceRuntime;
28
29namespace HeuristicLab.Clients.Hive.Slave.AzureClient {
30  public class WorkerRole : RoleEntryPoint {
31    private Core core;
32    private Thread coreThread;
33
34    private const string HiveServerAddressSetting = "HiveServerAddress";
35    private const string HiveServerCertificateSetting = "HiveServerCertifcateEncodedValue";
36
37    public override void Run() {
38      core = new Core(false);
39
40      string hiveServerAddress = RoleEnvironment.GetConfigurationSettingValue(HiveServerAddressSetting);
41      string hiveServerCertificate = RoleEnvironment.GetConfigurationSettingValue(HiveServerCertificateSetting);
42
43      // values are empty, settings from app.config are used
44      if (!string.IsNullOrEmpty(hiveServerAddress) && !string.IsNullOrEmpty(hiveServerCertificate)) {
45        core.SetNewHiveServer(hiveServerAddress, hiveServerCertificate);
46      }
47
48      coreThread = new Thread(core.Start);
49      coreThread.Start();
50
51      while (true) {
52        Thread.Sleep(10000);
53      }
54    }
55
56    public override bool OnStart() {
57      ServicePointManager.DefaultConnectionLimit = 12;
58      //core = new Core();
59      try {
60        if (!String.IsNullOrEmpty(RoleEnvironment.GetConfigurationSettingValue(Constants.DiagnosticsConnectionString))) {
61          DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
62          dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
63          dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
64          DiagnosticMonitor.Start(Constants.DiagnosticsConnectionString, dmc);
65        }
66      }
67      catch (RoleEnvironmentException ex) {
68        // diagnostics connection string not in configuration
69        // -> diagnostics disabled
70        // nothing more to do
71      }
72
73      RoleEnvironment.Changed += RoleEnvironmentChanged;
74
75      return base.OnStart();
76    }
77
78    public override void OnStop() {
79      core.Shutdown();
80      base.OnStop();
81    }
82
83    private void RoleEnvironmentChanged(object sender, RoleEnvironmentChangedEventArgs e) {
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.