#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using HeuristicLab.Clients.Hive.SlaveCore.MultiSlavesRunner.Properties;
namespace HeuristicLab.Clients.Hive.SlaveCore.MultiSlavesRunner {
public class Program {
static void Main(string[] args) {
EventLog eventLog = null;
try {
if (!System.Diagnostics.EventLog.SourceExists("HLHive")) {
System.Diagnostics.EventLog.CreateEventSource("HLHive", "HiveSlave");
}
eventLog = new EventLog();
eventLog.Source = "HLHive";
eventLog.Log = "HiveSlave";
}
catch (Exception) { }
var cores = new List();
Parallel.For(0, Settings.Default.NumberOfSlaves, i => {
string appName = "Hive Slave #" + i;
AppDomain applicationDomain = AppDomain.CreateDomain(appName);
var coreType = typeof(Core);
Console.WriteLine("Create core #" + i);
var core = (Core)applicationDomain.CreateInstanceAndUnwrap(coreType.Assembly.FullName, coreType.FullName);
core.ServiceEventLog = eventLog;
cores.Add(core);
});
Parallel.For(0, cores.Count, i => {
var core = cores[i];
var coreThread = new Thread(core.Start) {
IsBackground = true
};
Console.WriteLine("Start core #" + i);
coreThread.Start();
});
Console.WriteLine("Waiting for cores to start...");
Thread.Sleep(10000);
//mock a slave client
SlaveCommListener listener = new SlaveCommListener();
listener.Open();
Console.WriteLine("Press a key to quit");
Console.ReadLine();
//Environment.Exit(0); // quick shutdown ...
listener.Close();
foreach (var core in cores) {
try {
core.Shutdown();
}
catch (Exception) { }
}
Console.ReadLine();
}
}
}