Class 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 Detail

      • 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​(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 whether the channel pair was created in a stream-capable manner or not. Check isReadableChannelReady() to find out.
      • isReadableChannelReady

        public boolean isReadableChannelReady()
        Whether getReadableChannel() is ready to use.
      • getPartitionNumber

        public int getPartitionNumber()