- Timestamp:
- 10/18/14 03:25:58 (10 years ago)
- Location:
- branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmServiceNode.cs
r11468 r11481 25 25 using System; 26 26 using System.Collections.Generic; 27 using System.Linq; 27 28 using System.Threading; 28 using System.Linq;29 29 30 30 namespace HeuristicLab.Optimization.Networks { … … 34 34 private object locker = new object(); 35 35 private Dictionary<IAlgorithm, AutoResetEvent> waitHandles = new Dictionary<IAlgorithm,AutoResetEvent>(); 36 private Dictionary<IAlgorithm, Exception> exceptions = new Dictionary<IAlgorithm, Exception>(); 36 37 37 38 new public PortCollection Ports { … … 118 119 algorithm.Runs.Clear(); 119 120 algorithm.Prepare(); 121 algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred; 120 122 algorithm.Stopped += Algorithm_Stopped; 121 algorithm.Start(); 122 if (WaitHandle.WaitAny(new WaitHandle[] { waitHandles[algorithm], token.WaitHandle }) == 1) { 123 // retrieve results 124 foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) { 125 IResult result = null; 126 if (algorithm.Results.TryGetValue(p.Name, out result)) { 127 p.Value = result.Value; 128 } 129 } 130 131 lock (locker) { 132 waitHandles[algorithm].Dispose(); 133 waitHandles.Remove(algorithm); 134 Runs.Add(algorithm.Runs.ToArray()[0]); 135 } 136 } else { // cancellation 137 algorithm.Stop(); 138 lock (locker) { 139 waitHandles[algorithm].Dispose(); 140 waitHandles.Remove(algorithm); 141 } 142 } 143 } 144 123 124 using (token.Register(() => { algorithm.Stop(); })) { 125 algorithm.Start(); 126 waitHandles[algorithm].WaitOne(); 127 } 128 129 lock (locker) { 130 waitHandles[algorithm].Dispose(); 131 waitHandles.Remove(algorithm); 132 133 Exception ex = null; 134 if (exceptions.TryGetValue(algorithm, out ex)) { 135 exceptions.Remove(algorithm); 136 throw ex; 137 } 138 } 139 140 // retrieve results 141 var run = algorithm.Runs.First(); 142 foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) { 143 IItem result = null; 144 if (run.Results.TryGetValue(p.Name, out result)) { 145 p.Value = result; 146 } 147 } 148 149 lock (locker) { 150 Runs.Add(run); 151 } 152 } 153 154 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 155 var algorithm = (IAlgorithm)sender; 156 lock (locker) { 157 exceptions.Add(algorithm, e.Value); 158 } 159 algorithm.Stop(); 160 } 145 161 private void Algorithm_Stopped(object sender, EventArgs e) { 146 162 lock (locker) { -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/ClientNode.cs
r11468 r11481 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 using System; 26 using System.Collections.Generic; 25 using System.Linq; 27 26 using System.Threading; 28 using System.Linq;29 27 using System.Threading.Tasks; 30 28 … … 69 67 70 68 public virtual async Task CallServicesAsync() { 71 await CallServicesAsync( new CancellationToken());69 await CallServicesAsync(CancellationToken.None); 72 70 } 73 71 public virtual async Task CallServicesAsync(CancellationToken token) { -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/ClientPort.cs
r11468 r11481 107 107 return true; 108 108 } 109 public void CloneServicePortParameters() { 110 Parameters.Clear(); 111 foreach (var p in servicePort.Parameters) { 112 Parameters.Add((IServiceParameter)p.Clone()); 113 } 114 } 109 115 public ServiceParameterCollection PrepareParameters() { 110 116 if (!Valid) throw new InvalidOperationException("Port configurations do not match"); -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IClientPort.cs
r11468 r11481 32 32 33 33 bool IsValidServicePort(IServicePort servicePort); 34 void CloneServicePortParameters(); 34 35 ServiceParameterCollection PrepareParameters(); 35 36 ServiceParameterCollection CallService(ServiceParameterCollection parameters); -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/ServicePort.cs
r11468 r11481 43 43 44 44 public ServiceParameterCollection Process(ServiceParameterCollection parameters) { 45 return Process(parameters, new CancellationToken());45 return Process(parameters, CancellationToken.None); 46 46 } 47 47 public ServiceParameterCollection Process(ServiceParameterCollection parameters, CancellationToken token) { … … 49 49 } 50 50 public async Task<ServiceParameterCollection> ProcessAsync(ServiceParameterCollection parameters) { 51 return await ProcessAsync(parameters, new CancellationToken());51 return await ProcessAsync(parameters, CancellationToken.None); 52 52 } 53 53 public async Task<ServiceParameterCollection> ProcessAsync(ServiceParameterCollection parameters, CancellationToken token) {
Note: See TracChangeset
for help on using the changeset viewer.