Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/07/13 16:30:39 (11 years ago)
Author:
ascheibe
Message:

#1886 added tasks and hive tasks for RunCollectionModifiers

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers
Files:
2 added
1 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers/RunCollectionModifierExecutable.cs

    r10113 r10114  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Text;
    2625using System.Threading;
    2726using System.Threading.Tasks;
    2827using HeuristicLab.Common;
    2928using HeuristicLab.Core;
    30 using HeuristicLab.Hive;
    3129using HeuristicLab.Optimization;
    3230using HeuristicLab.Parameters;
    3331using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3432
    35 namespace HeuristicLab.Analysis.SolutionCaching.RunCollectionModifiers {
    36   [Item("RunCollectionModifierTask", "An item that runs RunCollectionModifiers on RunCollections with Hive support.")]
     33namespace HeuristicLab.Analysis.SolutionCaching {
     34  [Item("RunCollectionModifierExecutable", "An executable that runs RunCollectionModifiers on RunCollections.")]
    3735  [StorableClass]
    38   public class RunCollectionModifierTask : ParameterizedNamedItem, ITask {
    39     public virtual bool IsParallelizable {
    40       get { return false; }
    41     }
    42 
    43     public virtual bool ComputeInParallel {
    44       get { return false; }
    45       set {
    46         throw new NotSupportedException("Parallelization is not supported for RunCollectionModifierTasks.");
    47       }
    48     }
    49 
     36  public class RunCollectionModifierExecutable : ParameterizedNamedItem, IExecutable {
    5037    [Storable]
    5138    protected ExecutionState executionState;
     
    10188
    10289    #region Constructors and Cloning
    103     public RunCollectionModifierTask() {
     90    public RunCollectionModifierExecutable() {
    10491      Parameters.Add(new ValueParameter<ItemList<IRunCollectionModifier>>("RunCollectionModifiers", "List of RunCollectionModifiers that are executed. ", new ItemList<IRunCollectionModifier>()));
    10592      executionStack = new Stack<IRunCollectionModifier>();
     
    10895    }
    10996    [StorableConstructor]
    110     protected RunCollectionModifierTask(bool deserializing) : base(deserializing) { }
    111     protected RunCollectionModifierTask(RunCollectionModifierTask original, Cloner cloner)
     97    protected RunCollectionModifierExecutable(bool deserializing) : base(deserializing) { }
     98    protected RunCollectionModifierExecutable(RunCollectionModifierExecutable original, Cloner cloner)
    11299      : base(original, cloner) {
    113100      executionTime = original.executionTime;
     
    121108    }
    122109    public override IDeepCloneable Clone(Cloner cloner) {
    123       return new RunCollectionModifierTask(this, cloner);
     110      return new RunCollectionModifierExecutable(this, cloner);
    124111    }
    125112    #endregion
     
    134121        executionStack.Push(runCollectionModifier);
    135122      }
    136 
    137       executionState = ExecutionState.Prepared;
    138123    }
    139124
     
    151136          }
    152137          catch (AggregateException remaining) {
    153             if (remaining.InnerExceptions.Count == 1) OnTaskFailed(remaining.InnerExceptions[0]);
    154             else OnTaskFailed(remaining);
     138            if (remaining.InnerExceptions.Count == 1) OnExceptionOccuted(remaining.InnerExceptions[0]);
     139            else OnExceptionOccuted(remaining);
    155140          }
    156141        }
     
    158143        cancellationTokenSource = null;
    159144        if (stopPending) executionStack.Clear();
    160         if (executionStack.Count == 0) OnTaskStopped();
    161         else OnTaskPaused();
     145        if (executionStack.Count == 0) OnStopped();
     146        else OnPaused();
    162147      });
    163148    }
     
    166151      if (ExecutionState == ExecutionState.Paused) {
    167152        executionStack.Clear();
    168         OnTaskStopped();
     153        OnStopped();
    169154      } else {
    170155        stopPending = true;
     
    179164    protected virtual void RunModifiers(object state) {
    180165      CancellationToken ct = (CancellationToken)state;
    181       OnTaskStarted();
     166      OnStarted();
    182167
    183168      IRunCollectionModifier next;
     
    197182
    198183    #region Events
    199     public event EventHandler TaskStarted;
    200     protected virtual void OnTaskStarted() {
     184    public event EventHandler Prepared;
     185    protected virtual void OnPrepared() {
     186      ExecutionState = ExecutionState.Prepared;
     187      EventHandler handler = Prepared;
     188      if (handler != null) handler(this, EventArgs.Empty);
     189    }
     190    public event EventHandler Started;
     191    protected virtual void OnStarted() {
    201192      executionState = ExecutionState.Started;
    202       EventHandler handler = TaskStarted;
    203       if (handler != null) handler(this, EventArgs.Empty);
    204     }
    205 
    206     public event EventHandler TaskStopped;
    207     protected virtual void OnTaskStopped() {
     193      EventHandler handler = Started;
     194      if (handler != null) handler(this, EventArgs.Empty);
     195    }
     196    public event EventHandler Stopped;
     197    protected virtual void OnStopped() {
    208198      executionState = ExecutionState.Stopped;
    209       EventHandler handler = TaskStopped;
    210       if (handler != null) handler(this, EventArgs.Empty);
    211     }
    212 
    213     public event EventHandler TaskPaused;
    214     protected virtual void OnTaskPaused() {
     199      EventHandler handler = Stopped;
     200      if (handler != null) handler(this, EventArgs.Empty);
     201    }
     202    public event EventHandler Paused;
     203    protected virtual void OnPaused() {
    215204      executionState = ExecutionState.Paused;
    216       EventHandler handler = TaskPaused;
    217       if (handler != null) handler(this, EventArgs.Empty);
    218     }
    219 
    220     public event EventHandler TaskFailed;
    221     protected virtual void OnTaskFailed(Exception e) {
     205      EventHandler handler = Paused;
     206      if (handler != null) handler(this, EventArgs.Empty);
     207    }
     208    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
     209    protected virtual void OnExceptionOccuted(Exception e) {
    222210      var eventArgs = new EventArgs<Exception>(e);
    223211      Log.LogException(e);
    224       EventHandler handler = TaskFailed;
     212      EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
    225213      if (handler != null) handler(this, eventArgs);
    226214    }
    227 
    228215    public event EventHandler ExecutionTimeChanged;
    229216    protected virtual void OnExecutionTimeChanged() {
     
    231218      if (handler != null) handler(this, EventArgs.Empty);
    232219    }
    233 
    234220    public event EventHandler ExecutionStateChanged;
    235221    protected virtual void OnExecutionStateChanged() {
     
    237223      if (handler != null) handler(this, EventArgs.Empty);
    238224    }
    239 
    240     public event EventHandler ComputeInParallelChanged; //not needed
    241225    #endregion
    242226  }
Note: See TracChangeset for help on using the changeset viewer.