T
- The type of the result of the completed upload operation.public abstract class BaseAbstractGoogleAsyncWriteChannel<T> extends Object implements WritableByteChannel
Modifier and Type | Field and Description |
---|---|
protected AsyncWriteChannelOptions |
channelOptions |
protected static com.google.common.flogger.GoogleLogger |
logger |
protected ExecutorService |
threadPool |
protected Future<T> |
uploadOperation |
Constructor and Description |
---|
BaseAbstractGoogleAsyncWriteChannel(ExecutorService threadPool,
AsyncWriteChannelOptions channelOptions)
Construct a new channel using the given ExecutorService to run background uploads.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this channel.
|
T |
createResponseFromException(IOException e)
Derived classes may optionally intercept an IOException thrown from the execute() method of a
prepared request that came from
#createRequest , and return a reconstituted "response"
object if the IOException can be handled as a success; for example, if the caller already has
an identifier for an object, and the response is used solely for obtaining the same identifier,
and the IOException is a handled "409 Already Exists" type of exception, then the derived class
may override this method to return the expected "identifier" response. |
protected abstract String |
getResourceString() |
void |
handleResponse(T response)
Handle the API response.
|
void |
initialize()
Initialize this channel object for writing.
|
boolean |
isDirectUploadEnabled()
Returns true if direct media uploads are enabled.
|
boolean |
isOpen()
Tells whether this channel is open.
|
abstract void |
startUpload(InputStream pipeSource)
Create a new thread which handles the upload.
|
int |
write(ByteBuffer buffer)
Writes contents of the given buffer to this channel.
|
protected static final com.google.common.flogger.GoogleLogger logger
protected final ExecutorService threadPool
protected final AsyncWriteChannelOptions channelOptions
public BaseAbstractGoogleAsyncWriteChannel(ExecutorService threadPool, AsyncWriteChannelOptions channelOptions)
public void handleResponse(T response) throws IOException
This method is invoked after the upload has completed on the same thread that invokes close().
response
- The API response object.IOException
public T createResponseFromException(IOException e)
#createRequest
, and return a reconstituted "response"
object if the IOException can be handled as a success; for example, if the caller already has
an identifier for an object, and the response is used solely for obtaining the same identifier,
and the IOException is a handled "409 Already Exists" type of exception, then the derived class
may override this method to return the expected "identifier" response. Return null to let the
exception propagate through correctly.public boolean isDirectUploadEnabled()
public int write(ByteBuffer buffer) throws IOException
Note: The data that one writes gets written to a pipe which must not block if the pipe has sufficient buffer space. A success code returned from this method does not mean that the specific data was successfully written to the underlying storage. It simply means that there is no error at present. The data upload may encounter an error on a separate thread. Such error is not ignored; it shows up as an exception during a subsequent call to write() or close(). The only way to be sure of successful upload is when the close() method returns successfully.
write
in interface WritableByteChannel
buffer
- buffer to writeIOException
- on IO errorpublic boolean isOpen()
public void close() throws IOException
Note: The method returns only after all data has been successfully written to GCS or if there is a non-retry-able error.
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Channel
IOException
- on IO errorpublic void initialize() throws IOException
IOException
public abstract void startUpload(InputStream pipeSource) throws IOException
IOException
protected abstract String getResourceString()
Copyright © 2022. All rights reserved.