Java Code Examples for org.xnio.Pooled#free()

The following examples show how to use org.xnio.Pooled#free() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XnioByteBufferPool.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PooledByteBuffer allocate() {
    final Pooled<ByteBuffer> buf = pool.allocate();
    return new PooledByteBuffer() {

        private boolean open = true;

        @Override
        public ByteBuffer getBuffer() {
            return buf.getResource();
        }

        @Override
        public void close() {
            open = false;
            buf.free();
        }

        @Override
        public boolean isOpen() {
            return open;
        }
    };
}
 
Example 2
Source File: XnioByteBufferPool.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public XnioByteBufferPool(Pool<ByteBuffer> pool) {
    this.pool = pool;
    Pooled<ByteBuffer> buf = pool.allocate();
    bufferSize = buf.getResource().remaining();
    direct = !buf.getResource().hasArray();
    buf.free();
    if(direct) {
        arrayBackedPool = new DefaultByteBufferPool(false, bufferSize);
    } else {
        arrayBackedPool = this;
    }
}
 
Example 3
Source File: XnioUnsafeDirectByteBuf.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf capacity(int newCapacity) {
    ensureAccessible();
    if (newCapacity < 0 || newCapacity > maxCapacity()) {
        throw new IllegalArgumentException("newCapacity: " + newCapacity);
    }
    Pooled<ByteBuffer> oldPooled = this.pooled;
    super.capacity(newCapacity);
    if (oldPooled != pooled) {
        oldPooled.free();
    }
    return this;
}
 
Example 4
Source File: XnioDirectByteBuf.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf capacity(int newCapacity) {
    ensureAccessible();
    if (newCapacity < 0 || newCapacity > maxCapacity()) {
        throw new IllegalArgumentException("newCapacity: " + newCapacity);
    }
    Pooled<ByteBuffer> oldPooled = this.pooled;
    super.capacity(newCapacity);
    if (oldPooled != pooled) {
        oldPooled.free();
    }
    return this;
}