Class ReadableByteChunksFrameChannel

java.lang.Object
org.apache.druid.frame.channel.ReadableByteChunksFrameChannel
All Implemented Interfaces:
Closeable, AutoCloseable, ReadableFrameChannel

public class ReadableByteChunksFrameChannel extends Object implements ReadableFrameChannel
Channel backed by a byte stream that is continuously streamed in using addChunk(byte[]). The byte stream must be in the format of a FrameFile. This class is used by FrameFileHttpResponseHandler to provide nonblocking reads from a remote http server.
  • Method Details

    • create

      public static ReadableByteChunksFrameChannel create(String id, boolean framesOnly, @Nullable WireTransferableContext wireTransferableContext)
      Create a channel that aims to limit its memory footprint to one frame. The channel exerts backpressure from addChunk(byte[]) immediately once a full frame has been buffered.
      Parameters:
      id - identifier for this channel
      framesOnly - if true, expects stream to include only FRAMES part (no header or footer)
      wireTransferableContext - context for wire transfer serde
    • addChunk

      @Nullable public com.google.common.util.concurrent.ListenableFuture<?> addChunk(byte[] chunk)
      Adds a chunk of bytes. If this chunk forms a full frame, it will immediately become available for reading. Otherwise, the bytes will be buffered until a full frame is encountered. Returns a backpressure future if the amount of queued bytes is at or above this channel's limit. If the return future is nonnull, callers are politely requested to wait for the future to resolve before adding additional chunks. (This is not enforced; addChunk will continue to accept new chunks even if the channel is over its limit.) When done adding chunks call doneWriting.
      Throws:
      ChannelClosedForWritesException - if the channel is closed
    • setError

      public void setError(Throwable t)
      Clears the channel and replaces it with the given error. After calling this method, no additional chunks will be accepted.
    • doneWriting

      public void doneWriting()
      Call method when caller is done adding chunks.
    • isFinished

      public boolean isFinished()
      Description copied from interface: ReadableFrameChannel
      Returns whether this channel is finished. Finished channels will not generate any further data batches or errors. Generally, once you discover that a channel is finished, you should call ReadableFrameChannel.close() and then discard it. Note that it is possible for a channel to be unfinished and also have no available data batches or errors. This happens when it is not in a ready-for-reading state. See ReadableFrameChannel.readabilityFuture() for details.
      Specified by:
      isFinished in interface ReadableFrameChannel
    • canRead

      public boolean canRead()
      Description copied from interface: ReadableFrameChannel
      Returns whether this channel has a batch of data or error condition currently available. If this method returns true, then you can call ReadableFrameChannel.readFrame() or ReadableFrameChannel.read() to retrieve the batch or error. Note that it is possible for a channel to be unfinished and also have no available batches or errors. This happens when it is not in a ready-for-reading state. See ReadableFrameChannel.readabilityFuture() for details.
      Specified by:
      canRead in interface ReadableFrameChannel
    • read

      public RowsAndColumns read()
      Description copied from interface: ReadableFrameChannel
      Returns the next available batch of data from this channel as a RowsAndColumns. Before calling this method, you should check ReadableFrameChannel.canRead() to ensure there is a batch of data or error available.
      Specified by:
      read in interface ReadableFrameChannel
    • readabilityFuture

      public com.google.common.util.concurrent.ListenableFuture<?> readabilityFuture()
      Description copied from interface: ReadableFrameChannel
      Returns a future that will resolve when either ReadableFrameChannel.isFinished() or ReadableFrameChannel.canRead() would return true. The future will never resolve to an exception. If something exceptional has happened, the exception can be retrieved from ReadableFrameChannel.readFrame() or ReadableFrameChannel.read().
      Specified by:
      readabilityFuture in interface ReadableFrameChannel
    • close

      public void close()
      Description copied from interface: ReadableFrameChannel
      Releases any resources associated with this readable channel. After calling this, you should not call any other methods on the channel.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ReadableFrameChannel
    • getId

      public String getId()
    • getBytesAdded

      public long getBytesAdded()
    • isErrorOrFinished

      public boolean isErrorOrFinished()