- Timestamp:
- 06/19/09 15:21:33 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Grid.HiveBridge/3.2/HiveGridServerWrapper.cs
r2064 r2073 32 32 using HeuristicLab.PluginInfrastructure; 33 33 using HeuristicLab.Hive.Contracts.BusinessObjects; 34 using System.ServiceModel; 35 using HeuristicLab.Tracing; 34 36 35 37 namespace HeuristicLab.Grid.HiveBridge { 36 38 public class HiveGridServerWrapper : IGridServer { 39 private const int MAX_CONNECTION_RETRIES = 10; 40 private const int RETRY_TIMEOUT_SEC = 60; 37 41 private string address; 42 private IExecutionEngineFacade executionEngine; 43 private object connectionLock = new object(); 38 44 39 45 public HiveGridServerWrapper(string address) { … … 42 48 43 49 public JobState JobState(Guid guid) { 44 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(address); 45 ResponseObject<JobResult> response = executionEngineFacade.GetLastResult(guid, false); 46 if (response.Success == true && 50 ResponseObject<JobResult> response = SavelyExecute(() => executionEngine.GetLastResult(guid, false)); 51 if (response != null && response.Success == true && 47 52 (response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE || 48 53 response.StatusMessage == ApplicationConstants.RESPONSE_JOB_REQUEST_SET || 49 54 response.StatusMessage == ApplicationConstants.RESPONSE_JOB_REQUEST_ALLREADY_SET || 50 55 response.StatusMessage == ApplicationConstants.RESPONSE_JOB_JOB_RESULT_SENT)) { 51 56 return HeuristicLab.Grid.JobState.Busy; 52 57 } else return HeuristicLab.Grid.JobState.Unknown; 53 58 } … … 56 61 var jobObj = CreateJobObj(engine); 57 62 58 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(address); 59 ResponseObject<HeuristicLab.Hive.Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj); 60 return res.Obj.Id; 63 ResponseObject<HeuristicLab.Hive.Contracts.BusinessObjects.Job> res = SavelyExecute(() => executionEngine.AddJob(jobObj)); 64 return res == null ? Guid.Empty : res.Obj.Id; 61 65 } 62 66 63 67 public byte[] TryEndExecuteEngine(Guid guid) { 64 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(address);65 ResponseObject<JobResult> response = executionEngineFacade.GetLastResult(guid, false);66 if (response.Success && response.Obj != null) {68 ResponseObject<JobResult> response = SavelyExecute(() => executionEngine.GetLastResult(guid, false)); 69 if (response != null && 70 response.Success && response.Obj != null) { 67 71 HeuristicLab.Hive.Engine.Job restoredJob = (HeuristicLab.Hive.Engine.Job)PersistenceManager.RestoreFromGZip(response.Obj.Result); 68 72 // Serialize the engine … … 89 93 job.Engine.OperatorGraph.AddOperator(engine.OperatorGraph.InitialOperator); 90 94 job.Engine.OperatorGraph.InitialOperator = engine.OperatorGraph.InitialOperator; 95 job.Engine.Reset(); 91 96 92 97 // Serialize the job … … 143 148 return engine; 144 149 } 150 151 private TResult SavelyExecute<TResult>(Func<TResult> a) where TResult : Response { 152 int retries = 0; 153 if (executionEngine == null) 154 executionEngine = ServiceLocator.CreateExecutionEngineFacade(address); 155 156 do { 157 try { 158 lock (connectionLock) { 159 return a(); 160 } 161 } 162 catch (TimeoutException) { 163 retries++; 164 Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC)); 165 } 166 catch (CommunicationException) { 167 executionEngine = ServiceLocator.CreateExecutionEngineFacade(address); 168 retries++; 169 Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC)); 170 } 171 } while (retries < MAX_CONNECTION_RETRIES); 172 Logger.Warn("Reached max connection retries"); 173 return null; 174 } 145 175 } 146 176 }
Note: See TracChangeset
for help on using the changeset viewer.