Class OutputChannel

java.lang.Object
org.apache.druid.frame.processor.OutputChannel

public class OutputChannel extends Object
Represents an output channel for some frame processor. Composed of a pair of WritableFrameChannel, which the processor writes to, along with a supplier of a ReadableFrameChannel, which readers can read from. At the time an instance of this class is created, the writable channel is already open, but the readable channel has not yet been created. It is created upon the first call to getReadableChannel().
  • Method Details

    • pair

      public static OutputChannel pair(WritableFrameChannel writableChannel, MemoryAllocator frameMemoryAllocator, Supplier<ReadableFrameChannel> readableChannelSupplier, int partitionNumber)
      Creates an output channel pair, where the readable channel is not usable until writing is complete.
      Parameters:
      writableChannel - writable channel for producer
      frameMemoryAllocator - memory allocator for producer to use while writing frames to the channel
      readableChannelSupplier - readable channel for consumer. May be called multiple times, so you should wrap this in Suppliers.memoize(com.google.common.base.Supplier<T>) if needed.
      partitionNumber - partition number, if any; may be FrameWithPartition.NO_PARTITION if unknown
    • immediatelyReadablePair

      public static OutputChannel immediatelyReadablePair(WritableFrameChannel writableChannel, MemoryAllocator frameMemoryAllocator, ReadableFrameChannel readableChannel, int partitionNumber)
      Creates an output channel pair, where the readable channel is usable before writing is complete.
      Parameters:
      writableChannel - writable channel for producer
      frameMemoryAllocator - memory allocator for producer to use while writing frames to the channel
      readableChannel - readable channel for consumer
      partitionNumber - partition number, if any; may be FrameWithPartition.NO_PARTITION if unknown
    • readOnly

      public static OutputChannel readOnly(ReadableFrameChannel readableChannel, int partitionNumber)
      Creates a read-only output channel.
      Parameters:
      readableChannel - readable channel for consumer.
      partitionNumber - partition number, if any; may be FrameWithPartition.NO_PARTITION if unknown
    • readOnly

      public static OutputChannel readOnly(Supplier<ReadableFrameChannel> readableChannelSupplier, int partitionNumber)
      Creates a read-only output channel.
      Parameters:
      readableChannelSupplier - readable channel for consumer. May be called multiple times, so you should wrap this in Suppliers.memoize(com.google.common.base.Supplier<T>) if needed.
      partitionNumber - partition number, if any; may be FrameWithPartition.NO_PARTITION if unknown
    • nil

      public static OutputChannel nil(int partitionNumber)
      Create a nil output channel, representing a processor that writes nothing. It is not actually writable, but provides a way for downstream processors to read nothing.
    • getWritableChannel

      public WritableFrameChannel getWritableChannel()
      Returns the writable channel of this pair. The producer writes to this channel. Throws ISE if the output channel is read only.
    • getFrameMemoryAllocator

      public MemoryAllocator getFrameMemoryAllocator()
      Returns the memory allocator for the writable channel. The producer uses this to generate frames for the channel. Throws ISE if the output channel is read only.
    • getReadableChannel

      public ReadableFrameChannel getReadableChannel()
      Returns the readable channel of this pair. This readable channel may, or may not, be usable before the writable channel is closed. It depends on how the channel pair was created.
    • getReadableChannelSupplier

      public Supplier<ReadableFrameChannel> getReadableChannelSupplier()
    • getPartitionNumber

      public int getPartitionNumber()
    • mapWritableChannel

    • readOnly

      public OutputChannel readOnly()
      Returns a read-only version of this instance. Read-only versions have neither getWritableChannel() nor getFrameMemoryAllocator(), and therefore require substantially less memory. Returns the same instance if it is already read-only.
    • isReadOnly

      public boolean isReadOnly()
      Returns whether this instance is read-only (has no writable channel).
    • convertToReadOnly

      public void convertToReadOnly()
      Removes the reference to the writableChannel and frameMemoryAllocator from the object, making it more efficient