Пример #1
0
        protected virtual AcquiredJobs AcquireJobs(JobAcquisitionContext context, IJobAcquisitionStrategy acquisitionStrategy, ProcessEngineImpl currentProcessEngine)
        {
            ICommandExecutor commandExecutor = ((ProcessEngineConfigurationImpl)currentProcessEngine.ProcessEngineConfiguration).CommandExecutorTxRequired;

            var numJobsToAcquire = acquisitionStrategy.GetNumJobsToAcquire(currentProcessEngine.Name);

            AcquiredJobs acquiredJobs = null;

            if (numJobsToAcquire > 0)
            {
                JobExecutor.LogAcquisitionAttempt(currentProcessEngine);
                acquiredJobs = commandExecutor.Execute(JobExecutor.GetAcquireJobsCmd(numJobsToAcquire));
            }
            else
            {
                acquiredJobs = new AcquiredJobs(numJobsToAcquire);
            }

            context.SubmitAcquiredJobs(currentProcessEngine.Name, acquiredJobs);

            JobExecutor.LogAcquiredJobs(currentProcessEngine, acquiredJobs.Size());
            JobExecutor.LogAcquisitionFailureJobs(currentProcessEngine, acquiredJobs.NumberOfJobsFailedToLock);

            Log.AcquiredJobs(currentProcessEngine.Name, acquiredJobs);

            return(acquiredJobs);
        }
Пример #2
0
        public ProcessEngineImpl(ProcessEngineConfigurationImpl processEngineConfiguration)
        {
            this.processEngineConfiguration = processEngineConfiguration;
            Name = processEngineConfiguration.ProcessEngineName;

            RepositoryService    = processEngineConfiguration.RepositoryService;
            RuntimeService       = processEngineConfiguration.RuntimeService;
            HistoryService       = processEngineConfiguration.HistoryService;
            IdentityService      = processEngineConfiguration.IdentityService;
            TaskService          = processEngineConfiguration.TaskService;
            FormService          = processEngineConfiguration.FormService;
            ManagementService    = processEngineConfiguration.ManagementService;
            AuthorizationService = processEngineConfiguration.AuthorizationService;
            //this.caseService = processEngineConfiguration.CaseService;
            FilterService       = processEngineConfiguration.FilterService;
            ExternalTaskService = processEngineConfiguration.ExternalTaskService;
            DecisionService     = processEngineConfiguration.DecisionService;

            DatabaseSchemaUpdate            = processEngineConfiguration.DatabaseSchemaUpdate;
            JobExecutor                     = processEngineConfiguration.JobExecutor;
            commandExecutor                 = processEngineConfiguration.CommandExecutorTxRequired;
            CommandExecutorSchemaOperations = processEngineConfiguration.CommandExecutorSchemaOperations;
            //SessionFactories = processEngineConfiguration.SessionFactories;
            HistoryLevel = processEngineConfiguration.HistoryLevel;
            TransactionContextFactory = processEngineConfiguration.TransactionContextFactory;
            Log.LogDebug("使用的TransactionContextFactory:", TransactionContextFactory.GetType().Name.ToString());
            //TODO 数据库初始化入口
            //ExecuteSchemaOperations();

            if (ReferenceEquals(Name, null))
            {
                Name = ProcessEngines.NameDefault;
                Log.ProcessEngineCreated(ProcessEngines.NameDefault);
            }
            else
            {
                Log.ProcessEngineCreated(Name);
            }

            ProcessEngines.RegisterProcessEngine(this);

            if (JobExecutor != null)
            {
                JobExecutor.RegisterProcessEngine(this);
            }

            if (processEngineConfiguration.MetricsEnabled)
            {
                var reporterId        = processEngineConfiguration.MetricsReporterIdProvider.ProvideId(this);
                var dbMetricsReporter = processEngineConfiguration.DbMetricsReporter;
                dbMetricsReporter.ReporterId = reporterId;

                if (processEngineConfiguration.DbMetricsReporterActivate)
                {
                    dbMetricsReporter.Start();
                }
            }
        }
