Sha256: 9b0fef7edcba177c571683be6551385a4b1d597aa72157e05dff46ad2221838a

Contents?: true

Size: 1.43 KB

Versions: 19

Compression:

Stored size: 1.43 KB

Contents

package org.embulk.exec;

import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.ByteBuf;
import io.netty.util.ResourceLeakDetector;
import org.embulk.spi.Buffer;
import org.embulk.spi.BufferAllocator;

public class PooledBufferAllocator
        implements BufferAllocator
{
    private PooledByteBufAllocator nettyBuffer;

    public PooledBufferAllocator()
    {
        // TODO configure parameters
        this.nettyBuffer = new PooledByteBufAllocator(false);
    }

    public Buffer allocate()
    {
        return new NettyByteBufBuffer(nettyBuffer.buffer());
    }

    public Buffer allocate(int minimumCapacity)
    {
        int size = 32*1024;
        while (size < minimumCapacity) {
            size *= 2;
        }
        return new NettyByteBufBuffer(nettyBuffer.buffer(size));
    }

    private static class NettyByteBufBuffer
            extends Buffer
    {
        private ByteBuf buf;
        private Exception doubleFreeCheck;

        public NettyByteBufBuffer(ByteBuf buf)
        {
            super(buf.array(), buf.arrayOffset(), buf.capacity());
            this.buf = buf;
        }

        public void release()
        {
            if (doubleFreeCheck != null) {
                doubleFreeCheck.printStackTrace();
            }
            if (buf != null) {
                buf.release();
                buf = null;
                doubleFreeCheck = new NullPointerException();
            }
        }
    }
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
embulk-0.5.1 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.5.0 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.10 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.9 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.8 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.7 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.6 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.5 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.4 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.3 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.2 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.1 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.4.0 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.3.2 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.3.1 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.3.0 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.2.1 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.2.0 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java
embulk-0.1.0 embulk-core/src/main/java/org/embulk/exec/PooledBufferAllocator.java