Package io.grpc.netty
Class WriteQueue
- java.lang.Object
-
- io.grpc.netty.WriteQueue
-
class WriteQueue extends java.lang.Object
A queue of pending writes to aChannel
that is flushed as a single unit.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
WriteQueue.AbstractQueuedCommand
(package private) static interface
WriteQueue.QueuedCommand
Simple wrapper type around a command and its optional completion listener.private static class
WriteQueue.RunnableCommand
-
Field Summary
Fields Modifier and Type Field Description private io.netty.channel.Channel
channel
(package private) static int
DEQUE_CHUNK_SIZE
private java.lang.Runnable
later
Runnable
used to schedule work onto the tail of the event loop.private java.util.Queue<WriteQueue.QueuedCommand>
queue
private java.util.concurrent.atomic.AtomicBoolean
scheduled
-
Constructor Summary
Constructors Constructor Description WriteQueue(io.netty.channel.Channel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
drainNow()
Executes enqueued work directly on the current thread.(package private) io.netty.channel.ChannelFuture
enqueue(WriteQueue.QueuedCommand command, boolean flush)
Enqueue a write command on the channel.(package private) void
enqueue(java.lang.Runnable runnable, boolean flush)
Enqueue the runnable.private void
flush()
Process the queue of commands and dispatch them to the stream.(package private) void
scheduleFlush()
Schedule a flush on the channel.
-
-
-
Field Detail
-
DEQUE_CHUNK_SIZE
static final int DEQUE_CHUNK_SIZE
- See Also:
- Constant Field Values
-
later
private final java.lang.Runnable later
Runnable
used to schedule work onto the tail of the event loop.
-
channel
private final io.netty.channel.Channel channel
-
queue
private final java.util.Queue<WriteQueue.QueuedCommand> queue
-
scheduled
private final java.util.concurrent.atomic.AtomicBoolean scheduled
-
-
Method Detail
-
scheduleFlush
void scheduleFlush()
Schedule a flush on the channel.
-
enqueue
@CanIgnoreReturnValue io.netty.channel.ChannelFuture enqueue(WriteQueue.QueuedCommand command, boolean flush)
Enqueue a write command on the channel.- Parameters:
command
- a write to be executed on the channel.flush
- true if a flush of the write should be schedule, false if a later call to enqueue will schedule the flush.
-
enqueue
void enqueue(java.lang.Runnable runnable, boolean flush)
Enqueue the runnable. It is not safe for another thread to queue an Runnable directly to the event loop, because it will be out-of-order with writes. This method allows the Runnable to be processed in-order with writes.
-
drainNow
void drainNow()
Executes enqueued work directly on the current thread. This can be used to trigger writes before performing additional reads. Must be called from the event loop. This method makes no guarantee that the work queue is empty when it returns.
-
flush
private void flush()
Process the queue of commands and dispatch them to the stream. This method is only called in the event loop
-
-