Class BufferedContentChannel

  • All Implemented Interfaces:
    ContentChannel

    public final class BufferedContentChannel
    extends java.lang.Object
    implements ContentChannel
    This class implements an unlimited, non-blocking content queue. All ContentChannel methods are implemented by pushing to a thread-safe internal queue. All of the queued calls are forwarded to another ContentChannel when connectTo(ContentChannel) is called. Once connected, this class becomes a non-buffering proxy for the connected ContentChannel.
    Author:
    Simon Thoresen Hult
    • Constructor Detail

      • BufferedContentChannel

        public BufferedContentChannel()
    • Method Detail

      • connectTo

        public void connectTo​(ContentChannel content)

        Connects this BufferedContentChannel to a ContentChannel. First, this method forwards all queued calls to the connected ContentChannel. Once this method has been called, all future calls to write(ByteBuffer, CompletionHandler) and close(CompletionHandler) are synchronously forwarded to the connected ContentChannel.

        Parameters:
        content - The ContentChannel to connect to.
        Throws:
        java.lang.NullPointerException - If the content argument is null.
        java.lang.IllegalStateException - If another ContentChannel has already been connected.
      • write

        public void write​(java.nio.ByteBuffer buf,
                          CompletionHandler handler)
        Description copied from interface: ContentChannel
        Schedules the given ByteBuffer to be written to the content corresponding to this ContentChannel. This call transfers ownership of the given ByteBuffer to this ContentChannel, i.e. no further calls can be made to the buffer. The execution of writes happen in the same order as this method was invoked.
        Specified by:
        write in interface ContentChannel
        Parameters:
        buf - The ByteBuffer to schedule for write. No further calls can be made to this buffer.
        handler - The CompletionHandler to call after the write has been executed.