Package org.apache.druid.frame.processor
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 ofWritableFrameChannel
, which the processor writes to, along with a supplier of aReadableFrameChannel
, 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 togetReadableChannel()
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
convertToReadOnly()
Removes the reference to thewritableChannel
andframeMemoryAllocator
from the object, making it more efficientMemoryAllocator
getFrameMemoryAllocator()
Returns the memory allocator for the writable channel.int
getPartitionNumber()
ReadableFrameChannel
getReadableChannel()
Returns the readable channel of this pair.Supplier<ReadableFrameChannel>
getReadableChannelSupplier()
WritableFrameChannel
getWritableChannel()
Returns the writable channel of this pair.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.boolean
isReadableChannelReady()
WhethergetReadableChannel()
is ready to use.OutputChannel
mapWritableChannel(Function<WritableFrameChannel,WritableFrameChannel> mapFn)
static OutputChannel
nil(int partitionNumber)
Create a nil output channel, representing a processor that writes nothing.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.OutputChannel
readOnly()
Returns a read-only version of this instance.static OutputChannel
readOnly(Supplier<ReadableFrameChannel> readableChannelSupplier, int partitionNumber)
Creates a read-only output channel.static OutputChannel
readOnly(ReadableFrameChannel readableChannel, int partitionNumber)
Creates a read-only output channel.
-
-
-
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 producerframeMemoryAllocator
- memory allocator for producer to use while writing frames to the channelreadableChannelSupplier
- readable channel for consumer. May be called multiple times, so you should wrap this inSuppliers.memoize(com.google.common.base.Supplier<T>)
if needed.partitionNumber
- partition number, if any; may beFrameWithPartition.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 producerframeMemoryAllocator
- memory allocator for producer to use while writing frames to the channelreadableChannel
- readable channel for consumerpartitionNumber
- partition number, if any; may beFrameWithPartition.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 beFrameWithPartition.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 inSuppliers.memoize(com.google.common.base.Supplier<T>)
if needed.partitionNumber
- partition number, if any; may beFrameWithPartition.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. CheckisReadableChannelReady()
to find out.
-
isReadableChannelReady
public boolean isReadableChannelReady()
WhethergetReadableChannel()
is ready to use.
-
getReadableChannelSupplier
public Supplier<ReadableFrameChannel> getReadableChannelSupplier()
-
getPartitionNumber
public int getPartitionNumber()
-
mapWritableChannel
public OutputChannel mapWritableChannel(Function<WritableFrameChannel,WritableFrameChannel> mapFn)
-
readOnly
public OutputChannel readOnly()
Returns a read-only version of this instance. Read-only versions have neithergetWritableChannel()
norgetFrameMemoryAllocator()
, and therefore require substantially less memory.
-
convertToReadOnly
public void convertToReadOnly()
Removes the reference to thewritableChannel
andframeMemoryAllocator
from the object, making it more efficient
-
-