Changeset 1004
- Timestamp:
- 12/17/08 14:36:20 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Contracts/ApplicationConstants.cs
r969 r1004 41 41 public static string RESPONSE_COMMUNICATOR_LOGOUT_SUCCESS = "Communicator.LogoutSuccess"; 42 42 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"; 43 46 44 47 public static string RESPONSE_JOB_ALL_JOBS = "Job.AllJobs"; -
trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/Client.cs
r995 r1004 28 28 namespace HeuristicLab.Hive.Contracts.BusinessObjects { 29 29 30 public enum State { nullState, idle, calculating, offline };30 public enum State { nullState, idle, calculating, offline, finished }; 31 31 32 32 [DataContract] -
trunk/sources/HeuristicLab.Hive.Contracts/HiveServerMessages.resx
r969 r1004 217 217 <value>A user with this username exists allready</value> 218 218 </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> 219 225 </root> -
trunk/sources/HeuristicLab.Hive.Contracts/Interfaces/IClientCommunicator.cs
r838 r1004 40 40 ResponseJob PullJob(Guid clientId); 41 41 [OperationContract] 42 ResponseResultReceived SendJobResult(JobResult Result, bool finished);42 ResponseResultReceived SendJobResult(JobResult result, bool finished); 43 43 [OperationContract] 44 44 Response Logout(Guid clientId); -
trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs
r1001 r1004 17 17 /// </summary> 18 18 public class ClientCommunicator: IClientCommunicator { 19 int nrOfJobs = 1 ;19 int nrOfJobs = 10; 20 20 21 21 IClientAdapter clientAdapter; 22 22 IJobAdapter jobAdapter; 23 IJobResultsAdapter jobResultAdapter; 23 24 24 25 public ClientCommunicator() { … … 26 27 jobAdapter = ServiceLocator.GetJobAdapter(); 27 28 28 for (int i = 0; i < 10; i++) {29 for (int i = 0; i < nrOfJobs; i++) { 29 30 Job job = new Job(); 30 31 job.Id = i; … … 39 40 public Response Login(ClientInfo clientInfo) { 40 41 Response response = new Response(); 41 response.Success = true;42 42 43 43 ICollection<ClientInfo> allClients = clientAdapter.GetAll(); 44 44 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; 55 49 } 50 clientAdapter.Update(clientInfo); 51 response.Success = true; 52 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_SUCCESS; 56 53 57 54 return response; … … 64 61 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_HARDBEAT_RECEIVED; 65 62 response.ActionRequest = new List<MessageContainer>(); 66 List<Job> all Jobs = new List<Job>(jobAdapter.GetAll());67 if (all Jobs.Count > 0 && hbData.freeCores > 0)63 List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline)); 64 if (allOfflineJobs.Count > 0 && hbData.freeCores > 0) 68 65 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.FetchJob)); 69 66 else … … 76 73 ResponseJob response = new ResponseJob(); 77 74 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); 82 81 response.SerializedJob = PersistenceManager.SaveToGZip(new TestJob()); 83 82 response.Success = true; … … 91 90 } 92 91 93 public ResponseResultReceived SendJobResult(JobResult Result, bool finished) {92 public ResponseResultReceived SendJobResult(JobResult result, bool finished) { 94 93 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 95 120 response.Success = true; 96 121 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED; 97 response.JobId = Result.JobId;122 response.JobId = result.JobId; 98 123 99 124 return response;
Note: See TracChangeset
for help on using the changeset viewer.