Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1004


Ignore:
Timestamp:
12/17/08 14:36:20 (16 years ago)
Author:
msteinbi
Message:

Implementation of ClientCommunicator, pullJob sendHeartbeat (#399)

Location:
trunk/sources
Files:
5 edited

Legend:

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

    r969 r1004  
    4141    public static string RESPONSE_COMMUNICATOR_LOGOUT_SUCCESS = "Communicator.LogoutSuccess";
    4242    public static string RESPONSE_COMMUNICATOR_NO_JOBS_LEFT = "Communicator.NoJobsLeft";
     43    public static string RESPONSE_COMMUNICATOR_ID_MUST_NOT_BE_SET = "Communicator.IdMustNotBeSet";
     44    public static string RESPONSE_COMMUNICATOR_NO_JO_WITH_THIS_ID = "Communicator.NoJobWithThisId";
     45    public static string RESPONSE_COMMUNICATOR_WRONG_JOB_STATE = "Communicator.WrongJobState";
    4346
    4447    public static string RESPONSE_JOB_ALL_JOBS = "Job.AllJobs";
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/Client.cs

    r995 r1004  
    2828namespace HeuristicLab.Hive.Contracts.BusinessObjects {
    2929
    30   public enum State { nullState, idle, calculating, offline };
     30  public enum State { nullState, idle, calculating, offline, finished };
    3131
    3232  [DataContract]
  • trunk/sources/HeuristicLab.Hive.Contracts/HiveServerMessages.resx

    r969 r1004  
    217217    <value>A user with this username exists allready</value>
    218218  </data>
     219  <data name="Communicator.IdMustNotBeSet" xml:space="preserve">
     220    <value>The id must not be set in this context</value>
     221  </data>
     222  <data name="Communicator.NoJobWithThisId" xml:space="preserve">
     223    <value>There exists no job with this id</value>
     224  </data>
    219225</root>
  • trunk/sources/HeuristicLab.Hive.Contracts/Interfaces/IClientCommunicator.cs

    r838 r1004  
    4040    ResponseJob PullJob(Guid clientId);
    4141    [OperationContract]
    42     ResponseResultReceived SendJobResult(JobResult Result, bool finished);
     42    ResponseResultReceived SendJobResult(JobResult result, bool finished);
    4343    [OperationContract]
    4444    Response Logout(Guid clientId);
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r1001 r1004  
    1717  /// </summary>
    1818  public class ClientCommunicator: IClientCommunicator {
    19     int nrOfJobs = 1;
     19    int nrOfJobs = 10;
    2020
    2121    IClientAdapter clientAdapter;
    2222    IJobAdapter jobAdapter;
     23    IJobResultsAdapter jobResultAdapter;
    2324
    2425    public ClientCommunicator() {
     
    2627      jobAdapter = ServiceLocator.GetJobAdapter();
    2728
    28       for (int i = 0; i < 10; i++) {
     29      for (int i = 0; i < nrOfJobs; i++) {
    2930        Job job = new Job();
    3031        job.Id = i;
     
    3940    public Response Login(ClientInfo clientInfo) {
    4041      Response response = new Response();
    41       response.Success = true;
    4242
    4343      ICollection<ClientInfo> allClients = clientAdapter.GetAll();
    4444      ClientInfo client = clientAdapter.GetById(clientInfo.ClientId);
    45       if (client != null) {
    46         if (client.State != State.offline) {
    47           response.Success = false;
    48           response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_USER_ALLREADY_ONLINE;
    49         }
    50       }
    51 
    52       if (response.Success) {
    53         clientAdapter.Update(clientInfo);
    54         response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_SUCCESS;
     45      if (client != null && client.State != State.offline) {
     46        response.Success = false;
     47        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_USER_ALLREADY_ONLINE;
     48        return response;
    5549      }
     50      clientAdapter.Update(clientInfo);
     51      response.Success = true;
     52      response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_SUCCESS;
    5653
    5754      return response;
     
    6461      response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_HARDBEAT_RECEIVED;
    6562      response.ActionRequest = new List<MessageContainer>();
    66       List<Job> allJobs = new List<Job>(jobAdapter.GetAll());
    67       if (allJobs.Count > 0 && hbData.freeCores > 0)
     63      List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline));
     64      if (allOfflineJobs.Count > 0 && hbData.freeCores > 0)
    6865        response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.FetchJob));
    6966      else
     
    7673      ResponseJob response = new ResponseJob();
    7774      lock (this) {
    78         LinkedList<Job> allJobs = new LinkedList<Job>(jobAdapter.GetAll());
    79         if (allJobs.Last != null) {
    80           response.JobId = allJobs.Last.Value.Id;
    81           jobAdapter.Delete(allJobs.Last.Value);   
     75        LinkedList<Job> allOfflineJobs = new LinkedList<Job>(jobAdapter.GetJobsByState(State.offline));
     76        if (allOfflineJobs != null && allOfflineJobs.Count > 0) {
     77          Job job2Calculate = allOfflineJobs.First.Value;
     78          job2Calculate.State = State.calculating;
     79          response.JobId = job2Calculate.Id;
     80          jobAdapter.Update(job2Calculate);         
    8281          response.SerializedJob = PersistenceManager.SaveToGZip(new TestJob());
    8382          response.Success = true;
     
    9190    }
    9291
    93     public ResponseResultReceived SendJobResult(JobResult Result, bool finished) {
     92    public ResponseResultReceived SendJobResult(JobResult result, bool finished) {
    9493      ResponseResultReceived response = new ResponseResultReceived();
     94      if (result.Id != 0) {
     95        response.Success = false;
     96        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_ID_MUST_NOT_BE_SET;
     97        return response;
     98      }
     99      Job job = jobAdapter.GetById(result.JobId);
     100      if (job == null) {
     101        response.Success = false;
     102        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JO_WITH_THIS_ID;
     103        return response;
     104      }
     105      if (job.State != State.calculating) {
     106        response.Success = false;
     107        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_JOB_STATE;
     108        return response;
     109      }
     110      if (finished) {
     111        job.State = State.finished;
     112        jobAdapter.Update(job);
     113
     114        List<JobResult> jobResults = new List<JobResult>(jobResultAdapter.GetResultsOf(job));
     115        foreach (JobResult currentResult in jobResults)
     116          jobResultAdapter.Delete(currentResult);
     117      }
     118      jobResultAdapter.Update(result);   
     119
    95120      response.Success = true;
    96121      response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED;
    97       response.JobId = Result.JobId;
     122      response.JobId = result.JobId;
    98123
    99124      return response;
Note: See TracChangeset for help on using the changeset viewer.