Last change
on this file since 17013 was
17013,
checked in by dpiringe, 5 years ago
|
#2924:
- some changes in CLIApplication.cs to reduce unnecessary allocation of string objects
- renamed AppTest to ConsoleOptimizer and fixed race condition
- replaced enum RunnerJob with class RunnerMessage for more control of saved data
- changed usage of BinaryFormatter with HEAL.Attic, following types are now Storable:
- ConsoleOptimizer
- InspectApplication
- ApplicationBase
- ApplicationRunner
- AssemblyInfo
- Runner
- UniPath
- RunnerMessage
- switched QuietMode from ApplicationRunner to IRunner
- DockerRunnerHost can now automatically build docker images for linux and windows containers (also identifies which container type is active) -> removes the condition to have the image preinstalled
- to achieve this, there are two new folders DockerLinuxBuild and DockerWindowsBuild included in build output, which include Dockerfiles to build images for linux and windows container
- added NuGet package System.CodeDom to project HeuristicLab.Scripting-3.3
- added method Send(RunnerMessage) to IRunnerHost and transferred methods Pause and Resume to IRunner
- added internal reference of RunnerHost in Runner
- added abstract method SendMessage(RunnerMessage) in RunnerHost which gets called from method Send(RunnerMessage)
- because of a Google.Protobuf "bug", RunnerMessages cannot get serialized/deserialized directly on stream -> workaround with a byte array, which gets written and read
- additionally, the length of the array gets sent first (length as integer -> 4 bytes)
- static method in RunnerMessage to read a message from a stream
- the method SendMessage(RunnerMessage) in RunnerHost implements this functionality
|
File size:
1.7 KB
|
Rev | Line | |
---|
[17013] | 1 | using HEAL.Attic;
|
---|
[16984] | 2 |
|
---|
| 3 | namespace HeuristicLab.PluginInfrastructure {
|
---|
[17013] | 4 | [StorableType("612F98AF-E254-4C5E-BD41-75B4F1D9B96D")]
|
---|
[16984] | 5 | public class ApplicationRunner : Runner {
|
---|
| 6 | /// <summary>
|
---|
| 7 | /// Arguments for the StartApplication.
|
---|
| 8 | /// </summary>
|
---|
[17013] | 9 | [Storable]
|
---|
[16984] | 10 | public ICommandLineArgument[] Args { get; set; }
|
---|
| 11 |
|
---|
| 12 | /// <summary>
|
---|
| 13 | /// The application which should run in child process.
|
---|
| 14 | /// </summary>
|
---|
| 15 | public IApplication StartApplication {
|
---|
| 16 | get {
|
---|
[17013] | 17 | lock (locker) {
|
---|
| 18 | if (application == null)
|
---|
| 19 | application = (IApplication)new ProtoBufSerializer().Deserialize(serializedStartApplication);
|
---|
| 20 | return application;
|
---|
[16984] | 21 | }
|
---|
| 22 | }
|
---|
| 23 | set {
|
---|
[17013] | 24 | lock (locker) {
|
---|
| 25 | serializedStartApplication = new ProtoBufSerializer().Serialize(value);
|
---|
| 26 | application = value;
|
---|
[16984] | 27 | }
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | // Encapsulated application is necessary, because it is not possible to
|
---|
| 31 | // instantly deserialize the application, before all assemblies are loaded.
|
---|
[17013] | 32 | [Storable]
|
---|
[16984] | 33 | private byte[] serializedStartApplication = new byte[0];
|
---|
[17013] | 34 |
|
---|
[16993] | 35 | // cache application to prevent new instances every get call of StartApplication
|
---|
| 36 | private IApplication application;
|
---|
[17013] | 37 | private object locker = new object();
|
---|
[16984] | 38 |
|
---|
| 39 | protected override void Execute() {
|
---|
| 40 | StartApplication.Run(Args);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[17013] | 43 | protected override void OnRunnerMessage(RunnerMessage message) {
|
---|
| 44 | if (message is PauseRunnerMessage)
|
---|
| 45 | StartApplication.OnPause();
|
---|
| 46 | else if (message is ResumeRunnerMessage)
|
---|
| 47 | StartApplication.OnResume();
|
---|
| 48 | else if (message is CancelRunnerMessage)
|
---|
| 49 | StartApplication.OnCancel();
|
---|
[16984] | 50 | }
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.