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);
}
}
}
Aggregations