Package io.grpc.netty

Class WriteQueue


  • class WriteQueue
    extends java.lang.Object
    A queue of pending writes to a Channel that is flushed as a single unit.
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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
      • scheduled

        private final java.util.concurrent.atomic.AtomicBoolean scheduled
    • Constructor Detail

      • WriteQueue

        public WriteQueue​(io.netty.channel.Channel channel)
    • 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