I did something very similar once in [meshy](https://github.com/addthis/meshy) for controlling the queue state of runnables that produce stream data in response to windowing messages. There was an extra complication or two for my case but I think "window remaining == 0" and "pending entries == 0" are the analogous concepts. Anyway...

try this:

https://github.com/tea-dragon/netty/commit/5d5912c1e6d1fc03c59fe71de195013611decf29