Free cookie consent management tool by TermsFeed Policy Generator

Changeset 783


Ignore:
Timestamp:
11/19/08 17:03:25 (15 years ago)
Author:
msteinbi
Message:

First version of a dummy implementation of the ClientCommunicator (#371)

Location:
trunk/sources
Files:
1 added
3 edited

Legend:

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

    r780 r783  
    77namespace HeuristicLab.Hive.Contracts {
    88
    9   /// <summary>
    10   /// If a client sends a heartbeat the server can request sereral actions
    11   /// actions:
    12   ///  - jobReady: an new Job is ready to be calculated
    13   ///  - jobSnapshot: send a snapshot of the current status of the calculated job
    14   ///  - abortJobwithReturn: abort the job and return all existing results
    15   ///  - abortJobwithoutReturn: abort the job and don't send back anything
    16   ///  - nothingToDo: there is nothing to do at the moment
    17   /// </summary>
    18   public enum Action { jobReady, jobSnapshot, abortJobwithReturn, abortJobwithoutReturn, nothingToDo }
    199
    2010  /// <summary>
     
    2414  [DataContract]
    2515  public class ResponseHB : Response {
    26     /// <summary>
    27     /// The server can send more than one actionRequest to the client
    28     /// So they are stored in one Map
    29     /// key [long]: JobId
    30     /// value [Action]: action
    31     /// </summary>
    3216    [DataMember]
    33     public Dictionary<long, Action> ActionRequest { get; set; }
     17    public List<MessageContainer> ActionRequest { get; set; }
    3418  }
    3519}
  • trunk/sources/HeuristicLab.Hive.Contracts/ResponseJob.cs

    r780 r783  
    1515  public class ResponseJob : Response {
    1616    [DataMember]
    17     public Job Job { get; set; }
     17    public long JobId { get; set; }
    1818  }
    1919}
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r780 r783  
    1212  /// </summary>
    1313  public class ClientCommunicator: IClientCommunicator {
     14    List<Client> clients;
     15    List<long> jobs;
     16    int nrOfJobs = 10;
     17
     18    public ClientCommunicator() {
     19      jobs = new List<long>();
     20      for (int i = 1; i < nrOfJobs; i++) {
     21        jobs.Add(i);
     22      }
     23    }
     24
    1425    #region IClientCommunicator Members
    1526
    1627    public Response Login(Client clientInfo) {
     28      if (clients == null)
     29        clients = new List<Client>();
     30
     31      clients.Add(clientInfo);
     32
    1733      Response response = new Response();
    1834      response.Success = true;
    19       response.StatusMessage = "Logged in...";
     35      response.StatusMessage = "Client with GUID " + clientInfo.ClientId + " successuflly logged in";
    2036
    2137      return response;
     
    2339
    2440    public ResponseHB SendHeartBeat(HeartBeatData hbData) {
    25       throw new NotImplementedException();
     41      ResponseHB response = new ResponseHB();
     42
     43      response.Success = true;
     44      response.StatusMessage = "HeartBeat received";
     45      if (jobs.Count > 0)
     46        response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.FetchJob));
     47      else
     48        response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage));
     49
     50      return response;
    2651    }
    2752
    2853    public ResponseJob PullJob(Guid clientId) {
    29       throw new NotImplementedException();
     54      ResponseJob response = new ResponseJob();
     55
     56      response.JobId = jobs.ElementAt(jobs.Count);
     57      response.Success = true;
     58      response.StatusMessage = "Job with id " + jobs.Count + " sent";
     59      jobs.Remove(jobs.Count);
     60
     61      return response;
    3062    }
    3163
    3264    public Response SendJobResult(JobResult Result, bool finished) {
    33       throw new NotImplementedException();
     65      Response response = new Response();
     66      response.Success = true;
     67      response.StatusMessage = "Thanks for calculating";
     68
     69      return response;
    3470    }
    3571
    3672    public Response Logout(Guid clientId) {
    37       throw new NotImplementedException();
     73      bool clientRemoved = false;
     74      foreach (Client client in clients) {
     75        if (client.ClientId.Equals(clientId)) {
     76          clients.Remove(client);
     77          clientRemoved = true;
     78        }
     79      }
     80      Response response = new Response()
     81     
     82      if (clientRemoved) {
     83        response.Success = true;
     84        response.StatusMessage = "Successfully logged out. Good bye";
     85      } else {
     86        response.Success = false;
     87        response.StatusMessage = "Sorry, but you weren't logged in";
     88      }
     89      return response;
    3890    }
    3991
Note: See TracChangeset for help on using the changeset viewer.