// Scan queue for data to write from first non stalled stream.
int index = 0; // The index of the first non-stalled frame.
int size = queue.size();
while (index < size)
{
FrameBytes frameBytes = queue.getUnsafe(index);
IStream stream = frameBytes.getStream();
if (stream != null)
{
// Is it a frame belonging to an already stalled stream ?
if (stalled.size() > 0 && stalled.contains(stream))
{
++index;
continue;
}
// Has the stream consumed all its flow control window ?
if (stream.getWindowSize() <= 0)
{
stalled.add(stream);
++index;
continue;
}
}
// We will be possibly writing this frame, so take the frame off the queue.
queue.remove(index);
--size;
// Has the stream been reset for this data frame ?
if (stream != null && stream.isReset() && frameBytes instanceof StandardSession.DataFrameBytes)
{
// TODO: notify from within sync block !
frameBytes.failed(new StreamException(frameBytes.getStream().getId(),
StreamStatus.INVALID_STREAM, "Stream: " + frameBytes.getStream() + " is reset!"));
continue;
}
active.add(frameBytes);
}