Пример #3
0
        public override void Run()
        {
            lock (this)
            {
                Log.StartingToAcquireJobs(JobExecutor.Name);

                var acquisitionStrategy = InitializeAcquisitionStrategy();

                while (!IsInterrupted)
                {
                    AcquisitionContext.Reset();
                    AcquisitionContext.AcquisitionTime = (DateTime.Now.Ticks / 10000000);//DateTime.Now.Millisecond;


                    var engineIterator = JobExecutor.EngineIterator();

                    try
                    {
                        while (engineIterator.MoveNext())
                        {
                            var currentProcessEngine = engineIterator.Current;
                            if (!JobExecutor.HasRegisteredEngine(currentProcessEngine))
                            {
                                continue;
                            }

                            var acquiredJobs = AcquireJobs(AcquisitionContext, acquisitionStrategy, currentProcessEngine);
                            ExecuteJobs(AcquisitionContext, currentProcessEngine, acquiredJobs);
                        }
                    }
                    catch (System.Exception e)
                    {
                        Log.ExceptionDuringJobAcquisition(e);

                        AcquisitionContext.AcquisitionException = e;
                    }

                    AcquisitionContext.JobAdded = IsJobAdded;
                    ConfigureNextAcquisitionCycle(AcquisitionContext, acquisitionStrategy);
                    //The clear had to be done after the configuration, since a hint can be
                    //appear in the suspend and the flag shouldn't be cleaned in this case.
                    //The loop will restart after suspend with the isJobAdded flag and
                    //reconfigure with this flag
                    ClearJobAddedNotification();

                    var waitTime = acquisitionStrategy.WaitTime;
                    // wait the requested wait time minus the time that acquisition itself took
                    // this makes the intervals of job acquisition more constant and therefore predictable
                    waitTime = Math.Max(0, (AcquisitionContext.AcquisitionTime + waitTime) - (DateTime.Now.Ticks / 10000000));
                    SuspendAcquisition(waitTime);
                }

                Log.StoppedJobAcquisition(JobExecutor.Name);
            }
        }
 public BackoffJobAcquisitionStrategy(JobExecutor jobExecutor)
     : this(jobExecutor.WaitTimeInMillis,
            jobExecutor.WaitIncreaseFactor,
            jobExecutor.MaxWait,
            jobExecutor.BackoffTimeInMillis,
            jobExecutor.WaitIncreaseFactor,
            jobExecutor.MaxBackoff,
            jobExecutor.BackoffDecreaseThreshold,
            jobExecutor.MaxJobsPerAcquisition)
 {
 }
 public virtual void run()
 {
     try
     {
         ESS.FW.Bpm.Engine.Impl.JobExecutor.JobExecutor jobExecutor = outerInstance.processEngineConfiguration.JobExecutor;
         jobs = outerInstance.processEngineConfiguration.CommandExecutorTxRequired.Execute(new ControlledCommand <AcquiredJobs>(activeThread, new AcquireJobsCmd(jobExecutor)));
     }
     catch (OptimisticLockingException e)
     {
         this.exception = e;
     }
     Debug.WriteLine(TestContext.CurrentContext.Test.Name + " ends");
 }
Пример #6
0
        protected internal virtual void ExecuteJobs(JobAcquisitionContext context, ProcessEngineImpl currentProcessEngine, AcquiredJobs acquiredJobs)
        {
            // submit those jobs that were acquired in previous cycles but could not be scheduled for execution
            var additionalJobs = context.AdditionalJobBatchesByEngine.GetValueOrNull(currentProcessEngine.Name);

            if (additionalJobs != null)
            {
                foreach (var jobBatch in additionalJobs)
                {
                    Log.ExecuteJobs(currentProcessEngine.Name, jobBatch);

                    JobExecutor.ExecuteJobs(jobBatch, currentProcessEngine);
                }
            }

            // submit those jobs that were acquired in the current cycle
            foreach (var jobIds in acquiredJobs.JobIdBatches)
            {
                Log.ExecuteJobs(currentProcessEngine.Name, jobIds);

                JobExecutor.ExecuteJobs(jobIds, currentProcessEngine);
            }
        }
Пример #7
0
        ////////// 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();
                }
            }
        }
Пример #8
0
 protected internal void setUp()
 {
     //base.SetUp();
     jobExecutor = processEngineConfiguration.JobExecutor;
 }
Пример #9
0
 public SequentialJobAcquisitionRunnable(JobExecutor jobExecutor) : base(jobExecutor)
 {
     AcquisitionContext = InitializeAcquisitionContext();
 }
Пример #10
0
 public ExecuteJobsRunnable(IList <string> jobIds, ProcessEngineImpl processEngine)
 {
     _jobIds        = jobIds;
     _processEngine = processEngine;
     _jobExecutor   = ((ProcessEngineConfigurationImpl)processEngine.ProcessEngineConfiguration).JobExecutor;
 }
 private AcquiredJobs GetExecutableJobs(ESS.FW.Bpm.Engine.Impl.JobExecutor.JobExecutor jobExecutor)
 {
     return(processEngineConfiguration.CommandExecutorTxRequired.Execute(new AcquireJobsCmd(jobExecutor)));
 }
Пример #12
0
        public virtual void JobsRejected(IList <string> jobIds, ProcessEngineImpl processEngine, JobExecutor jobExecutor)
        {
            var acquireJobsRunnable = jobExecutor.AcquireJobsRunnable;

            if (acquireJobsRunnable is SequentialJobAcquisitionRunnable)
            {
                var context = ((SequentialJobAcquisitionRunnable)acquireJobsRunnable).AcquisitionContext;
                context.SubmitRejectedBatch(processEngine.Name, jobIds);
            }
            else
            {
                jobExecutor.GetExecuteJobsRunnable(jobIds, processEngine).Run(null);
            }
        }
Пример #13
0
 public AcquireJobsRunnable(JobExecutor jobExecutor)
 {
     this.JobExecutor = jobExecutor;
 }
 public DefaultAcquireJobsCommandFactory(JobExecutor jobExecutor)
 {
     this.JobExecutor = jobExecutor;
 }
Пример #15
0
 public virtual void JobsRejected(IList <string> jobIds, ProcessEngineImpl processEngine, JobExecutor jobExecutor)
 {
     jobExecutor.GetExecuteJobsRunnable(jobIds, processEngine).Run(null);
 }
Пример #16
0
 public MessageAddedNotification(JobExecutor jobExecutor)
 {
     this.JobExecutor = jobExecutor;
 }