Free cookie consent management tool by TermsFeed Policy Generator

Changeset 402


Ignore:
Timestamp:
07/29/08 17:55:35 (16 years ago)
Author:
gkronber
Message:

moved GZip persistence into the PersistenceManager in HeuristicLab.Core because compression is needed in several plugins (CEDMA and Grid)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/PersistenceManager.cs

    r267 r402  
    2525using System.Xml;
    2626using System.IO;
     27using System.IO.Compression;
    2728
    2829namespace HeuristicLab.Core {
     
    8687    }
    8788
     89    public static IStorable RestoreFromGZip(byte[] serializedStorable) {
     90      GZipStream stream = new GZipStream(new MemoryStream(serializedStorable), CompressionMode.Decompress);
     91      return Load(stream);
     92    }
     93
     94    public static byte[] SaveToGZip(IStorable storable) {
     95      MemoryStream memStream = new MemoryStream();
     96      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
     97      Save(storable, stream);
     98      stream.Close();
     99      return memStream.ToArray();
     100    }
     101
    88102    public static string BuildTypeString(Type type) {
    89103      string assembly = type.Assembly.FullName;
  • trunk/sources/HeuristicLab.Grid/ClientForm.cs

    r383 r402  
    3333using System.Threading;
    3434using System.IO;
    35 using System.IO.Compression;
    3635using System.Net;
     36using System.Diagnostics;
    3737
    3838namespace HeuristicLab.Grid {
     
    6161    private void startButton_Click(object sender, EventArgs e) {
    6262      try {
     63        Trace.Listeners.Clear();
     64        Trace.Listeners.Add(new EventLogTraceListener("HeuristicLab.Grid"));
     65
    6366        ResetConnection();
    6467        fetchOperationTimer.Start();
     
    7780
    7881    private void ResetConnection() {
     82      Trace.TraceInformation("Reset connection in GridClient");
    7983      NetTcpBinding binding = new NetTcpBinding();
    8084      binding.MaxReceivedMessageSize = 100000000; // 100Mbytes
     
    112116          gotEngine = engineStore.TryTakeEngine(out currentGuid, out engineXml);
    113117        } catch(TimeoutException) {
     118          Trace.TraceWarning("TimeoutException while trying to get an engine");
    114119          currentEngine = null;
    115120          currentGuid = Guid.Empty;
     
    118123          fetchOperationTimer.Start();
    119124        } catch(CommunicationException) {
     125          Trace.TraceWarning("CommunicationException while trying to get an engine");
    120126          // connection problem -> reset connection and start the timer again
    121127          ResetConnection();
     
    156162              success = true;
    157163            } catch(TimeoutException) {
     164              Trace.TraceWarning("TimeoutException while trying to store the result of an engine");
    158165              success = false;
    159166              retries++;
    160167              Thread.Sleep(TimeSpan.FromSeconds(CONNECTION_RETRY_TIMEOUT_SEC));
    161168            } catch(CommunicationException) {
     169              Trace.TraceWarning("CommunicationException while trying to store the result of an engine");
    162170              ResetConnection();
    163171              success = false;
     
    180188
    181189    private ProcessingEngine RestoreEngine(byte[] engine) {
    182       GZipStream stream = new GZipStream(new MemoryStream(engine), CompressionMode.Decompress);
    183       return (ProcessingEngine)PersistenceManager.Load(stream);
     190      return (ProcessingEngine)PersistenceManager.RestoreFromGZip(engine);
    184191    }
    185192    private byte[] SaveEngine(IEngine engine) {
    186       MemoryStream memStream = new MemoryStream();
    187       GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
    188       PersistenceManager.Save(engine, stream);
    189       stream.Close();
    190       return memStream.ToArray();
     193      return PersistenceManager.SaveToGZip(engine);
    191194    }
    192195  }
  • trunk/sources/HeuristicLab.Grid/JobManager.cs

    r391 r402  
    2929using HeuristicLab.Core;
    3030using System.IO;
    31 using System.IO.Compression;
    3231using System.Windows.Forms;
    3332using System.Diagnostics;
     
    6968
    7069    public JobManager(string address) {
     70      Trace.Listeners.Clear();
     71      Trace.Listeners.Add(new EventLogTraceListener("HeuristicLab.Grid"));
    7172      this.address = address;
    7273      Thread starterThread = new Thread(StartEngines);
     
    9394
    9495    private void ResetConnection() {
     96      Trace.TraceInformation("Reset connection in JobManager");
    9597      lock(connectionLock) {
    9698        // open a new channel
     
    139141          }
    140142        }
    141       } finally {
    142         Debug.Assert(false);  // make sure that we are notified when this thread is stopped in debugging
     143      } catch(Exception e) {
     144        Trace.TraceError("Exception "+e+" in JobManager.StartEngines() killed the start-engine thread\n"+e.StackTrace);
    143145      }
    144146    }
     
    181183          }
    182184        }
    183       } finally {
    184         Debug.Assert(false); // just to make sure that I get notified when debugging whenever this thread is killed somehow
     185      } catch(Exception e) {
     186        Trace.TraceError("Exception " + e + " in JobManager.GetResults() killed the results-gathering thread\n"+ e.StackTrace);
    185187      }
    186188    }
     
    199201
    200202    private byte[] ZipEngine(ProcessingEngine engine) {
    201       MemoryStream memStream = new MemoryStream();
    202       GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
    203       PersistenceManager.Save(engine, stream);
    204       stream.Close();
    205       byte[] zippedEngine = memStream.ToArray();
    206       memStream.Close();
    207       return zippedEngine;
     203      return PersistenceManager.SaveToGZip(engine);
    208204    }
    209205
     
    219215        }
    220216        // restore the engine
    221         using(GZipStream stream = new GZipStream(new MemoryStream(zippedResult), CompressionMode.Decompress)) {
    222           return (ProcessingEngine)PersistenceManager.Load(stream);
    223         }
     217        return (ProcessingEngine)PersistenceManager.RestoreFromGZip(zippedResult);
    224218      }
    225219    }
     
    244238        }
    245239      } while(retries < MAX_CONNECTION_RETRIES);
     240      Trace.TraceWarning("Reached max connection retries in TryStartExecuteEngine");
    246241      return Guid.Empty;
    247242    }
     
    264259        }
    265260      } while(retries < MAX_CONNECTION_RETRIES);
     261      Trace.TraceWarning("Reached max connection retries in TryEndExecuteEngine");
    266262      return null;
    267263    }
     
    285281        }
    286282      } while(retries < MAX_CONNECTION_RETRIES);
     283      Trace.TraceWarning("Reached max connection retries in TryGetJobState");
    287284      return JobState.Unknown;
    288285    }
Note: See TracChangeset for help on using the changeset viewer.