Exemple #1
0
        IByteBuffer Wrap(IByteBuffer buffer)
        {
            var         tracker      = new NoopResourceLeakTracker();
            IByteBuffer leakAwareBuf = this.Wrap(buffer, tracker);

            this.trackers.Enqueue(tracker);
            return(leakAwareBuf);
        }
        protected sealed override IByteBuffer Wrap(CompositeByteBuffer buffer)
        {
            var tracker      = new NoopResourceLeakTracker();
            var leakAwareBuf = (WrappedCompositeByteBuffer)this.Wrap(buffer, tracker);

            this.trackers.Enqueue(tracker);
            return(leakAwareBuf);
        }
        public void AddComponentWithLeakAwareByteBuf()
        {
            NoopResourceLeakTracker tracker = new NoopResourceLeakTracker();

            var buffer       = Unpooled.WrappedBuffer(Encoding.ASCII.GetBytes("hello world")).Slice(6, 5);
            var leakAwareBuf = Wrap(buffer, tracker);

            var composite = Unpooled.CompositeBuffer();

            composite.AddComponent(true, leakAwareBuf);
            byte[]      result = new byte[5];
            IByteBuffer bb     = composite[0];

            //System.out.println(bb);
            bb.ReadBytes(result);
            Assert.Equal(Encoding.ASCII.GetBytes("world"), result);
            composite.Release();
        }
        public override void Dispose()
        {
            base.Dispose();

            for (; ;)
            {
                NoopResourceLeakTracker tracker = null;
                if (this.trackers.Count > 0)
                {
                    tracker = this.trackers.Dequeue();
                }

                if (tracker == null)
                {
                    break;
                }

                Assert.True(tracker.Closed);
            }
        }