public virtual void waitForJobExecutorOnCondition(long maxMillisToWait, long intervalMillis, Callable <bool> condition) { JobExecutor jobExecutor = processEngineConfiguration.JobExecutor; jobExecutor.start(); try { Timer timer = new Timer(); InteruptTask task = new InteruptTask(Thread.CurrentThread); timer.schedule(task, maxMillisToWait); bool conditionIsViolated = true; try { while (conditionIsViolated) { Thread.Sleep(intervalMillis); conditionIsViolated = !condition.call(); } } catch (InterruptedException) { } catch (Exception e) { throw new ProcessEngineException("Exception while waiting on condition: " + e.Message, e); } finally { timer.cancel(); } if (conditionIsViolated) { throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded"); } } finally { jobExecutor.shutdown(); } }
////////// helper methods //////////////////////////// public virtual void WaitForJobExecutorToProcessAllJobs(long maxMillisToWait, int intervalMillis, ESS.FW.Bpm.Engine.Impl.JobExecutor.JobExecutor jobExecutor, IRuntimeService runtimeService, bool shutdown) { try { InteruptTask task = new InteruptTask(Thread.CurrentThread); System.Threading.Timer timer = new Timer(task.Run, null, maxMillisToWait, 0); bool areJobsAvailable = true; try { while (areJobsAvailable && !task.TimeLimitExceeded) { Thread.Sleep(intervalMillis); areJobsAvailable = AreJobsAvailable(runtimeService); } } catch (ThreadInterruptedException e) { } finally { timer.Change(-1, 0); } if (areJobsAvailable) { throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded"); } } finally { if (shutdown) { jobExecutor.Shutdown(); } } }
//////////////////////// copied from AbstractActivitiTestcase public virtual void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) { JobExecutor jobExecutor = processEngineConfiguration.JobExecutor; jobExecutor.start(); try { Timer timer = new Timer(); InteruptTask task = new InteruptTask(Thread.CurrentThread); timer.schedule(task, maxMillisToWait); bool areJobsAvailable = true; try { while (areJobsAvailable && !task.TimeLimitExceeded) { Thread.Sleep(intervalMillis); areJobsAvailable = areJobsAvailable(); } } catch (InterruptedException) { } finally { timer.cancel(); } if (areJobsAvailable) { throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded"); } } finally { jobExecutor.shutdown(); } }