Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1368 for trunk


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

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

Location:
trunk/sources
Files:
1 added
6 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) {
  • trunk/sources/HeuristicLab.Hive.Client.Core/Heartbeat.cs

    r1366 r1368  
    7373      Console.WriteLine("tick"); 
    7474      ClientInfo info = ConfigManager.Instance.GetClientInfo();
    75       // Todo: remove tempfix for free cores. Fix spelling of freeCores (uppercase)
     75      // Todo: remove tempfix for free cores.
    7676
    7777      HeartBeatData heartBeatData = new HeartBeatData {
    7878        ClientId = info.ClientId,
    79         freeCores = info.NrOfCores - (ClientStatusInfo.JobsFetched - ClientStatusInfo.JobsProcessed),
    80         freeMemory = 1000,
    81         jobProgress = ConfigManager.Instance.GetProgressOfAllJobs()
     79        FreeCores = info.NrOfCores - (ClientStatusInfo.JobsFetched - ClientStatusInfo.JobsProcessed),
     80        FreeMemory = 1000,
     81        JobProgress = ConfigManager.Instance.GetProgressOfAllJobs()
    8282      };
    8383      if (wcfService.ConnState == NetworkEnum.WcfConnState.Failed) {
  • trunk/sources/HeuristicLab.Hive.Client.ExecutionEngine/Executor.cs

    r1132 r1368  
    9393      //Job isn't finished!
    9494      if (Job.Running) {
    95         return null;
     95        throw new InvalidStateException("Job is still running");
    9696      } else {
    9797        return SerializeJobObject();
  • trunk/sources/HeuristicLab.Hive.Client.ExecutionEngine/HeuristicLab.Hive.Client.ExecutionEngine.csproj

    r1008 r1368  
    6666    <Compile Include="Executor.cs" />
    6767    <Compile Include="ExecutionEnginePlugin.cs" />
     68    <Compile Include="InvalidStateException.cs" />
    6869    <Compile Include="Properties\AssemblyInfo.cs" />
    6970  </ItemGroup>
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/HeartBeatData.cs

    r1121 r1368  
    3333    public Guid ClientId { get; set; }
    3434    [DataMember]
    35     public int freeMemory { get; set; }
     35    public int FreeMemory { get; set; }
    3636    [DataMember]
    37     public int freeCores { get; set; }
     37    public int FreeCores { get; set; }
    3838    [DataMember]
    39     public Dictionary<long, double> jobProgress { get; set; } // TODO: define Type
     39    public Dictionary<long, double> JobProgress { get; set; } // TODO: define Type
    4040  }
    4141}
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r1365 r1368  
    190190      response.Success = true;
    191191      response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_HEARTBEAT_RECEIVED;
    192       if (hbData.freeCores > 0 && scheduler.ExistsJobForClient(hbData))
     192      if (hbData.FreeCores > 0 && scheduler.ExistsJobForClient(hbData))
    193193        response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.FetchJob));
    194194      else
    195195        response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage));
    196196
    197       if (hbData.jobProgress != null) {
     197      if (hbData.JobProgress != null) {
    198198        List<Job> jobsOfClient = new List<Job>(jobAdapter.GetActiveJobsOf(clientAdapter.GetById(hbData.ClientId)));
    199199        if (jobsOfClient == null || jobsOfClient.Count == 0) {
     
    203203        }
    204204
    205         foreach (KeyValuePair<long, double> jobProgress in hbData.jobProgress) {
     205        foreach (KeyValuePair<long, double> jobProgress in hbData.JobProgress) {
    206206          Job curJob = jobAdapter.GetById(jobProgress.Key);
    207207          if (curJob.Client == null || curJob.Client.ClientId != hbData.ClientId) {
Note: See TracChangeset for help on using the changeset viewer.