Free cookie consent management tool by TermsFeed Policy Generator

Changeset 816


Ignore:
Timestamp:
11/25/08 23:24:36 (16 years ago)
Author:
kgrading
Message:

implemented the persistance management (#390)

Location:
trunk/sources
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Common/Interfaces/IJob.cs

    r779 r816  
    11using System;
     2using HeuristicLab.Core;
    23namespace HeuristicLab.Hive.Client.Common {
    3   public interface IJob {
    4     System.Xml.XmlNode GetXmlNode();
     4  public interface IJob: IStorable {
    55    event EventHandler JobStopped;
    66    long JobId { get; set; }
    7     int Progress { get; set; }
     7    double Progress { get; set; }
    88    void Run();
    99    bool Running { get; set; }
  • trunk/sources/HeuristicLab.Hive.Client.Common/JobBase.cs

    r779 r816  
    3131namespace HeuristicLab.Hive.Client.Common {
    3232  [Serializable]
    33   abstract public class JobBase : IJob {
    34 
    35     public long JobId { get; set; }
     33  abstract public class JobBase : StorableBase, IJob {
    3634
    3735    private Thread thread = null;
     36    public event EventHandler JobStopped;
    3837   
    39     public int Progress { get; set; }
     38    public long JobId { get; set; }   
     39    public double Progress { get; set; }       
     40    public bool Running { get; set; }
    4041   
    41     protected bool abort = false;
    42     public bool Running { get; set; }
    43 
    44     public event EventHandler JobStopped;
     42    protected bool abort = false;   
    4543
    4644    abstract public void Run();
     
    6361    }
    6462
    65     public XmlNode GetXmlNode() {
    66       XmlDocument doc = PersistenceManager.CreateXmlDocument();
    67       return doc.CreateNode(XmlNodeType.Element, "testnode", null);     
     63    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     64      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     65
     66      XmlNode progr = document.CreateNode(XmlNodeType.Element, "Progress", null);
     67      progr.InnerText = Convert.ToString(Progress);
     68
     69      node.AppendChild(progr);
     70      return node;
     71    }
     72    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     73      base.Populate(node, restoredObjects);
     74
     75      XmlNode progr = node.SelectSingleNode("Progress");
     76      Progress = Convert.ToDouble(progr.InnerText);
    6877    }
    6978
  • trunk/sources/HeuristicLab.Hive.Client.Common/TestJob.cs

    r782 r816  
    2525using System.Text;
    2626using System.Diagnostics;
     27using System.Xml;
    2728
    2829namespace HeuristicLab.Hive.Client.Common {
    2930  [Serializable]
    3031  public class TestJob: JobBase {
     32
     33    private int runValue = 0;
     34
    3135    public override void Run() {
    32       for (int x = 0; x < 10; x++) {
     36      int max = 10;
     37      while(runValue < max && abort == false) {
    3338        for (int y = 0; y < Int32.MaxValue; y++) ;
    34         if (abort == true) {
    35           Logging.GetInstance().Info(this.ToString(), "Job Processing aborted");
    36           Debug.WriteLine("Job Abort Processing");
    37           break;
    38         }
    39         Logging.GetInstance().Info(this.ToString(), "Iteration " + x + " done");
    40         Debug.WriteLine("Iteration " + x + " done");
     39          if (abort == true) {
     40            Logging.GetInstance().Info(this.ToString(), "Job Processing aborted");
     41            Debug.WriteLine("Job Abort Processing");
     42           break;
     43          }
     44        runValue++;
     45        Progress = runValue / max;
     46        Logging.GetInstance().Info(this.ToString(), "Iteration " + runValue + " done");
     47        Debug.WriteLine("Iteration " + runValue + " done");
     48        Debug.WriteLine("Progress " + Progress*100 + " Percent");
    4149      }     
    4250      OnJobStopped();
    4351    }
     52    public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, HeuristicLab.Core.IStorable> persistedObjects) {     
     53      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     54   
     55      XmlNode startValue = document.CreateNode(XmlNodeType.Element, "StartValue", null);
     56      startValue.InnerText = Convert.ToString(runValue);
     57     
     58      node.AppendChild(startValue);
     59      return node;
     60    }
     61
     62    public override void Populate(XmlNode node, IDictionary<Guid, HeuristicLab.Core.IStorable> restoredObjects) {
     63      base.Populate(node, restoredObjects);
     64
     65      XmlNode startValue = node.SelectSingleNode("StartValue");
     66      runValue = Convert.ToInt32(startValue.InnerText);
     67    }
     68
     69
    4470  }
    4571}
  • trunk/sources/HeuristicLab.Hive.Client.Core/Core.cs

    r811 r816  
    3636using HeuristicLab.Hive.Contracts;
    3737using System.Runtime.Remoting.Messaging;
     38using HeuristicLab.PluginInfrastructure;
    3839
    3940
     
    140141    private void GetFinishedJob(object jobId) {
    141142      long jId = (long)jobId;
    142       String obj = engines[jId].GetFinishedJob();
    143       engines[jId].GetFinishedJob();
     143      byte[] obj = engines[jId].GetFinishedJob();
     144     
    144145      AppDomain.Unload(appDomains[jId]);
    145146      appDomains.Remove(jId);
     
    152153    private void GetSnapshot(object jobId) {
    153154      long jId = (long)jobId;
    154       String obj = engines[jId].GetSnapshot();
     155      byte[] obj = engines[jId].GetSnapshot();
    155156    }
    156157
     
    160161      IJob job = new TestJob { JobId = e.Result.JobId };
    161162
    162       AppDomain appDomain = CreateNewAppDomain(sandboxed);
     163      PluginManager pm = PluginManager.Manager;
     164      AppDomain appDomain =  pm.CreateAndInitAppDomain("AppDomain");
     165
     166      //AppDomain appDomain = CreateNewAppDomain(sandboxed);
    163167      appDomains.Add(job.JobId, appDomain);
    164168
    165169      Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    166       engine.Job = job;
    167170      engine.JobId = job.JobId;
    168171      engine.Queue = MessageQueue.GetInstance();
  • trunk/sources/HeuristicLab.Hive.Client.Core/CoreApplication.cs

    r735 r816  
    3131
    3232namespace HeuristicLab.Hive.Client.Core {
    33   [ClassInfo(Name = "Hive Client Core", Description = "Hive Client Core baseclass", AutoRestart = true)]
     33  [ClassInfo(Name = "Hive Client", Description = "Hive Client Core baseclass", AutoRestart = true)]
    3434  public class CoreApplication: ApplicationBase {
    3535    public override void Run() {
  • trunk/sources/HeuristicLab.Hive.Client.Core/HeuristicLab.Hive.Client.Core.csproj

    r790 r816  
    8282  </ItemGroup>
    8383  <ItemGroup>
     84    <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj">
     85      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
     86      <Name>HeuristicLab.Core</Name>
     87    </ProjectReference>
    8488    <ProjectReference Include="..\HeuristicLab.Hive.Client.Common\HeuristicLab.Hive.Client.Common.csproj">
    8589      <Project>{89F4BC52-C174-481E-9BD2-3814171020E8}</Project>
  • trunk/sources/HeuristicLab.Hive.Client.ExecutionEngine/Executor.cs

    r793 r816  
    2929using System.IO;
    3030using HeuristicLab.Hive.Contracts;
     31using HeuristicLab.Core;
    3132
    3233namespace HeuristicLab.Hive.Client.ExecutionEngine {
     
    5657    }
    5758
    58     public String GetSnapshot() {
     59    public byte[] GetSnapshot() {
    5960      //if the job is still running, something went VERY bad.
    6061      if (Job.Running) {
     
    6465        CurrentMessage = MessageContainer.MessageType.NoMessage;
    6566        // Pack the whole job inside an xml document
    66         String job = SerializeJobObject();       
     67        byte[] job = SerializeJobObject();       
    6768        // Restart the job
    6869        Job.Start();
     
    7273    }
    7374
    74     public String GetFinishedJob() {
     75    public byte[] GetFinishedJob() {
    7576      //Job isn't finished!
    7677      if (Job.Running) {
     
    8788    }
    8889
    89     private String SerializeJobObject() {
    90       XmlSerializer serializer = new XmlSerializer(typeof(TestJob));
    91       MemoryStream ms = new MemoryStream();
    92       serializer.Serialize(ms, Job);
    93       StreamReader reader = new StreamReader(ms);
    94       return reader.ReadToEnd();       
     90    private byte[] SerializeJobObject() {
     91      return PersistenceManager.SaveToGZip(Job);
    9592    }
    9693
    97     private void RestoreJobObject(String serializedJob) {
    98       System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
    99       XmlSerializer serializer = new XmlSerializer(typeof(TestJob));
    100       MemoryStream ms = new MemoryStream();
    101       ms.Write(encoding.GetBytes(serializedJob), 0, serializedJob.Length);
    102       Job = (TestJob) serializer.Deserialize(ms);     
     94    private void RestoreJobObject(byte[] sjob) {
     95      Job = (IJob)PersistenceManager.RestoreFromGZip(sjob);
    10396    }
    10497
    10598    public Executor() {
    10699      CurrentMessage = MessageContainer.MessageType.NoMessage;
     100      Job = new TestJob();
    107101    }   
    108102  }
  • trunk/sources/HeuristicLab.Hive.Client.ExecutionEngine/HeuristicLab.Hive.Client.ExecutionEngine.csproj

    r793 r816  
    5757  </ItemGroup>
    5858  <ItemGroup>
     59    <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj">
     60      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
     61      <Name>HeuristicLab.Core</Name>
     62    </ProjectReference>
    5963    <ProjectReference Include="..\HeuristicLab.Hive.Client.Common\HeuristicLab.Hive.Client.Common.csproj">
    6064      <Project>{89F4BC52-C174-481E-9BD2-3814171020E8}</Project>
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r811 r816  
    1414    List<ClientInfo> clients;
    1515    LinkedList<long> jobs;
    16     int nrOfJobs = 3;
     16    int nrOfJobs = 1;
    1717
    1818    public ClientCommunicator() {
Note: See TracChangeset for help on using the changeset viewer.