Stores the work group along with the smart thread pool work items group
예제 #1
0
        /// <summary>
        /// Adds a new work group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="concurrencyLevel">The concurrency level.</param>
        /// <param name="maxQueueSize">Maximum size of the queue. Work groups have a queue that is separate per queue, and is not shared with non work group items</param>
        /// <returns></returns>
        /// <exception cref="DotNetWorkQueueException">Start must be called on the scheduler before adding work groups</exception>
        public override IWorkGroup AddWorkGroup(string name, int concurrencyLevel, int maxQueueSize)
        {
            ThrowIfDisposed();

            var group = new WorkGroup(name, concurrencyLevel, maxQueueSize);

            if (_groups.ContainsKey(group))
            {
                return(_groups[group].GroupInfo);
            }

            var groupWithItem = new WorkGroupWithItem(group, _metrics.Counter(
                                                          $"work group {name}", Units.Items));

            _groups.TryAdd(group, groupWithItem);
            return(groupWithItem.GroupInfo);
        }
예제 #2
0
        /// <summary>
        /// Adds a new work group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="concurrencyLevel">The concurrency level.</param>
        /// <param name="maxQueueSize">Maximum size of the queue. Work groups have a queue that is separate per queue, and is not shared with non work group items</param>
        /// <returns></returns>
        /// <exception cref="DotNetWorkQueueException">Start must be called on the scheduler before adding work groups</exception>
        public override IWorkGroup AddWorkGroup(string name, int concurrencyLevel, int maxQueueSize)
        {
            ThrowIfDisposed();

            if (_smartThreadPool == null)
            {
                throw new DotNetWorkQueueException("Start must be called on the scheduler before adding work groups");
            }

            var group = new WorkGroup(name, concurrencyLevel, maxQueueSize);

            if (_groups.ContainsKey(group))
            {
                return(_groups[group].GroupInfo);
            }

            var groupWithItem = new WorkGroupWithItem(group, Policy.Bulkhead(concurrencyLevel, maxQueueSize, OnBulkheadRejected), _metrics.Counter(
                                                          $"work group {name}", Units.Items));

            _groups.TryAdd(group, groupWithItem);
            return(groupWithItem.GroupInfo);
        }
예제 #3
0
        /// <summary>
        /// Adds a new work group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="concurrencyLevel">The concurrency level.</param>
        /// <param name="maxQueueSize">Maximum size of the queue. Work groups have a queue that is separate per queue, and is not shared with non work group items</param>
        /// <returns></returns>
        /// <exception cref="DotNetWorkQueueException">Start must be called on the scheduler before adding work groups</exception>
        public override IWorkGroup AddWorkGroup(string name, int concurrencyLevel, int maxQueueSize)
        {
            ThrowIfDisposed();

            if (_smartThreadPool == null)
                throw new DotNetWorkQueueException("Start must be called on the scheduler before adding work groups");

            var group = new WorkGroup(name, concurrencyLevel, maxQueueSize);
            if (_groups.ContainsKey(group)) return _groups[group].GroupInfo;

            var startInfo = new WIGStartInfo
            {
                PostExecuteWorkItemCallback = PostExecuteWorkItemCallback
            };
            var groupWithItem = new WorkGroupWithItem(group, _smartThreadPool.CreateWorkItemsGroup(concurrencyLevel, startInfo), _metrics.Counter(
                $"work group {name}", Units.Items));
            _groups.TryAdd(group, groupWithItem);
            return groupWithItem.GroupInfo;
        }