Beispiel #1
0
        public override TPoolItem Get()
        {
            var item = _innerPool.Take();

            if (null == item)
            {
                item = _policy.Create();
            }

            return(_policy.PreGetting(item));
        }
Beispiel #2
0
        /// <summary>
        /// Get object from pool, if not available create as per supplied policy.
        /// It uses concurrent queue as backing store, as soon queue is empty, queue will be filled again.
        /// </summary>
        /// <returns></returns>
        public override Application Get()
        {
            var x = _concurrentQueue.TryDequeue(out Application application);

            Task.Run(() =>
            {
                if (_concurrentQueue.Count == 0)
                {
                    FillQueue();
                }
            }).ConfigureAwait(false);


            return(x ? application : _policy.Create());
        }
Beispiel #3
0
        public override T Get()
        {
            for (var i = 0; i < _items.Length; i++)
            {
                var item = _items[i];
                if (item != null && Interlocked.CompareExchange(ref _items[i], null, item) == item)
                {
                    return(item);
                }
            }

            return(_policy.Create());
        }
Beispiel #4
0
        public override T Get()
        {
            T obj;

            if (_pool.TryDequeue(out obj))
            {
                return(obj);
            }
            else
            {
                return(_policy.Create());
            }
        }
        public RabbitWorker(ILoggerFactory loggerFactory, IOptions <RabbitOptions> options, IServiceScopeFactory scopeFactory)
        {
            _logger       = loggerFactory.CreateLogger <RabbitWorker>();
            _options      = options.Value;
            _scopeFactory = scopeFactory;

            using (var serviceScope = scopeFactory.CreateScope())
            {
                _provider = serviceScope.ServiceProvider.GetRequiredService <IPooledObjectPolicy <IModel> >();
                _channel  = _provider.Create();
            }

            Console.Write("=== Rabbit Connection Setup Successfull ===");
        }
Beispiel #6
0
        public bool TryPop([NotNullWhen(true)] out T?obj)
        {
            var nextIndex = Interlocked.Increment(ref _index) - 1;

            if (nextIndex < _capacity)
            {
                if (_buffer[nextIndex] is { } o)
                {
                    obj = o;
                    return(true);
                }

                obj = _policy.Create();
                _buffer[nextIndex] = obj;
                return(true);
            }

            obj = null;
            return(false);
        }
    public bool TryPop([NotNullWhen(true)] out T?obj)
    {
        var nextIndex = _index++;

        if (nextIndex < _capacity)
        {
            if (_buffer[nextIndex] is { } o)
            {
                obj = o;
                return(true);
            }

            obj = _policy.Create();
            _buffer[nextIndex] = obj;
            return(true);
        }

        obj = null;
        return(false);
    }
 public override WeakReference <T> Create()
 {
     return(new WeakReference <T>(_policy.Create()));
 }
 public override T Get()
 {
     return(_policy.Create());
 }
 private T Create() => _fastPolicy?.Create() ?? _policy.Create();
Beispiel #11
0
 private T Create()
 {
     return(_policy.Create());
 }
Beispiel #12
0
 public RabbitBaseListener(IPooledObjectPolicy <IModel> pooledObjectPolicy)
 {
     channel = pooledObjectPolicy.Create();
 }