Package org.apache.druid.frame.channel
Class ReadableInputStreamFrameChannel
- java.lang.Object
-
- org.apache.druid.frame.channel.ReadableInputStreamFrameChannel
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ReadableFrameChannel
public class ReadableInputStreamFrameChannel extends Object implements ReadableFrameChannel
Channel backed by anInputStream.Frame channels are expected to be nonblocking, but InputStreams cannot be read in nonblocking fashion. This implementation deals with that by using an
ExecutorServiceto read from the stream in a separate thread.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanRead()Returns whether this channel has a frame or error condition currently available.voidclose()Releases any resources associated with this readable channel.booleanisFinished()Returns whether this channel is finished.static ReadableInputStreamFrameChannelopen(InputStream inputStream, String id, ExecutorService executorService, boolean framesOnly)Create an instance of this class and immediately start reading from the provided InputStream.Frameread()Returns the next available frame from this channel.com.google.common.util.concurrent.ListenableFuture<?>readabilityFuture()Returns a future that will resolve when eitherReadableFrameChannel.isFinished()orReadableFrameChannel.canRead()would return true.
-
-
-
Method Detail
-
open
public static ReadableInputStreamFrameChannel open(InputStream inputStream, String id, ExecutorService executorService, boolean framesOnly)
Create an instance of this class and immediately start reading from the provided InputStream.
-
isFinished
public boolean isFinished()
Description copied from interface:ReadableFrameChannelReturns whether this channel is finished. Finished channels will not generate any further frames or errors. Generally, once you discover that a channel is finished, you should callReadableFrameChannel.close()and then discard it. Note that it is possible for a channel to be unfinished and also have no available frames or errors. This happens when it is not in a ready-for-reading state. SeeReadableFrameChannel.readabilityFuture()for details.- Specified by:
isFinishedin interfaceReadableFrameChannel
-
canRead
public boolean canRead()
Description copied from interface:ReadableFrameChannelReturns whether this channel has a frame or error condition currently available. If this method returns true, then you can callReadableFrameChannel.read()to retrieve the frame or error. Note that it is possible for a channel to be unfinished and also have no available frames or errors. This happens when it is not in a ready-for-reading state. SeeReadableFrameChannel.readabilityFuture()for details.- Specified by:
canReadin interfaceReadableFrameChannel
-
read
public Frame read()
Description copied from interface:ReadableFrameChannelReturns the next available frame from this channel. Before calling this method, you should checkReadableFrameChannel.canRead()to ensure there is a frame or error available.- Specified by:
readin interfaceReadableFrameChannel
-
readabilityFuture
public com.google.common.util.concurrent.ListenableFuture<?> readabilityFuture()
Description copied from interface:ReadableFrameChannelReturns a future that will resolve when eitherReadableFrameChannel.isFinished()orReadableFrameChannel.canRead()would return true. The future will never resolve to an exception. If something exceptional has happened, the exception can be retrieved fromReadableFrameChannel.read().- Specified by:
readabilityFuturein interfaceReadableFrameChannel
-
close
public void close()
Description copied from interface:ReadableFrameChannelReleases any resources associated with this readable channel. After calling this, you should not call any other methods on the channel.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReadableFrameChannel
-
-