* Peek the first buffer and inspect it to see if it needs any special handling
* If it is to large to use as part of a gathering write then branch and just focus on
* writing the one
*/
final int queuedForWrite = 0;
final BBContainer peekedBuffer = m_queuedBuffers.peek();
if (peekedBuffer.b.remaining() > MAX_GATHERING_WRITE) {
/*
* If the buffer is not direct and it is this large it should be split up in separate writes
*/
if (!peekedBuffer.b.isDirect()) {
/**
* Split a big heap byte buffer into many smaller slices
* so Java doesn't allocate a bunch of direct ByteBuffers
*/
//The source buffer for the slices that holds the memory goes in first
//so it will be discarded once all the slices have been read.
m_queuedBuffers.push(peekedBuffer);
final int originalPosition = peekedBuffer.b.position();
do {
final int amountToSplit = Math.min(peekedBuffer.b.remaining(), MAX_GATHERING_WRITE);
peekedBuffer.b.position(peekedBuffer.b.limit() - amountToSplit);
final BBContainer splice = DBBPool.wrapBB(peekedBuffer.b.slice());
m_queuedBuffers.push(splice);
m_messagesWritten--;//corrects message count
peekedBuffer.b.limit(peekedBuffer.b.position());
peekedBuffer.b.position(originalPosition);
}