Esempio n. 1
0
        public BasicProperties RentBasicProperties()
        {
            var properties = _propertiesPool.GetObject();

            properties.ResetSafeFlags();
            return(properties);
        }
Esempio n. 2
0
        internal Task __BasicPublishTask(string exchange, string routingKey, bool mandatory,
                                         BasicProperties properties, ArraySegment <byte> buffer)
        {
            if (properties == null)
            {
                properties = BasicProperties.Empty;
            }

            var tcs  = new TaskCompletionSource <bool>();
            var args = _basicPubArgsPool.GetObject();

            args.exchange   = exchange;
            args.routingKey = routingKey;
            args.mandatory  = mandatory;
            args.properties = properties;
            args.buffer     = buffer;

            _connectionIo.SendCommand(_channelNum, 60, 40,
                                      null, // AmqpChannelLevelFrameWriter.InternalBasicPublish,
                                      reply: (channel, classMethodId, error) =>
            {
                if (properties.IsReusable)
                {
                    _channel.Return(properties);                             // the tcs is left for the confirmation keeper
                }

                if (error == null)
                {
                    tcs.TrySetResult(true);
                }
                else
                {
                    AmqpIOBase.SetException(tcs, error, classMethodId);
                }
            },
                                      expectsReply: false,
//				tcsL: null,
                                      optArg: args);

            return(tcs.Task);
        }
Esempio n. 3
0
        public void ConsistencyCheck(int howManyThreads, int poolSize)
        {
            var iterations = 100000;

            _pool = new ObjectPoolArray <FakeRecycleableObj>(
                () => new FakeRecycleableObj(i => _pool.PutObject(i)),
                poolSize, preInitialize: true, ignoreDispose: false);

            var countDown = new CountdownEvent(howManyThreads);
            var hasError  = false;

            for (int i = 0; i < howManyThreads; i++)
            {
                ThreadFactory.BackgroundThread(() =>
                {
                    try
                    {
                        for (int j = 0; j < iterations; j++)
                        {
                            var obj = _pool.GetObject();
                            if (i % 20 == 0)
                            {
                                Thread.Sleep(_rnd.Next(1, 3));                // some entropy
                            }
                            obj.Use("something");                             // Use will recycle itself
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex);
                        hasError = true;
                    }
                    finally
                    {
                        countDown.Signal();
                    }
                }, "Test_" + i);
            }

            countDown.Wait();

            _pool.DumpDiagnostics();

            Assert.False(hasError, "Not expecting to have error(s)");
        }