Пример #1
0
        /// <summary>
        /// @see IJobOperator#Stop .
        /// </summary>
        /// <param name="executionId"></param>
        /// <returns></returns>
        /// <exception cref="NoSuchJobException">&nbsp;</exception>
        /// <exception cref="JobExecutionNotRunningException">&nbsp;</exception>
        public bool Stop(long executionId)
        {
            JobExecution jobExecution = FindExecutionById(executionId);
            // Indicate the execution should be stopped by setting it's status to
            // 'STOPPING'. It is assumed that
            // the step implementation will check this status at chunk boundaries.
            BatchStatus status = jobExecution.Status;

            if (!(status == BatchStatus.Started || status == BatchStatus.Starting))
            {
                throw new JobExecutionNotRunningException(
                          string.Format("JobExecution must be running so that it can be stopped: {0}", jobExecution));
            }
            jobExecution.Status = BatchStatus.Stopping;
            JobRepository.Update(jobExecution);

            try
            {
                IJob job     = JobRegistry.GetJob(jobExecution.JobInstance.JobName);
                var  locator = job as IStepLocator;
                if (locator != null)
                {
                    //can only process as StepLocator is the only way to get the step object
                    //get the current stepExecution
                    foreach (StepExecution stepExecution in jobExecution.StepExecutions)
                    {
                        if (stepExecution.BatchStatus.IsRunning())
                        {
                            try
                            {
                                //have the step execution that's running -> need to 'stop' it
                                IStep step        = locator.GetStep(stepExecution.StepName);
                                var   taskletStep = step as TaskletStep;
                                if (taskletStep != null)
                                {
                                    ITasklet tasklet          = taskletStep.Tasklet;
                                    var      stoppableTasklet = tasklet as IStoppableTasklet;
                                    if (stoppableTasklet != null)
                                    {
                                        StepSynchronizationManager.Register(stepExecution);
                                        stoppableTasklet.Stop();
                                        StepSynchronizationManager.Release();
                                    }
                                }
                            }
                            catch (NoSuchStepException e)
                            {
                                _logger.Warn("Step not found {0}", e.Message);
                            }
                        }
                    }
                }
            }
            catch (NoSuchJobException e)
            {
                _logger.Warn("Cannot find Job object {0}", e.Message);
            }

            return(true);
        }
        public void TestGetValue()
        {
            var manager = new StepScopeLifetimeManager();

            StepSynchronizationManager.Register(_stepExecution1);

            var result = manager.GetValue();

            Assert.IsNull(result);
        }
        /// <summary>
        /// Resolve object from context.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public object Resolve(IBuilderContext context)
        {
            object value;

            StepSynchronizationManager.GetContext().GetStepExecutionContext().TryGetValue(_propertyName, out value);
            if (value == null)
            {
                throw new InvalidOperationException(string.Format("Failed to get property {0} in step context.", _propertyName));
            }
            return(value is T ? (T)value : StringConverter.Convert <T>(value.ToString()));
        }
        public void TestSetValue1()
        {
            var obj     = new object();
            var manager = new StepScopeLifetimeManager();

            StepSynchronizationManager.Register(_stepExecution1);
            manager.SetValue(obj);

            var result = manager.GetValue();

            Assert.AreEqual(obj, result);
        }
Пример #5
0
        private void Check(IUnityContainer container)
        {
            var a = container.Resolve <A>("a");

            Assert.IsNotNull(a);
            Assert.IsNotNull(a.I);
            Assert.IsTrue(a.I is IProxyObject);

            StepSynchronizationManager.Register(_stepExecution);

            Assert.IsNotNull(((IProxyObject)a.I).GetInstance());
            Assert.AreEqual("B", a.M());
        }
        private static void RegisterDestructionCallback(Tuple <Type, string> key, object instance)
        {
            var disposable = instance as IDisposable;

            if (disposable != null)
            {
                var name = key.Item1.FullName + ':' + key.Item2;
                StepSynchronizationManager.GetContext().RegisterDestructionCallback(name, new Task(() =>
                {
                    disposable.Dispose();
                }));
            }
        }
Пример #7
0
        public void TestAllInStepScope()
        {
            IUnityContainer container = new UnityContainer();

            container.AddNewExtension <StepScopeExtension>();
            container.RegisterStepScope <A>("a", new InjectionConstructor(new ResolvedParameter <B>("i")));
            container.RegisterStepScope <B>("i");

            StepSynchronizationManager.Register(_stepExecution);

            var a = container.Resolve <A>("a");

            Assert.IsNotNull(a.I);
            Assert.IsFalse(a.I is IProxyObject);
        }
Пример #8
0
 /// <summary>
 /// Stores an object for the current step.
 /// </summary>
 /// <param name="newValue">the object to store</param>
 public override void SetValue(object newValue)
 {
     if (!(newValue is IProxyObject))
     {
         Context.SetAttribute(_name, newValue);
         var disposable = newValue as IDisposable;
         if (disposable != null)
         {
             StepSynchronizationManager.GetContext().RegisterDestructionCallback(_name, new Task(() =>
             {
                 disposable.Dispose();
             }));
         }
     }
 }
Пример #9
0
 /// <summary>
 /// Registers the StepExecution for property resolution via StepScope
 /// </summary>
 /// <param name="stepExecution"></param>
 protected void DoExecutionRegistration(StepExecution stepExecution)
 {
     StepSynchronizationManager.Register(stepExecution);
 }
Пример #10
0
 /// <summary>
 /// Releases the most recent StepExecution
 /// </summary>
 protected void DoExecutionRelease()
 {
     StepSynchronizationManager.Release();
 }