Free cookie consent management tool by TermsFeed Policy Generator

Changeset 779 for trunk/sources


Ignore:
Timestamp:
11/19/08 16:08:44 (16 years ago)
Author:
kgrading
Message:

Continued work on ticket (#365) + created a Job Interface

Location:
trunk/sources
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Common/HeuristicLab.Hive.Client.Common.csproj

    r768 r779  
    6666  <ItemGroup>
    6767    <Compile Include="CommonPlugin.cs" />
     68    <Compile Include="Interfaces\IJob.cs" />
    6869    <Compile Include="JobBase.cs" />
    6970    <Compile Include="Logging.cs" />
  • trunk/sources/HeuristicLab.Hive.Client.Common/JobBase.cs

    r770 r779  
    2727using System.Xml;
    2828using HeuristicLab.Core;
     29using HeuristicLab.Hive.Client.Common;
    2930
    3031namespace HeuristicLab.Hive.Client.Common {
    3132  [Serializable]
    32   abstract public class JobBase {
     33  abstract public class JobBase : IJob {
     34
     35    public long JobId { get; set; }
    3336
    3437    private Thread thread = null;
  • trunk/sources/HeuristicLab.Hive.Client.Common/TestJob.cs

    r770 r779  
    2424using System.Linq;
    2525using System.Text;
     26using System.Diagnostics;
    2627
    2728namespace HeuristicLab.Hive.Client.Common {
     
    3334        if (abort == true) {
    3435          Logging.getInstance().Info(this.ToString(), "Job Processing aborted");
    35           //Console.WriteLine("Job Abort Processing");
     36          Debug.WriteLine("Job Abort Processing");
    3637          break;
    3738        }
    3839        Logging.getInstance().Info(this.ToString(), "Iteration " + x + " done");
    39         //Console.WriteLine("Iteration " + x + " done");
     40        Debug.WriteLine("Iteration " + x + " done");
    4041      }     
    4142      OnJobStopped();
  • trunk/sources/HeuristicLab.Hive.Client.Core/Core.cs

    r770 r779  
    5858    }
    5959
    60     public void Start() {
    61       Logging.getInstance().Info(this.ToString(), "Info Message");
    62       //Logging.getInstance().Error(this.ToString(), "Error Message");
    63       //Logging.getInstance().Error(this.ToString(), "Exception Message", new Exception("Exception"));     
    64 
     60    public void Start() {     
    6561      Heartbeat beat = new Heartbeat();
    6662      beat.Interval = 5000;
     
    6864
    6965      MessageQueue queue = MessageQueue.GetInstance();
    70      
    71       TestJob job = new TestJob();
    72 
    73       AppDomain appDomain = CreateNewAppDomain(false);
    74      
    75       //This is a HACK. remove static directory ASAP
    76       //Executor engine = (Executor)appDomain.CreateInstanceFromAndUnwrap(@"C:\Program Files\HeuristicLab 3.0\plugins\HeuristicLab.Hive.Client.ExecutionEngine-3.2.dll", "HeuristicLab.Hive.Client.ExecutionEngine.Executor");
    77      
    78       Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    79       //ExecutionEngine.Executor engine = new ExecutionEngine.Executor();
    80       engine.Job = job;
    81       engine.JobId = 1L;
    82       engine.Queue = queue;     
    83       engine.Start();
    84       engines.Add(engine.JobId, engine);
    85 
    86       Thread.Sleep(15000);
    87       engine.RequestSnapshot();
     66      queue.AddMessage(MessageContainer.MessageType.FetchJob);     
    8867      while (true) {
    8968        MessageContainer container = queue.GetMessage();
     69        Debug.WriteLine("Main loop received this message: " + container.Message.ToString());
    9070        Logging.getInstance().Info(this.ToString(), container.Message.ToString());
    9171        DetermineAction(container);
    92 
    93        
    9472      }
    95     }
    96 
    97     Assembly appDomain_TypeResolve(object sender, ResolveEventArgs args) {
    98       throw new NotImplementedException();
    9973    }
    10074
     
    11690
    11791    private void DetermineAction(MessageContainer container) {
    118       if(container.Message == MessageContainer.MessageType.AbortJob)
    119         engines[container.JobId].Abort();
    120       else if (container.Message == MessageContainer.MessageType.JobAborted)
    121         //kill appdomain
    122         Console.WriteLine("tmp");
    123       else if (container.Message == MessageContainer.MessageType.RequestSnapshot)
    124         engines[container.JobId].RequestSnapshot();
    125       else if (container.Message == MessageContainer.MessageType.SnapshotReady)
    126         // must be async!
    127         engines[container.JobId].GetSnapshot();
    128     }       
     92      switch (container.Message) {
     93        case MessageContainer.MessageType.AbortJob:
     94          engines[container.JobId].Abort();
     95          break;
     96        case MessageContainer.MessageType.JobAborted:
     97          Debug.WriteLine("-- Job Aborted Message received");
     98          break;
     99       
     100       
     101        case MessageContainer.MessageType.RequestSnapshot:
     102          engines[container.JobId].RequestSnapshot();
     103          break;
     104        case MessageContainer.MessageType.SnapshotReady:
     105          engines[container.JobId].GetSnapshot();
     106          break;
     107       
     108       
     109        case MessageContainer.MessageType.FetchJob:
     110          IJob job = CreateNewJob();
     111         
     112          AppDomain appDomain = CreateNewAppDomain(false);
     113          appDomains.Add(job.JobId, appDomain);
     114         
     115          Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
     116          engine.Job = job;
     117          engine.JobId = job.JobId;
     118          engine.Queue = MessageQueue.GetInstance();
     119          engine.Start();
     120          engines.Add(engine.JobId, engine);
     121          break;
     122
     123        case MessageContainer.MessageType.FinishedJob:
     124          engines[container.JobId].GetFinishedJob();
     125          AppDomain.Unload(appDomains[container.JobId]);
     126          appDomains.Remove(container.JobId);
     127          engines.Remove(container.JobId);
     128          break;
     129
     130      }
     131    }
     132   
     133    /// <summary>
     134    /// Simulator Class for new Jobs. will be replaced with fetching Jobs from the Interface
     135    /// </summary>
     136    /// <returns></returns>
     137    private IJob CreateNewJob() {
     138      Random random = new Random();
     139      IJob job = new TestJob();
     140      job.JobId = random.Next();
     141      return job;
     142    }
    129143  }
    130144}
  • trunk/sources/HeuristicLab.Hive.Client.ExecutionEngine/Executor.cs

    r771 r779  
    3232  public class Executor: MarshalByRefObject {
    3333    public long JobId { get; set; }
    34     public TestJob Job { get; set; }
     34    public IJob Job { get; set; }
    3535    public MessageContainer.MessageType CurrentMessage { get; set; }
    3636    public MessageQueue Queue { get; set; }
     
    5555    }
    5656
    57     public XmlNode GetSnapshot() {
     57    public String GetSnapshot() {
    5858      //if the job is still running, something went VERY bad.
    5959      if (Job.Running) {
     
    6363        CurrentMessage = MessageContainer.MessageType.NoMessage;
    6464        // Pack the whole job inside an xml document
    65         String job = SerializeJobObject();
    66         XmlNode node = Job.GetXmlNode();       
     65        String job = SerializeJobObject();       
    6766        // Restart the job
    6867        Job.Start();
    6968        // Return the Snapshot
    70         return node;
     69        return job;
    7170      }
    7271    }
    7372
    74     public XmlNode GetFinishedJob() {
     73    public String GetFinishedJob() {
    7574      //Job isn't finished!
    7675      if (Job.Running) {
    7776        return null;
    7877      } else {
    79         return Job.GetXmlNode();
     78        return SerializeJobObject();
    8079      }
    8180    }
Note: See TracChangeset for help on using the changeset viewer.