Пример #1
0
        /// <summary>
        /// 处理过期或已达上限的数据
        /// </summary>
        private void Handler()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            while (true)
            {
                var count = _bag.Count;
                if (count >= _size || (count > 0 && stopwatch.ElapsedMilliseconds >= _timeout))
                {
                    var list = new List <T>();
                    for (int i = 0; i < count; i++)
                    {
                        if (_bag.TryTake(out T t))
                        {
                            list.Add(t);
                        }
                    }
                    OnBatched?.Invoke(this, list);
                    stopwatch.Restart();
                }
                else
                {
                    ThreadHelper.Sleep(_timeout);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 释放批量打包缓存
        /// </summary>
        public void Dispose()
        {
            var count = _bag.Count;

            if (count > 0)
            {
                var list = new List <T>();
                for (int i = 0; i < count; i++)
                {
                    if (_bag.TryTake(out T t))
                    {
                        list.Add(t);
                    }
                }
                OnBatched?.Invoke(this, list);
            }
        }
Пример #3
0
        private void Bacher_OnBatched(IBatcher sender, byte[] data)
        {
            var bacher = (Batcher)sender;

            OnBatched?.Invoke(bacher.Name, data);
        }
Пример #4
0
 private void _classificationBatcher_OnBatched(string id, byte[] data)
 {
     OnBatched?.Invoke(id, data);
 }