R
- The type of request (e.g. ReadRequest or WriteRequest issued by this access to the I/O threads.public abstract class AsynchronousFileIOChannel<T,R extends org.apache.flink.runtime.io.disk.iomanager.IORequest> extends AbstractFileIOChannel
The asynchrony of the access makes it possible to implement read-ahead or write-behind types of I/O accesses.
FileIOChannel.Enumerator, FileIOChannel.ID
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed
Flag marking this channel as closed
|
protected Object |
closeLock
The lock that is used during closing to synchronize the thread that waits for all
requests to be handled with the asynchronous I/O thread.
|
protected IOException |
exception
An exception that was encountered by the asynchronous request handling thread.
|
protected RequestQueue<R> |
requestQueue
A request queue for submitting asynchronous requests to the corresponding IO worker thread.
|
protected AtomicInteger |
requestsNotReturned
An atomic integer that counts the number of requests that we still wait for to return.
|
protected RequestDoneCallback<T> |
resultHandler
Handler for completed requests
|
fileChannel, id, LOG
Modifier | Constructor and Description |
---|---|
protected |
AsynchronousFileIOChannel(FileIOChannel.ID channelID,
RequestQueue<R> requestQueue,
RequestDoneCallback<T> callback,
boolean writeEnabled)
Creates a new channel access to the path indicated by the given ID.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addRequest(R request) |
void |
checkErroneous()
Checks the exception state of this channel.
|
void |
close()
Closes the channel and waits until all pending asynchronous requests are processed.
|
void |
closeAndDelete()
This method waits for all pending asynchronous requests to return.
|
protected void |
handleProcessedBuffer(T buffer,
IOException ex)
Handles a processed Buffer.
|
boolean |
isClosed()
Checks whether the channel has been closed.
|
protected boolean |
registerAllRequestsProcessedListener(NotificationListener listener)
Registers a listener to be notified when all outstanding requests have been processed.
|
deleteChannel, getChannelID, getNioFileChannel, getSize
protected final Object closeLock
protected final RequestQueue<R extends org.apache.flink.runtime.io.disk.iomanager.IORequest> requestQueue
protected final AtomicInteger requestsNotReturned
protected final RequestDoneCallback<T> resultHandler
protected volatile IOException exception
protected volatile boolean closed
protected AsynchronousFileIOChannel(FileIOChannel.ID channelID, RequestQueue<R> requestQueue, RequestDoneCallback<T> callback, boolean writeEnabled) throws IOException
channelID
- The id describing the path of the file that the channel accessed.requestQueue
- The queue that this channel hands its IO requests to.callback
- The callback to be invoked when a request is done.writeEnabled
- Flag describing whether the channel should be opened in read/write mode, rather
than in read-only mode.IOException
- Thrown, if the channel could no be opened.public boolean isClosed()
FileIOChannel
isClosed
in interface FileIOChannel
isClosed
in class AbstractFileIOChannel
public void close() throws IOException
FileChannel
is closed even if an exception interrupts the closing.
Important: the isClosed()
method returns true
immediately after this method has been called even when there are outstanding requests.
close
in interface FileIOChannel
close
in class AbstractFileIOChannel
IOException
- Thrown, if an I/O exception occurred while waiting for the buffers, or if
the closing was interrupted.public void closeAndDelete() throws IOException
Even if an exception interrupts the closing, such that not all request are handled, the underlying FileChannel is closed and deleted.
closeAndDelete
in interface FileIOChannel
closeAndDelete
in class AbstractFileIOChannel
IOException
- Thrown, if an I/O exception occurred while waiting for the buffers, or if the closing was interrupted.public final void checkErroneous() throws IOException
IOException
- Thrown, if the channel is erroneous. The thrown exception contains the original exception
that defined the erroneous state as its cause.protected final void handleProcessedBuffer(T buffer, IOException ex)
buffer
- The buffer to be processed.ex
- The exception that occurred in the I/O threads when processing the buffer's request.protected final void addRequest(R request) throws IOException
IOException
protected boolean registerAllRequestsProcessedListener(NotificationListener listener) throws IOException
New requests can arrive right after the listener got notified. Therefore, it is not safe to assume that the number of outstanding requests is still zero after a notification unless there was a close right before the listener got called.
Returns true
, if the registration was successful. A registration can fail,
if there are no outstanding requests when trying to register a listener.
IOException
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.