Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/09 17:05:34 (15 years ago)
Author:
kgrading
Message:

part three of the awesome "FixTheBug!" Show (#529)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Core/Core.cs

    r1367 r1368  
    5151  /// </summary>
    5252  public class Core: MarshalByRefObject {
    53     public delegate string GetASnapshotDelegate();
    54     //Todo: private + getter/setter removen.
    55     public static Object Locker { get; set; }
    56     //Todo: ev. Rename to "abortRequested"
    57     public static bool ShutdownFlag { get; set; }
    58    
    59     //Todo: Access modifier
    60     Dictionary<long, Executor> engines = new Dictionary<long, Executor>();
    61     Dictionary<long, AppDomain> appDomains = new Dictionary<long, AppDomain>();
    62     Dictionary<long, Job> jobs = new Dictionary<long, Job>();
     53    //Todo: Ask wagner
     54    public static Object Locker { get; set; }   
     55    public static bool abortRequested { get; set; }
     56       
     57    private Dictionary<long, Executor> engines = new Dictionary<long, Executor>();
     58    private Dictionary<long, AppDomain> appDomains = new Dictionary<long, AppDomain>();
     59    private Dictionary<long, Job> jobs = new Dictionary<long, Job>();
    6360
    6461    private WcfService wcfService;
     
    7067    public void Start() {
    7168      Core.Locker = new Object();
    72       ShutdownFlag = false;
     69      abortRequested = false;
    7370
    7471      Logging.GetInstance().Info(this.ToString(), "Hive Client started");
     
    10198      //Main processing loop     
    10299      //Todo: own thread for message handling
    103       while (!ShutdownFlag) {
     100      //Rly?!
     101      while (!abortRequested) {
    104102        MessageContainer container = queue.GetMessage();
    105103        Debug.WriteLine("Main loop received this message: " + container.Message.ToString());
     
    113111    /// </summary>
    114112    /// <param name="container">The Container, containing the message</param>
    115     private void DetermineAction(MessageContainer container) {
    116       //Todo: Threads aus Threadpool verwenden
    117      
     113    private void DetermineAction(MessageContainer container) {           
    118114      switch (container.Message) {
    119115        //Server requests to abort a job
     
    131127        //Snapshot is ready and can be sent back to the Server
    132128        case MessageContainer.MessageType.SnapshotReady:
    133           Thread ssr = new Thread(new ParameterizedThreadStart(GetSnapshot));
    134           ssr.Start(container.JobId);         
     129          ThreadPool.QueueUserWorkItem(new WaitCallback(GetSnapshot), container.JobId);
     130          //Thread ssr = new Thread(new ParameterizedThreadStart(GetSnapshot));
     131          //ssr.Start(container.JobId);         
    135132          break;
    136133        //Pull a Job from the Server
     
    140137        //A Job has finished and can be sent back to the server
    141138        case MessageContainer.MessageType.FinishedJob:
    142           Thread finThread = new Thread(new ParameterizedThreadStart(GetFinishedJob));
    143           finThread.Start(container.JobId);         
     139          ThreadPool.QueueUserWorkItem(new WaitCallback(GetFinishedJob), container.JobId);
     140          //Thread finThread = new Thread(new ParameterizedThreadStart(GetFinishedJob));
     141          //finThread.Start(container.JobId);         
    144142          break;     
    145143        //Hard shutdown of the client
    146144        case MessageContainer.MessageType.Shutdown:
    147           ShutdownFlag = true;
     145          abortRequested = true;
    148146          beat.StopHeartBeat();
    149147          break;
     
    155153   
    156154    private void GetFinishedJob(object jobId) {
    157       long jId = (long)jobId;
    158       //Todo: Don't return null, throw exception!
    159       byte[] sJob = engines[jId].GetFinishedJob();
    160 
    161       if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin) {
    162         wcfService.ProcessJobResultAsync(ConfigManager.Instance.GetClientInfo().ClientId,
    163           jId,
    164           sJob,
    165           1,
    166           null,
    167           true);
    168       } else {
    169         //Todo: locking
    170         JobStorageManager.PersistObjectToDisc(wcfService.ServerIP, wcfService.ServerPort, jId, sJob);
    171         AppDomain.Unload(appDomains[jId]);
    172         appDomains.Remove(jId);
    173         engines.Remove(jId);
    174         jobs.Remove(jId);
     155      long jId = (long)jobId;     
     156      try {
     157        byte[] sJob = engines[jId].GetFinishedJob();
     158
     159        if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin) {
     160          wcfService.ProcessJobResultAsync(ConfigManager.Instance.GetClientInfo().ClientId,
     161            jId,
     162            sJob,
     163            1,
     164            null,
     165            true);
     166        } else {         
     167          JobStorageManager.PersistObjectToDisc(wcfService.ServerIP, wcfService.ServerPort, jId, sJob);
     168          lock (Core.Locker) {
     169            AppDomain.Unload(appDomains[jId]);
     170            appDomains.Remove(jId);
     171            engines.Remove(jId);
     172            jobs.Remove(jId);
     173          }
     174        }
     175      }
     176      catch (InvalidStateException ise) {
     177        Logging.GetInstance().Error(this.ToString(), "Exception: ", ise);
    175178      }
    176179    }
     
    224227      }
    225228    }
    226 
    227     //Todo: Remove intellgent stuff from the async event and move it to the main thread (message queue)
     229   
    228230    //Todo: Seperate this method into 2: Finished jobs and Snapshots
    229231    void wcfService_SendJobResultCompleted(object sender, ProcessJobResultCompletedEventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.