Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/02/11 15:23:59 (13 years ago)
Author:
cneumuel
Message:

#1233

  • changed the way lifecycle methods are called. The new service method TriggerLifecycle checks when the latest cleanup was made and performs one (if necessary). This can also be called by an external program (like a windows task)
  • robustified logging
Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HeuristicLab.Services.Hive-3.4.csproj

    r5405 r5593  
    115115    <Compile Include="Interfaces\ILifecycleManager.cs" />
    116116    <Compile Include="Interfaces\IServiceLocator.cs" />
    117     <Compile Include="Standalone\HeuristicLabServicesHiveApplication.cs" />
    118     <Compile Include="Standalone\MainForm.cs">
    119       <SubType>Form</SubType>
    120     </Compile>
    121     <Compile Include="Standalone\MainForm.Designer.cs">
    122       <DependentUpon>MainForm.cs</DependentUpon>
    123     </Compile>
    124117    <Compile Include="AuthorizationManager.cs" />
    125118    <Compile Include="HeuristicLabServicesHivePlugin.cs" />
     
    148141  </ItemGroup>
    149142  <ItemGroup>
    150     <EmbeddedResource Include="Standalone\MainForm.resx">
    151       <DependentUpon>MainForm.cs</DependentUpon>
    152     </EmbeddedResource>
     143    <Folder Include="Standalone\" />
    153144  </ItemGroup>
    154145  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs

    r5535 r5593  
    229229    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
    230230    public List<MessageContainer> Heartbeat(Heartbeat heartbeat) {
     231      TriggerLifecycle();
     232
    231233      using (trans.OpenTransaction()) {
    232234        return heartbeatManager.ProcessHeartbeat(heartbeat);
     
    255257    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
    256258    public IEnumerable<Plugin> GetPlugins() {
    257       return dao.GetPlugins(x => true);
     259      return dao.GetPlugins(x => x.IsLocal == false);
    258260    }
    259261
     
    382384      }
    383385    }
     386
     387    public void TriggerLifecycle() {
     388      using (trans.OpenTransaction()) {
     389        DateTime lastCleanup = dao.GetLastCleanup();
     390        if (DateTime.Now - lastCleanup > TimeSpan.FromSeconds(59)) {
     391          dao.SetLastCleanup(DateTime.Now);
     392          lifecycleManager.Cleanup();
     393        }
     394      }
     395    }
    384396    #endregion
    385397
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/Interfaces/ILifecycleManager.cs

    r5405 r5593  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using HeuristicLab.Services.Hive.Common;
    6 using HeuristicLab.Services.Hive.Common.DataTransfer;
    7 
     1
    82namespace HeuristicLab.Services.Hive {
    93  /// <summary>
     
    115  /// </summary>
    126  public interface ILifecycleManager {
    13     void Start();
    14 
    15     void Stop();
     7    void Cleanup();
    168  }
    179}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs

    r5526 r5593  
    11using System;
    22using System.Linq;
    3 using HeuristicLab.Core;
    43using HeuristicLab.Services.Hive.Common;
    54using HeuristicLab.Services.Hive.Common.DataTransfer;
     
    76namespace HeuristicLab.Services.Hive {
    87  /// <summary>
    9   /// This class holds the state of all recent heartbeats and decides to reschedule jobs and set slaves offline
     8  /// This class offers methods for cleaning up offline slaves and jobs
    109  /// </summary>
    1110  public class LifecycleManager : ILifecycleManager {
     
    1918      get { return ServiceLocator.Instance.AuthorizationManager; }
    2019    }
    21 
    22     private static object locker = new object();
    23 
    24     // Windows-Forms timer is single threaded, so callbacks will be synchron
    25     private System.Windows.Forms.Timer timer;
    26 
    27     public ExecutionState ExecutionState {
    28       get { return timer.Enabled ? ExecutionState.Started : Core.ExecutionState.Stopped; }
     20    private ILogger log {
     21      get { return LogFactory.GetLogger(this.GetType().Namespace); }
    2922    }
    3023
    31     public LifecycleManager() {
    32       this.timer = new System.Windows.Forms.Timer();
    33       this.timer.Tick += new EventHandler(timer_Tick);
    34     }
    35 
    36     public void Start() {
    37       if (ExecutionState == Core.ExecutionState.Stopped) {
    38         // kick off the event immediately
    39         timer_Tick(this, EventArgs.Empty);
    40 
    41         // start the timer
    42         this.timer.Interval = (int)new TimeSpan(0, 0, 30).TotalMilliseconds;
    43         this.timer.Start();
    44       }
    45     }
    46 
    47     public void Stop() {
    48       if (ExecutionState == Core.ExecutionState.Started) {
    49         timer.Stop();
    50       }
    51     }
    52 
    53     /// <summary>
    54     /// This method is supposed to check if slaves are online
    55     /// if not -> set them offline and check if they where calculating a job
    56     /// </summary>
    57     private void timer_Tick(object sender, EventArgs e) {
    58       lock (locker) {
    59         using (trans.OpenTransaction()) {
    60           SetTimeoutSlavesOffline();
    61           FinishParentJobs();
    62         }
    63       }
     24    public void Cleanup() {
     25      log.Log("LifecycleManager.Cleanup()");
     26      SetTimeoutSlavesOffline();
     27      FinishParentJobs();
    6428    }
    6529
     
    10165      }
    10266    }
     67
    10368  }
    10469}
Note: See TracChangeset for help on using the changeset viewer.