Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/10 17:48:10 (14 years ago)
Author:
cneumuel
Message:

HiveExperiment is now able to send IOptimizers of an Experiment and receive the calculated result (#1115)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Client.Core/3.3/Heartbeat.cs

    r4060 r4119  
    4343    private bool offline;
    4444
    45     public double Interval { get; set; }   
     45    public double Interval { get; set; }
    4646    private Timer heartbeatTimer = null;
    47        
     47
     48    private static object locker = new object();
     49
    4850    public Heartbeat() {
    4951      Interval = 100;
     
    5153
    5254    public Heartbeat(double interval) {
    53       Interval = interval;     
     55      Interval = interval;
    5456    }
    5557
     
    7476    /// <param name="sender"></param>
    7577    /// <param name="e"></param>
    76     void heartbeatTimer_Elapsed(object sender, ElapsedEventArgs e) {     
    77       ClientDto info = ConfigManager.Instance.GetClientInfo();     
     78    void heartbeatTimer_Elapsed(object sender, ElapsedEventArgs e) {
     79      lock (locker) {
     80        // check if cwfService is disconnected for any reason (should happen at first heartbeat)
     81        // [chn] TODO: Client should always send heartbeats. when calendar disallows he should tell the server he does not want to compute anything
     82        if (wcfService.ConnState == NetworkEnum.WcfConnState.Disconnected &&
     83          (!UptimeManager.Instance.CalendarAvailable || UptimeManager.Instance.IsOnline())) {
     84          wcfService.Connect();
     85        }
    7886
    79       PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true);
    80       int mb = (int)(counter.NextValue() / 1024 / 1024);
     87        ClientDto info = ConfigManager.Instance.GetClientInfo();
    8188
    82       HeartBeatData heartBeatData = new HeartBeatData {
    83         ClientId = info.Id,
    84         FreeCores = info.NrOfCores - ConfigManager.Instance.GetUsedCores(),
    85         FreeMemory = mb,
    86         JobProgress = ConfigManager.Instance.GetProgressOfAllJobs()     
    87       };
    88        
    89       DateTime lastFullHour = DateTime.Parse(DateTime.Now.Hour.ToString() + ":00");
    90       TimeSpan span = DateTime.Now - lastFullHour;
    91       if (span.TotalSeconds < (Interval/1000)) {
    92         if (UptimeManager.Instance.IsOnline() && UptimeManager.Instance.CalendarAvailable) {
    93           //That's quiet simple: Just reconnect and you're good for new jobs
    94           if (wcfService.ConnState != NetworkEnum.WcfConnState.Loggedin) {
    95             Logger.Info("Client goes online according to timetable");
    96             wcfService.Connect();
     89        PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true);
     90        int mb = (int)(counter.NextValue() / 1024 / 1024);
     91
     92        HeartBeatData heartBeatData = new HeartBeatData {
     93          ClientId = info.Id,
     94          FreeCores = info.NrOfCores - ConfigManager.Instance.GetUsedCores(),
     95          FreeMemory = mb,
     96          JobProgress = ConfigManager.Instance.GetProgressOfAllJobs()
     97        };
     98
     99        DateTime lastFullHour = DateTime.Parse(DateTime.Now.Hour.ToString() + ":00");
     100        TimeSpan span = DateTime.Now - lastFullHour;
     101        if (span.TotalSeconds < (Interval / 1000)) {
     102          if (UptimeManager.Instance.IsOnline() && UptimeManager.Instance.CalendarAvailable) {
     103            //That's quiet simple: Just reconnect and you're good for new jobs
     104            if (wcfService.ConnState != NetworkEnum.WcfConnState.Loggedin) {
     105              Logger.Info("Client goes online according to timetable");
     106              wcfService.Connect();
     107            }
     108          } else {
     109            //We have quit a lot of work to do here: snapshot all jobs, submit them back, then disconnect and then pray to god that nothing goes wrong
     110            MessageQueue.GetInstance().AddMessage(MessageContainer.MessageType.UptimeLimitDisconnect);
    97111          }
    98         } else {
    99           //We have quit a lot of work to do here: snapshot all jobs, submit them back, then disconnect and then pray to god that nothing goes wrong
    100           MessageQueue.GetInstance().AddMessage(MessageContainer.MessageType.UptimeLimitDisconnect);                 
    101         }       
    102       }
    103       if (wcfService.ConnState == NetworkEnum.WcfConnState.Failed) {
    104         wcfService.Connect();
    105       } else if (wcfService.ConnState == NetworkEnum.WcfConnState.Loggedin) {
    106         Logger.Debug("Sending Heartbeat: " + heartBeatData);       
    107         wcfService.ProcessHeartBeatAsync(heartBeatData);
     112        }
     113        if (wcfService.ConnState == NetworkEnum.WcfConnState.Failed) {
     114          wcfService.Connect();
     115        } else if (wcfService.ConnState == NetworkEnum.WcfConnState.Loggedin) {
     116          Logger.Debug("Sending Heartbeat: " + heartBeatData);
     117          wcfService.ProcessHeartBeatAsync(heartBeatData);
     118        }
    108119      }
    109120    }
     
    111122    void wcfService_ProcessHeartBeatCompleted(object sender, ProcessHeartBeatCompletedEventArgs e) {
    112123      Logger.Debug("Heartbeat received");
    113       e.Result.ActionRequest.ForEach(mc => MessageQueue.GetInstance().AddMessage(mc));     
     124      e.Result.ActionRequest.ForEach(mc => MessageQueue.GetInstance().AddMessage(mc));
    114125    }
    115126
Note: See TracChangeset for help on using the changeset viewer.