// subsequent call to setNextFreePos(), which calls moveCurrentWritePosition(),
// blows up. By normalizing the end position, we effectively block until the
// head can advance to the same position (or beyond), i.e., until all iterators
// have caught up, which allows setNextFreePos()/moveCurrentWritePosition() to
// succeed. See DDSDBUS-1816 for even more details.
final BufferPosition normalizedWriteEndPos = new BufferPosition(writeEndPos,
_bufferPositionParser,
_buffers);
normalizedWriteEndPos.skipOverFreeSpace();
boolean interrupted = false;
if (!empty())
{
if (QueuePolicy.BLOCK_ON_WRITE == _queueingPolicy)
{
interrupted = waitForReadEventsFreeSpace(logDebugEnabled, writeStartPos,
normalizedWriteEndPos.getPosition());
}
else
{
freeUpSpaceForReadEvents(logDebugEnabled, writeStartPos,
normalizedWriteEndPos.getPosition());
}
}
if (logDebugEnabled)
{
_log.debug("ensureFreeSpace: writeStart:" + _bufferPositionParser.toString(writeStartPos, _buffers) +
"; writeEnd:" + _bufferPositionParser.toString(writeEndPos, _buffers) +
"; normalizedWriteEnd:" + normalizedWriteEndPos +
"; head:" + _head + "; tail:" + _tail +
"; interrupted:" + interrupted);
}
assert interrupted || !overwritesHead(writeStartPos, normalizedWriteEndPos.getPosition());
return interrupted;
}