コード例 #1
0
        /// <summary>
        /// Starts this instance and initializes all the timers and queues.
        /// </summary>
        /// <returns></returns>
        public bool Start()
        {
            if (serviceStatus == ServiceStatus.Stopped)
            {
                CheckAbnormallyTerminatedJobs();
                CalculateJobsNextExecutionTimes();
                foreach (QueueDefinition queueDefinition in SettingsProvider.Queues)
                {
                    IExecutionQueue queue = Utils.CreateInstanceWithRequiredInterface <IExecutionQueue>(queueDefinition.Type, typeof(IExecutionQueue).AssemblyQualifiedName);
                    if (queue != null)
                    {
                        jobQueues.Add(queueDefinition.Id, queue);
                        jobQueues[queueDefinition.Id].Id                    = queueDefinition.Id;
                        jobQueues[queueDefinition.Id].ThreadCount           = queueDefinition.ThreadCount;
                        jobQueues[queueDefinition.Id].JobFinishedExecuting += new EventHandler <JobFinishedExecutingEventArgs>(Queue_JobFinishedExecuting);
                    }
                }

                //To change the accuracy of scheduled jobs, this interval can be changed.
                pollTimer.Interval = SettingsProvider.PollFrequency.TotalMilliseconds;
                pollTimer.Start();

                serviceStatus = ServiceStatus.Running;
                return(true);
            }
            else if (serviceStatus == ServiceStatus.Paused)
            {
                return(Resume());
            }
            return(false);
        }
コード例 #2
0
ファイル: QueuePresenter.cs プロジェクト: larsw/storyteller
        public QueuePresenter(IQueueView view, IExecutionQueue queue, IQueuedItemFactory factory)
        {
            _queue = queue;
            _view  = view;

            _items.OnMissing = factory.Build;
        }
コード例 #3
0
 public QueuedTestItem(Test test, IExecutionQueue queue, IScreenConductor shell)
     : this()
 {
     linkText.Content = test.LocatorPath();
     link.Click      += (x, y) => shell.OpenScreen(test);
     stop.Click      += (x, y) => queue.Cancel(test);
 }
コード例 #4
0
ファイル: TestService.cs プロジェクト: larsw/storyteller
 public TestService(IExecutionQueue queue, ITestConverter converter, IEventAggregator events,
                    FixtureLibrary library)
 {
     _queue     = queue;
     _converter = converter;
     _events    = events;
     _library   = library;
 }
コード例 #5
0
ファイル: StatusPresenter.cs プロジェクト: larsw/storyteller
 public StatusPresenter(IStatusView view, IScreenConductor shell, GrammarErrorsSubject errors,
                        IExecutionQueue queue)
 {
     _view      = view;
     _conductor = shell;
     _errors    = errors;
     _queue     = queue;
 }
コード例 #6
0
        /// <summary>
        /// Starts this instance and initializes all the timers and queues.
        /// </summary>
        /// <returns></returns>
        public bool Start()
        {
            if (serviceStatus == ServiceStatus.Stopped)
            {
                CheckAbnormallyTerminatedJobs();
                foreach (QueueDefinition queueDefinition in SettingsProvider.Queues)
                {
                    IExecutionQueue queue = (IExecutionQueue)Utils.CreateInstanceWithRequiredInterface(queueDefinition.Type, typeof(IExecutionQueue).Name);
                    if (queue != null)
                    {
                        jobQueues.Add(queueDefinition.Id, queue);
                        jobQueues[queueDefinition.Id].Id                    = queueDefinition.Id;
                        jobQueues[queueDefinition.Id].ThreadCount           = queueDefinition.ThreadCount;
                        jobQueues[queueDefinition.Id].JobFinishedExecuting += new EventHandler <JobFinishedExecutingEventArgs>(Queue_JobFinishedExecuting);
                    }
                }

                jobQueueTimer.Interval = SettingsProvider.PollFrequency.TotalMilliseconds;
                jobQueueTimer.Start();

                //To change the accuracy of scheduled jobs, this interval can be changed. However, be aware that each scheduled jobs' next occurence gets calculated on every tick.
                scheduleTimer.Interval = 1000;
                scheduleTimer.Start();

                checkForJobEnqueue  = true;
                eventTimer.Interval = 100;
                eventTimer.Start();

                serviceStatus = ServiceStatus.Running;
                return(true);
            }
            else if (serviceStatus == ServiceStatus.Paused)
            {
                return(Resume());
            }
            return(false);
        }
