private void receiveLoop() {
if (isShutdown) {
return;
}
WaveletOperation next = opChannel.peek();
while (next != null && !isShutdown) {
// We flush the listener before every operation and specify what the next operation
// will be, so the listener can choose to only flush the (editor of the) affected blip.
// (Alternatively, we could tell the listener to flush everything before entering the
// receive loop and then receive and pass on all available operations without further
// flushes. That would be faster if, generally, there are more ops per batch than
// blips in the wave. We have no evidence that that's the case.)
receptionIsPaused = !listener.flush(next, resumeCallback);
if (receptionIsPaused) {
// The listener will call resume callback later, which clears receptionIsPaused
// and runs the receive loop. We stop the receive loop until then.
return;
}
// We take the next operation and pass it to the listener, if the
// operation is still the same, that is, it has not been modified
// by operation transformation against any client operations sent
// to us from within the call to serverOperationListener.flush().
// Otherwise we cycle around and call flush again, just to be sure.
WaveletOperation newNext = opChannel.peek();
if (next == newNext) {
listener.consume(opChannel.receive());
if (!isShutdown) {
next = opChannel.peek();
}