Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/04/10 22:47:22 (14 years ago)
Author:
kgrading
Message:

added logging (#826)

File:
1 edited

Legend:

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

    r2117 r2588  
    102102      //Rly?!
    103103      while (!abortRequested) {
    104         MessageContainer container = queue.GetMessage();
    105         Debug.WriteLine("Main loop received this message: " + container.Message.ToString());
    106         Logging.Instance.Info(this.ToString(), container.Message.ToString());
     104        MessageContainer container = queue.GetMessage();       
    107105        DetermineAction(container);
    108106      }
     
    114112    /// </summary>
    115113    /// <param name="container">The Container, containing the message</param>
    116     private void DetermineAction(MessageContainer container) {           
     114    private void DetermineAction(MessageContainer container) {
     115      Logging.Instance.Info(this.ToString(), "Message: " + container.Message.ToString() + " for job: " + container.JobId);       
    117116      switch (container.Message) {
    118117        //Server requests to abort a job
    119         case MessageContainer.MessageType.AbortJob:
     118        case MessageContainer.MessageType.AbortJob:         
    120119          if(engines.ContainsKey(container.JobId))
    121120            engines[container.JobId].Abort();
     
    127126
    128127        case MessageContainer.MessageType.JobAborted:         
    129         //todo: thread this
    130           Debug.WriteLine("Job aborted, he's dead");
     128        //todo: thread this         
    131129          lock (engines) {           
    132130            Guid jobId = new Guid(container.JobId.ToString());
     
    145143       
    146144        //Request a Snapshot from the Execution Engine
    147         case MessageContainer.MessageType.RequestSnapshot:
     145        case MessageContainer.MessageType.RequestSnapshot:         
    148146          if (engines.ContainsKey(container.JobId))
    149147            engines[container.JobId].RequestSnapshot();
     
    154152       
    155153        //Snapshot is ready and can be sent back to the Server
    156         case MessageContainer.MessageType.SnapshotReady:
     154        case MessageContainer.MessageType.SnapshotReady:         
    157155          ThreadPool.QueueUserWorkItem(new WaitCallback(GetSnapshot), container.JobId);         
    158156          break;
     
    160158       
    161159        //Pull a Job from the Server
    162         case MessageContainer.MessageType.FetchJob:
     160        case MessageContainer.MessageType.FetchJob:         
    163161          if (!currentlyFetching) {
    164162            wcfService.SendJobAsync(ConfigManager.Instance.GetClientInfo().Id);
    165163            currentlyFetching = true;
    166           }         
     164          } else
     165            Logging.Instance.Info(this.ToString(), "Currently fetching, won't fetch this time!");
    167166          break;         
    168167       
    169168       
    170169        //A Job has finished and can be sent back to the server
    171         case MessageContainer.MessageType.FinishedJob:
     170        case MessageContainer.MessageType.FinishedJob:         
    172171          ThreadPool.QueueUserWorkItem(new WaitCallback(GetFinishedJob), container.JobId);         
    173172          break;     
     
    218217    /// <param name="jobId"></param>
    219218    private void GetFinishedJob(object jobId) {
    220       Guid jId = (Guid)jobId;     
     219      Guid jId = (Guid)jobId;
     220      Logging.Instance.Info(this.ToString(), "Getting the finished job with id: " + jId);
    221221      try {
    222222        if (!engines.ContainsKey(jId)) {
     
    228228
    229229        if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin) {
     230          Logging.Instance.Info(this.ToString(), "Sending the finished job with id: " + jId);
    230231          wcfService.StoreFinishedJobResultAsync(ConfigManager.Instance.GetClientInfo().Id,
    231232            jId,
     
    235236            true);
    236237        } else {
     238          Logging.Instance.Info(this.ToString(), "Storing the finished job with id: " + jId + " to hdd");
    237239          JobStorageManager.PersistObjectToDisc(wcfService.ServerIP, wcfService.ServerPort, jId, sJob);
    238240          lock (engines) {
     
    251253
    252254    private void GetSnapshot(object jobId) {
     255      Logging.Instance.Info(this.ToString(), "Fetching a snapshot for job " + jobId);
    253256      Guid jId = (Guid)jobId;
    254257      byte[] obj = engines[jId].GetSnapshot();
     258      Logging.Instance.Info(this.ToString(), "BEGIN: Sending snapshot sync");
    255259      wcfService.ProcessSnapshotSync(ConfigManager.Instance.GetClientInfo().Id,
    256260        jId,
     
    258262        engines[jId].Progress,
    259263        null);
    260 
     264      Logging.Instance.Info(this.ToString(), "END: Sended snapshot sync");
    261265      //Uptime Limit reached, now is a good time to destroy this jobs.
    262266      if (!UptimeManager.Instance.isOnline()) {
     
    267271     
    268272      } else {
     273        Logging.Instance.Info(this.ToString(), "Restarting the job" + jobId);
    269274        engines[jId].StartOnlyJob();
    270275      }
     
    294299    /// <param name="e"></param>
    295300    void wcfService_SendJobCompleted(object sender, SendJobCompletedEventArgs e) {
     301      Logging.Instance.Info(this.ToString(), "Received new job with id " + e.Result.Job.Id);
    296302      if (e.Result.StatusMessage != ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT) {       
    297303        bool sandboxed = false;
    298304        List<byte[]> files = new List<byte[]>();
     305        Logging.Instance.Info(this.ToString(), "Fetching plugins for job " + e.Result.Job.Id);
    299306        foreach (CachedHivePluginInfo plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.PluginsNeeded))
    300307          files.AddRange(plugininfo.PluginFiles);
    301 
     308        Logging.Instance.Info(this.ToString(), "Plugins fetched for job " + e.Result.Job.Id);
    302309        AppDomain appDomain = PluginManager.Manager.CreateAndInitAppDomainWithSandbox(e.Result.Job.Id.ToString(), sandboxed, null, files);
    303310        appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException);
     
    306313            jobs.Add(e.Result.Job.Id, e.Result.Job);
    307314            appDomains.Add(e.Result.Job.Id, appDomain);
    308 
     315            Logging.Instance.Info(this.ToString(), "Creating AppDomain");
    309316            Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
     317            Logging.Instance.Info(this.ToString(), "Created AppDomain");
    310318            engine.JobId = e.Result.Job.Id;
    311             engine.Queue = MessageQueue.GetInstance();           
     319            engine.Queue = MessageQueue.GetInstance();
     320            Logging.Instance.Info(this.ToString(), "Starting Engine for job " + e.Result.Job.Id);
    312321            engine.Start(e.Data);
    313322            engines.Add(e.Result.Job.Id, engine);
     
    318327          }
    319328        }       
    320       }
     329      } else
     330        Logging.Instance.Info(this.ToString(), "No more jobs left!");
    321331      currentlyFetching = false;
    322332    }
     
    328338    /// <param name="e"></param>
    329339    void wcfService_StoreFinishedJobResultCompleted(object sender, StoreFinishedJobResultCompletedEventArgs e) {
     340      Logging.Instance.Info(this.ToString(), "Job submitted with id " + e.Result.JobId);
    330341      KillAppDomain(e.Result.JobId);
    331342      if (e.Result.Success) {           
     
    408419    /// <param name="id">the GUID of the job</param>
    409420    private void KillAppDomain(Guid id) {
     421      Logging.Instance.Info(this.ToString(), "Shutting down Appdomain for Job " + id);
    410422      lock (engines) {
    411423        try {
Note: See TracChangeset for help on using the changeset viewer.