コード例 #7
0
        public TaskDispatcher(byte maxConcurrency, IExecutionQueue[] executionQueues)
        {
            if (maxConcurrency == 0)
            {
                throw new ArgumentOutOfRangeException("maxConcurrency", "MaxConcurrency should be greater than zero.");
            }

            if (executionQueues == null)
            {
                throw new ArgumentNullException("executionQueues");
            }

            if (executionQueues.Length == 0)
            {
                throw new ArgumentOutOfRangeException("executionQueues", "List of execution queues cannot be empty.");
            }

            if (executionQueues.Any(x => x == null))
            {
                throw new ArgumentOutOfRangeException("executionQueues", "Execution queues cannot contain null values.");
            }

            var queueTotalConcurrency = (byte)executionQueues.Sum(x => x.MaxConcurrency);

            _maxConcurrency = Math.Min(maxConcurrency, queueTotalConcurrency);
            _executionQueues = executionQueues.OrderByDescending(x => x.Priority).ToArray();

            _executionInfos = new ExecutionInfo[_maxConcurrency];
            _threadNames = Enumerable.Range(0, _maxConcurrency).Select(x => "DarkFlow#" + x).ToArray();

            foreach (var executionQueue in executionQueues)
            {
                executionQueue.TaskAdded += OnTaskAdded;
            }

            Thread.MemoryBarrier();
        }
コード例 #8
0
        private void OnTaskAdded(IExecutionQueue executor)
        {
            Contract.Require(executor != null, "executor != null");

            TryStartNewThread(executor);
        }
コード例 #9
0
        private void TryStartNewThread(IExecutionQueue executor)
        {
            BEGIN:
            if (_disposed) return;

            //Second check to ensure concurrency threshold would not be exceeded.
            var currentConcurrency = Interlocked.Increment(ref _currentConcurrency);

            if (currentConcurrency > _maxConcurrency)
            {
                currentConcurrency = Interlocked.Decrement(ref _currentConcurrency);

                if (currentConcurrency == 0)
                {
                    goto BEGIN;
                }

                return;
            }
            ExecutionEnvelope envelope;
            if (executor == null)
            {
                envelope = TakeNextTask();
            }
            else
            {
                envelope = executor.Dequeue();
            }

            if (envelope == null)
            {
                Interlocked.Decrement(ref _currentConcurrency);
                return;
            }

            if (Logger.IsDebugEnabled)
            {
                Logger.Debug("Starting new execution thread.");
            }

            var executionInfo = new ExecutionInfo { CurrentTask = envelope };

            var tplTask = new Task(PerformTasks, executionInfo);

            executionInfo.TakeFreeCell(_executionInfos, _threadNames);

            executionInfo.TplTask = tplTask;

            tplTask.Start();
        }
コード例 #10
0
 public IconService(IExecutionQueue queue)
 {
     _queue = queue;
 }
コード例 #11
0
 internal JobExecutionContext(JobContext jobContext, IExecutionQueue executionQueue, Thread thread)
     : this(jobContext, executionQueue)
 {
     Thread = thread;
 }
コード例 #12
0
 internal JobExecutionContext(JobContext jobContext, IExecutionQueue executionQueue)
 {
     JobContext     = jobContext;
     ExecutionQueue = executionQueue;
 }
コード例 #13
0
 public QueuedItemFactory(IExecutionQueue queue, IScreenConductor shell)
 {
     _queue = queue;
     _shell = shell;
 }
コード例 #14
0
ファイル: IIconService.cs プロジェクト: adymitruk/storyteller
 public IconService(IExecutionQueue queue)
 {
     _queue = queue;
 }
コード例 #15
0
 public QueuedItemFactory(IExecutionQueue queue, IScreenConductor shell)
 {
     _queue = queue;
     _shell = shell;
 }