Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2068 for trunk/sources


Ignore:
Timestamp:
06/19/09 13:38:20 (15 years ago)
Author:
kgrading
Message:

added various comments (#467)

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Communication/3.2/WcfService.cs

    r2063 r2068  
    278278    /// Send back finished and Stored Job Results
    279279    /// </summary>
    280     /*#region SendJobResults
    281     public event System.EventHandler<StoreFinishedJobResultCompletedEventArgs> ProcessStoredJobResultCompleted;
    282     public void ProcessStoredJobResultAsync(Guid clientId, long jobId, byte[] result, double percentage, Exception exception, bool finished) {
    283       if (ConnState == NetworkEnum.WcfConnState.Loggedin)
    284         //TODO: some sort of algo for the stored jobs
    285         proxy.ProcessJobResultAsync(clientId, jobId, result, percentage, exception, finished);
    286     } 
    287     #endregion  */
    288 
    289280    private Stream GetStreamedJobResult(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception) {
    290281      JobResult jobResult =
  • trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs

    r2063 r2068  
    173173          break;     
    174174       
    175        
     175
     176        //When the timeslice is up
    176177        case MessageContainer.MessageType.UptimeLimitDisconnect:
    177178          Logging.Instance.Info(this.ToString(), "Uptime Limit reached, storing jobs and sending them back");
     
    211212    #region Async Threads for the EE
    212213   
     214    /// <summary>
     215    /// serializes the finished job and submits it to the server. If, at the time, a network connection is unavailable, the Job gets stored on the disk.
     216    /// once the connection gets reestablished, the job gets submitted
     217    /// </summary>
     218    /// <param name="jobId"></param>
    213219    private void GetFinishedJob(object jobId) {
    214220      Guid jId = (Guid)jobId;     
     
    255261      //Uptime Limit reached, now is a good time to destroy this jobs.
    256262      if (!UptimeManager.Instance.isOnline()) {
    257         lock (engines) {
    258           appDomains[jId].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
    259           AppDomain.Unload(appDomains[jId]);
    260           appDomains.Remove(jId);
    261           engines.Remove(jId);
    262           jobs.Remove(jId);
    263         }
    264         GC.Collect();
    265 
     263        KillAppDomain(jId);       
    266264        //Still anything running?
    267265        if (engines.Count == 0)
     
    277275    //Eventhandlers for the communication with the wcf Layer
    278276    #region wcfService Events
    279 
     277    /// <summary>
     278    /// Login has returned
     279    /// </summary>
     280    /// <param name="sender"></param>
     281    /// <param name="e"></param>
    280282    void wcfService_LoginCompleted(object sender, LoginCompletedEventArgs e) {
    281283      if (e.Result.Success) {
     
    286288    }   
    287289
     290    /// <summary>
     291    /// A new Job from the wcfService has been received and will be started within a AppDomain.
     292    /// </summary>
     293    /// <param name="sender"></param>
     294    /// <param name="e"></param>
    288295    void wcfService_SendJobCompleted(object sender, SendJobCompletedEventArgs e) {
    289296      if (e.Result.StatusMessage != ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT) {       
    290297        bool sandboxed = false;
    291         //todo: For testing!!!
    292         //beat.StopHeartBeat();       
    293         //Todo: make a set & override the equals method
    294298        List<byte[]> files = new List<byte[]>();
    295299        foreach (CachedHivePluginInfo plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.PluginsNeeded))
     
    318322    }
    319323
     324    /// <summary>
     325    /// A finished job has been stored on the server
     326    /// </summary>
     327    /// <param name="sender"></param>
     328    /// <param name="e"></param>
    320329    void wcfService_StoreFinishedJobResultCompleted(object sender, StoreFinishedJobResultCompletedEventArgs e) {
    321       lock(engines) {
    322         try {
    323           appDomains[e.Result.JobId].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
    324           AppDomain.Unload(appDomains[e.Result.JobId]);
    325           appDomains.Remove(e.Result.JobId);
    326           engines.Remove(e.Result.JobId);
    327           jobs.Remove(e.Result.JobId);
    328         }
    329         catch (Exception ex) {
    330           Logging.Instance.Error(this.ToString(), "Exception when unloading the appdomain: ", ex);
    331         }
    332       }
    333       if (e.Result.Success) {       
    334      
    335         //if the engine is running again -> we sent an snapshot. Otherwise the job was finished
    336         //this method has a risk concerning race conditions.
    337         //better expand the sendjobresultcompltedeventargs with a boolean "snapshot?" flag
    338 
     330      KillAppDomain(e.Result.JobId);
     331      if (e.Result.Success) {           
    339332        ClientStatusInfo.JobsProcessed++;
    340333        Debug.WriteLine("ProcessedJobs to:" + ClientStatusInfo.JobsProcessed);               
     
    344337    }
    345338
     339    /// <summary>
     340    /// A snapshot has been stored on the server
     341    /// </summary>
     342    /// <param name="sender"></param>
     343    /// <param name="e"></param>
    346344    void wcfService_ProcessSnapshotCompleted(object sender, ProcessSnapshotCompletedEventArgs e) {
    347345      Logging.Instance.Info(this.ToString(), "Snapshot " + e.Result.JobId + " has been transmitted according to plan.");
    348346    }
    349347
    350     //Todo: First stop all threads, then terminate
     348    /// <summary>
     349    /// The server has been changed. All Appdomains and Jobs must be aborted!
     350    /// </summary>
     351    /// <param name="sender"></param>
     352    /// <param name="e"></param>
    351353    void wcfService_ServerChanged(object sender, EventArgs e) {
    352354      Logging.Instance.Info(this.ToString(), "ServerChanged has been called");
    353355      lock (engines) {
    354         foreach (KeyValuePair<Guid, AppDomain> entries in appDomains) {
    355           appDomains[entries.Key].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
    356           AppDomain.Unload(appDomains[entries.Key]);
     356        foreach (KeyValuePair<Guid, Executor> entries in engines) {
     357          engines[entries.Key].Abort();
     358          //appDomains[entries.Key].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
     359          //AppDomain.Unload(appDomains[entries.Key]);
    357360        }
    358         appDomains = new Dictionary<Guid, AppDomain>();
    359         engines = new Dictionary<Guid, Executor>();
    360       }
    361     }
    362 
     361        //appDomains = new Dictionary<Guid, AppDomain>();
     362        //engines = new Dictionary<Guid, Executor>();
     363        //jobs = new Dictionary<Guid, Job>();
     364      }
     365    }
     366
     367    /// <summary>
     368    /// Connnection to the server has been estabilshed => Login and Send the persistet Jobs from the harddisk.
     369    /// </summary>
     370    /// <param name="sender"></param>
     371    /// <param name="e"></param>
    363372    void wcfService_Connected(object sender, EventArgs e) {
    364       wcfService.LoginSync(ConfigManager.Instance.GetClientInfo());
     373      wcfService.LoginSync(ConfigManager.Instance.GetClientInfo());     
    365374      JobStorageManager.CheckAndSubmitJobsFromDisc();
     375      currentlyFetching = false;
    366376    }
    367377
     
    392402      return jobs;
    393403    }
     404
     405    /// <summary>
     406    /// Kill a appdomain with a specific id.
     407    /// </summary>
     408    /// <param name="id">the GUID of the job</param>
     409    private void KillAppDomain(Guid id) {
     410      lock (engines) {
     411        try {
     412          appDomains[id].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
     413          AppDomain.Unload(appDomains[id]);
     414          appDomains.Remove(id);
     415          engines.Remove(id);
     416          jobs.Remove(id);
     417        }       
     418        catch (Exception ex) {
     419          Logging.Instance.Error(this.ToString(), "Exception when unloading the appdomain: ", ex);
     420        }
     421      }
     422      GC.Collect();
     423    }
    394424  }
    395425}
Note: See TracChangeset for help on using the changeset viewer.