public virtual void WaitForJobExecutorToProcessAllJobs(long maxMillisToWait)
        {
            var jobExecutor = processEngineConfiguration.JobExecutor;

            jobExecutor.Start();
            int intervalMillis = 1000;

            var jobExecutorWaitTime = jobExecutor.WaitTimeInMillis * 2;

            if (maxMillisToWait < jobExecutorWaitTime)
            {
                maxMillisToWait = jobExecutorWaitTime;
            }

            try
            {
                InterruptTask task  = new InterruptTask(Thread.CurrentThread);
                Timer         timer = new Timer(task.Run, null, maxMillisToWait, 0);

                bool areJobsAvailable = true;
                try
                {
                    while (areJobsAvailable && !task.TimeLimitExceeded)
                    {
                        Thread.Sleep(intervalMillis);
                        try
                        {
                            areJobsAvailable = AreJobsAvailable();
                        }
                        catch (System.Exception e)
                        {
                            // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
                            // isolation level doesn't allow READ of the table
                            string msg = "error";
                        }
                    }
                }
                catch (ThreadInterruptedException e)
                {
                    var msg = e.Message;
                }
                finally
                {
                    timer.Change(-1, 0);
                }
                if (areJobsAvailable)
                {
                    throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
                }
            }
            finally
            {
                jobExecutor.Shutdown();
            }
        }
Esempio n. 2
0
        public virtual void waitForJobExecutorToProcessAllJobs(long maxMillisToWait)
        {
            ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl)processEngine.ProcessEngineConfiguration;
            JobExecutor jobExecutor = processEngineConfiguration.JobExecutor;

            jobExecutor.start();
            long intervalMillis = 1000;

            int jobExecutorWaitTime = jobExecutor.WaitTimeInMillis * 2;

            if (maxMillisToWait < jobExecutorWaitTime)
            {
                maxMillisToWait = jobExecutorWaitTime;
            }

            try
            {
                Timer         timer = new Timer();
                InterruptTask task  = new InterruptTask(Thread.CurrentThread);
                timer.schedule(task, maxMillisToWait);
                bool areJobsAvailable = true;
                try
                {
                    while (areJobsAvailable && !task.TimeLimitExceeded)
                    {
                        Thread.Sleep(intervalMillis);
                        try
                        {
                            areJobsAvailable = areJobsAvailable();
                        }
                        catch (Exception)
                        {
                            // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
                            // isolation level doesn't allow READ of the table
                        }
                    }
                }
                catch (InterruptedException)
                {
                }
                finally
                {
                    timer.cancel();
                }
                if (areJobsAvailable)
                {
                    throw new AssertionError("time limit of " + maxMillisToWait + " was exceeded");
                }
            }
            finally
            {
                jobExecutor.shutdown();
            }
        }
