Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/27/09 13:17:44 (15 years ago)
Author:
gkronber
Message:

Worked on hive engine. #545 (Engine which can be executed in the Hive)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Engine/HiveEngine.cs

    r1432 r1440  
    2525using HeuristicLab.Core;
    2626using System.Threading;
     27using HeuristicLab.Hive.JobBase;
     28using HeuristicLab.Hive.Contracts.Interfaces;
    2729
    2830namespace HeuristicLab.Hive.Engine {
     
    3133  /// in parallel.
    3234  /// </summary>
    33   public class HiveEngine : EngineBase, IEditable {
    34     private IOperator currentOperator;
     35  public class HiveEngine : ItemBase, IEngine, IEditable {
     36    private Job job;
     37    public string HiveServerUrl { get; set; }
    3538
    36     /// <summary>
    37     /// Creates a new instance of <see cref="HiveEngineEditor"/>.
    38     /// </summary>
    39     /// <returns>The created view as <see cref="HiveEngineEditor"/>.</returns>
     39    public HiveEngine() {
     40      job = new Job();
     41    }
     42
     43
     44    #region IEngine Members
     45
     46    public IOperatorGraph OperatorGraph {
     47      get { return job.Engine.OperatorGraph; }
     48    }
     49
     50    public IScope GlobalScope {
     51      get { return job.Engine.GlobalScope; }
     52    }
     53
     54    public TimeSpan ExecutionTime {
     55      get { return job.Engine.ExecutionTime; }
     56    }
     57
     58    public bool Running {
     59      get { return job.Engine.Running; }
     60    }
     61
     62    public bool Canceled {
     63      get { return job.Engine.Canceled; }
     64    }
     65
     66    public bool Terminated {
     67      get { return job.Engine.Terminated; }
     68    }
     69
     70    public void Execute() {
     71      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
     72      HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
     73      jobObj.SerializedJob = PersistenceManager.SaveToGZip(job);
     74      executionEngineFacade.AddJob(jobObj);
     75    }
     76
     77    public void ExecuteStep() {
     78      throw new NotSupportedException();
     79    }
     80
     81    public void ExecuteSteps(int steps) {
     82      throw new NotSupportedException();
     83    }
     84
     85    public void Abort() {
     86      throw new NotImplementedException();
     87    }
     88
     89    public void Reset() {
     90      throw new NotImplementedException();
     91    }
     92
     93    public event EventHandler Initialized;
     94
     95    public event EventHandler<OperationEventArgs> OperationExecuted;
     96
     97    public event EventHandler<ExceptionEventArgs> ExceptionOccurred;
     98
     99    public event EventHandler ExecutionTimeChanged;
     100
     101    public event EventHandler Finished;
     102
     103    #endregion
     104
     105    public void RequestSnapshot() {
     106      throw new NotImplementedException();
     107    }
     108
    40109    public override IView CreateView() {
    41110      return new HiveEngineEditor(this);
    42111    }
    43112
    44     /// <summary>
    45     /// Creates a new instance of <see cref="HiveEngineEditor"/>.
    46     /// </summary>
    47     /// <returns>The created editor as <see cref="HiveEngineEditor"/>.</returns>
    48     public virtual IEditor CreateEditor() {
     113    #region IEditable Members
     114
     115    public IEditor CreateEditor() {
    49116      return new HiveEngineEditor(this);
    50117    }
    51 
    52     /// <summary>
    53     /// Aborts the current operator.
    54     /// </summary>
    55     /// <remarks>Calls <see cref="EngineBase.Abort"/> of base class <see cref="EngineBase"/> and
    56     /// <see cref="IOperator.Abort"/> of the current <see cref="IOperator"/>.</remarks>
    57     public override void Abort() {
    58       base.Abort();
    59       if (currentOperator != null)
    60         currentOperator.Abort();
    61     }
    62 
    63     /// <summary>
    64     /// Deals with the next operation, if it is an <see cref="AtomicOperation"/> it is executed,
    65     /// if it is a <see cref="CompositeOperation"/> its single operations are pushed on the execution stack.
    66     /// </summary>
    67     /// <remarks>If an error occurs during the execution the operation is aborted and the operation
    68     /// is pushed on the stack again.<br/>
    69     /// If the execution was successful <see cref="EngineBase.OnOperationExecuted"/> is called.</remarks>
    70     protected override void ProcessNextOperation() {
    71       IOperation operation = myExecutionStack.Pop();
    72       if (operation is AtomicOperation) {
    73         AtomicOperation atomicOperation = (AtomicOperation)operation;
    74         IOperation next = null;
    75         try {
    76           currentOperator = atomicOperation.Operator;
    77           next = atomicOperation.Operator.Execute(atomicOperation.Scope);
    78         }
    79         catch (Exception ex) {
    80           // push operation on stack again
    81           myExecutionStack.Push(atomicOperation);
    82           Abort();
    83           ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex);});
    84         }
    85         if (next != null)
    86           myExecutionStack.Push(next);
    87         OnOperationExecuted(atomicOperation);
    88         if (atomicOperation.Operator.Breakpoint) Abort();
    89       } else if (operation is CompositeOperation) {
    90         CompositeOperation compositeOperation = (CompositeOperation)operation;
    91         for (int i = compositeOperation.Operations.Count - 1; i >= 0; i--)
    92           myExecutionStack.Push(compositeOperation.Operations[i]);
    93       }
    94     }
     118    #endregion
    95119  }
    96120}
Note: See TracChangeset for help on using the changeset viewer.