Search in sources :

Example 1 with CircularBuffer

use of com.datatorrent.netlet.util.CircularBuffer in project apex-core by apache.

the class BufferServerSubscriber method onMessage.

@Override
public void onMessage(byte[] buffer, int offset, int length) {
    Slice f;
    if (freeFragments.isEmpty()) {
        f = new Slice(buffer, offset, length);
    } else {
        f = freeFragments.pollUnsafe();
        f.buffer = buffer;
        f.offset = offset;
        f.length = length;
    }
    if (!offeredFragments.offer(f)) {
        synchronized (backlog) {
            if (!suspended) {
                suspendRead();
                suspended = true;
            }
            int newsize = offeredFragments.capacity() == MAX_SENDBUFFER_SIZE ? offeredFragments.capacity() : offeredFragments.capacity() << 1;
            backlog.add(offeredFragments = new CircularBuffer<>(newsize));
            offeredFragments.add(f);
        }
    }
}
Also used : CircularBuffer(com.datatorrent.netlet.util.CircularBuffer) Slice(com.datatorrent.netlet.util.Slice)

Aggregations

CircularBuffer (com.datatorrent.netlet.util.CircularBuffer)1 Slice (com.datatorrent.netlet.util.Slice)1