Esempio n. 3
0
        public virtual void waitForJobExecutorOnCondition(long maxMillisToWait, Callable <bool> condition)
        {
            JobExecutor jobExecutor = processEngineConfiguration.JobExecutor;

            jobExecutor.start();
            long intervalMillis = 500;

            if (maxMillisToWait < (jobExecutor.WaitTimeInMillis * 2))
            {
                maxMillisToWait = (jobExecutor.WaitTimeInMillis * 2);
            }

            try
            {
                Timer         timer = new Timer();
                InterruptTask task  = new InterruptTask(Thread.CurrentThread);
                timer.schedule(task, maxMillisToWait);
                bool conditionIsViolated = true;
                try
                {
                    while (conditionIsViolated && !task.TimeLimitExceeded)
                    {
                        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();
            }
        }
        public virtual void WaitForJobExecutorOnCondition(long maxMillisToWait, Func <bool> condition)
        {
            var jobExecutor = processEngineConfiguration.JobExecutor;

            jobExecutor.Start();
            int intervalMillis = 500;

            if (maxMillisToWait < (jobExecutor.WaitTimeInMillis * 2))
            {
                maxMillisToWait = (jobExecutor.WaitTimeInMillis * 2);
            }

            try
            {
                InterruptTask          task  = new InterruptTask(Thread.CurrentThread);
                System.Threading.Timer timer = new Timer(task.Run, null, maxMillisToWait, 0);

                bool conditionIsViolated = true;
                try
                {
                    while (conditionIsViolated && !task.TimeLimitExceeded)
                    {
                        Thread.Sleep(intervalMillis);
                        conditionIsViolated = !condition();
                    }
                }
                catch (ThreadInterruptedException e)
                {
                }
                catch (System.Exception e)
                {
                    throw new ProcessEngineException("Exception while waiting on condition: " + e.Message, e);
                }
                finally
                {
                    timer.Change(-1, 0);
                }
                if (conditionIsViolated)
                {
                    throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
                }
            }
            finally
            {
                jobExecutor.Shutdown();
            }
        }
Esempio n. 5
0
        private IEnumerator <Task> AcquireOneInterrupted(Process p, object data)
        {
            IResource r = (IResource)data;
            Task      t = new InterruptTask(p.Simulation);

            p.WaitOnTask(t, t.Priority + 10);
            Assert.AreEqual(1, t.BlockCount);

            yield return(r.Acquire(p));

            // The InterruptTask should interrupt us here.
            Assert.IsTrue(p.Interrupted);
            yield return(p.Delay(3));

            // After a delay, the interrupt flag should be cleared.
            Assert.IsTrue(!p.Interrupted);
            yield break;
        }
Esempio n. 6
0
        public virtual void WaitForJobExecutorToProcessAllJobs(long maxMillisToWait)
        {
            ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl)ProcessEngine.ProcessEngineConfiguration;

            ESS.FW.Bpm.Engine.Impl.JobExecutor.JobExecutor jobExecutor = processEngineConfiguration.JobExecutor;
            jobExecutor.Start();
            int intervalMillis = 1000;

            int jobExecutorWaitTime = jobExecutor.WaitTimeInMillis * 2;

            if (maxMillisToWait < jobExecutorWaitTime)
            {
                maxMillisToWait = jobExecutorWaitTime;
            }

            try
            {
                InterruptTask          task  = new InterruptTask(Thread.CurrentThread);
                System.Threading.Timer timer = new System.Threading.Timer(task.Run, null, maxMillisToWait, 0);

                bool areJobsAvailable = true;
                try
                {
                    while (areJobsAvailable && !task.TimeLimitExceeded)
                    {
                        Thread.Sleep(intervalMillis);
                        try
                        {
                            areJobsAvailable = AreJobsAvailable();
                        }
                        catch (System.Exception ex)
                        {
                            // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
                            // isolation level doesn't allow READ of the table
                        }
                    }
                }
                catch (ThreadInterruptedException e)
                {
                }
                finally
                {
                    timer.Change(-1, 0);
                }
                if (areJobsAvailable)
                {
                    throw new AssertionException("time limit of " + maxMillisToWait + " was exceeded");
                }
            }
            finally
            {
                jobExecutor.Shutdown();
            }

            //try
            //{
            //    Timer timer = new Timer();
            //    InterruptTask task = new InterruptTask(Thread.CurrentThread);
            //    timer.Schedule(task, maxMillisToWait);
            //    bool areJobsAvailable = true;
            //    try
            //    {
            //        while (areJobsAvailable && !task.TimeLimitExceeded)
            //        {
            //            Thread.Sleep(intervalMillis);
            //            try
            //            {
            //                areJobsAvailable = areJobsAvailable();
            //            }
            //            catch (Exception)
            //            {
            //                // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
            //                // isolation level doesn't allow Permissions.Read of the table
            //            }
            //        }
            //    }
            //    //catch (InterruptedException)
            //    //{
            //    //}
            //    finally
            //    {
            //        timer.Cancel();
            //    }
            //    if (areJobsAvailable)
            //    {
            //        throw new AssertionError("time limit of " + maxMillisToWait + " was exceeded");
            //    }

            //}
            //finally
            //{
            //    jobExecutor.Shutdown();
            //}
        }