Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1096


Ignore:
Timestamp:
01/08/09 16:22:59 (16 years ago)
Author:
msteinbi
Message:

Implementing Lifecycle Management (#453)

Location:
trunk/sources
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Contracts/ApplicationConstants.cs

    r1086 r1096  
    4747    public static string RESPONSE_COMMUNICATOR_NO_JO_WITH_THIS_ID = "Communicator.NoJobWithThisId";
    4848    public static string RESPONSE_COMMUNICATOR_WRONG_JOB_STATE = "Communicator.WrongJobState";
     49    public static string RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN = "Communicator.UserNotLoggedIn";
    4950
    5051    public static string RESPONSE_JOB_ALL_JOBS = "Job.AllJobs";
  • trunk/sources/HeuristicLab.Hive.Contracts/HiveServerMessages.resx

    r1024 r1096  
    226226    <value>The state of the job must be offline</value>
    227227  </data>
     228  <data name="Communicator.UserNotLoggedIn" xml:space="preserve">
     229    <value>User is not logged in, you must login before sending Heartbeats</value>
     230  </data>
    228231</root>
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/CachedDataAdapter.cs

    r1095 r1096  
    4242      new List<ICachedDataAdapter>();
    4343
     44    private DataTable temp = new DataTable();
     45
    4446    protected CachedDataAdapter() {
    4547      FillCache();
     
    127129    [MethodImpl(MethodImplOptions.Synchronized)]
    128130    protected abstract RowT FindCachedById(long id);
    129 
    130     protected abstract DataTable GetDataTable();
    131131
    132132    [MethodImpl(MethodImplOptions.Synchronized)]
     
    191191            !PutInCache(obj)) {
    192192          //remove from cache
    193           GetDataTable().ImportRow(row);
     193          temp.ImportRow(row);
    194194
    195195          UpdateRow(row);
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientAdapter.cs

    r1094 r1096  
    202202    }
    203203
    204     protected override System.Data.DataTable GetDataTable() {
    205       return data;
    206     }
    207204    #endregion
    208205
     
    214211          ClientInfo found = GetById(client.ClientId);
    215212          if (found != null)
    216             client = found;
     213            client.Id = found.Id;
    217214        }
    218215
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/JobAdapter.cs

    r1094 r1096  
    188188        new Selector(adapter.GetData),
    189189        new Selector(cache.AsEnumerable<dsHiveServer.JobRow>));
    190     }
    191 
    192     protected override System.Data.DataTable GetDataTable() {
    193       return data;
    194190    }
    195191
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ResourceAdapter.cs

    r1094 r1096  
    127127    }
    128128
    129     protected override System.Data.DataTable GetDataTable() {
    130       return data;
    131     }
    132129    #endregion
    133130
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r1088 r1096  
    1111using System.Reflection;
    1212using HeuristicLab.Hive.JobBase;
     13using System.Runtime.CompilerServices;
    1314
    1415namespace HeuristicLab.Hive.Server.Core {
     
    4445    }
    4546
     47    [MethodImpl(MethodImplOptions.Synchronized)]
    4648    void lifecycleManager_OnServerHeartbeat(object sender, EventArgs e) {
    4749      List<ClientInfo> allClients = new List<ClientInfo>(clientAdapter.GetAll());
     50      List<Job> allJobs = new List<Job>(jobAdapter.GetAll());
    4851
    4952      foreach (ClientInfo client in allClients) {
    50        
     53        if (client.State != State.offline && client.State != State.nullState) {
     54          if (!lastHeartbeats.ContainsKey(client.ClientId)) {
     55            client.State = State.offline;
     56            clientAdapter.Update(client);
     57          } else {
     58            DateTime lastHbOfClient = lastHeartbeats[client.ClientId];
     59            int diff = lastHbOfClient.CompareTo(DateTime.Now);
     60            Console.WriteLine(diff);
     61          }
     62        } else {
     63          if (lastHeartbeats.ContainsKey(client.ClientId))
     64            lastHeartbeats.Remove(client.ClientId);
     65        }
    5166      }
    5267    }
     
    5469    #region IClientCommunicator Members
    5570
     71    [MethodImpl(MethodImplOptions.Synchronized)]
    5672    public Response Login(ClientInfo clientInfo) {
    5773      Response response = new Response();
    5874
     75      if (lastHeartbeats.ContainsKey(clientInfo.ClientId)) {
     76        lastHeartbeats[clientInfo.ClientId] = DateTime.Now;
     77      } else {
     78        lastHeartbeats.Add(clientInfo.ClientId, DateTime.Now);
     79      }
     80
    5981      ICollection<ClientInfo> allClients = clientAdapter.GetAll();
    6082      ClientInfo client = clientAdapter.GetById(clientInfo.ClientId);
    61       if (client != null && client.State != State.offline) {
     83      if (client != null && client.State != State.offline && client.State != State.nullState) {
    6284        response.Success = false;
    6385        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_USER_ALLREADY_ONLINE;
    6486        return response;
    6587      }
     88      clientInfo.State = State.idle;
    6689      clientAdapter.Update(clientInfo);
    6790      response.Success = true;
     
    7194    }
    7295
     96    [MethodImpl(MethodImplOptions.Synchronized)]
    7397    public ResponseHB SendHeartBeat(HeartBeatData hbData) {
    7498      ResponseHB response = new ResponseHB();
     99
     100      response.ActionRequest = new List<MessageContainer>();
     101      if (clientAdapter.GetById(hbData.ClientId).State == State.offline ||
     102          clientAdapter.GetById(hbData.ClientId).State == State.nullState) {
     103        response.Success = false;
     104        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN;
     105        response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage));
     106        return response;
     107      }
    75108
    76109      if (lastHeartbeats.ContainsKey(hbData.ClientId)) {
     
    82115      response.Success = true;
    83116      response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_HARDBEAT_RECEIVED;
    84       response.ActionRequest = new List<MessageContainer>();
    85117      List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline));
    86118      if (allOfflineJobs.Count > 0 && hbData.freeCores > 0)
     
    146178      return response;
    147179    }
    148                            
     180
     181    [MethodImpl(MethodImplOptions.Synchronized)]                       
    149182    public Response Logout(Guid clientId) {
    150183      Response response = new Response();
    151      
     184
     185      if (lastHeartbeats.ContainsKey(clientId))
     186        lastHeartbeats.Remove(clientId);
     187
    152188      ClientInfo client = clientAdapter.GetById(clientId);
    153189      if (client == null) {
Note: See TracChangeset for help on using the changeset viewer.