public class ReliableResourceCallable extends Object implements Callable<ReliableResourceStatus>
The client uses the @ReliableResourceInputStream to read from the @FileBackedOutputStream.
This class will read bytes in chunks (whose size is specified by the caller) until it either reaches the EOF or it is interrupted (either by an @IOException or the @CachedResource).
If the @InputStream is read until the EOF, then a -1 is returned indicating the entire stream was read successfully. Otherwise, the number of bytes read thus far is returned so that the caller can react accordingly (e.g., reopen the product @InputStream and skip forward that many bytes already read).
Constructor and Description |
---|
ReliableResourceCallable(InputStream input,
com.google.common.io.CountingOutputStream countingFbos,
FileOutputStream fos,
int chunkSize,
Object lock)
Used when downloading and caching the product.
|
ReliableResourceCallable(InputStream input,
com.google.common.io.CountingOutputStream countingFbos,
int chunkSize,
Object lock)
Used when only downloading, no caching to @FileOutputStream because caching was disabled or had
previous failed attempt trying to cache the product.
|
ReliableResourceCallable(InputStream input,
FileOutputStream fos,
int chunkSize,
Object lock)
Used when only caching, no writing to @FileBackedOutputStream because no client is reading from
it.
|
Modifier and Type | Method and Description |
---|---|
ReliableResourceStatus |
call() |
long |
getBytesRead()
Returns the number of bytes read from the product's @InputStream.
|
ReliableResourceStatus |
getReliableResourceStatus()
Returns the current status of the resource download, e.g., COMPLETED, INTERRUPTED, CANCELED,
etc.
|
void |
setBytesRead(long bytesRead)
Called when a new Callable is created for new retry attempt at product retrieval and the
bytesRead from previous attempt need to be skipped forward.
|
void |
setCancelDownload(boolean cancelDownload)
Set to true when the current resource download should be canceled.
|
void |
setInterruptDownload(boolean interruptDownload)
Set to true to indicate that the current resource download should be interrupted.
|
public ReliableResourceCallable(InputStream input, com.google.common.io.CountingOutputStream countingFbos, int chunkSize, Object lock)
input
- countingFbos
- chunkSize
- public ReliableResourceCallable(InputStream input, FileOutputStream fos, int chunkSize, Object lock)
input
- fos
- chunkSize
- public ReliableResourceCallable(InputStream input, com.google.common.io.CountingOutputStream countingFbos, FileOutputStream fos, int chunkSize, Object lock)
input
- the product @InputStreamcountingFbos
- the FileBackedOutputStream that is written to, number of bytes written to
it are countedfos
- the @FileOutputStream that the cached product is written tochunkSize
- the number of bytes to read from the product @InputStream per chunkpublic long getBytesRead()
public void setBytesRead(long bytesRead)
bytesRead
- public ReliableResourceStatus getReliableResourceStatus()
public void setInterruptDownload(boolean interruptDownload)
interruptDownload
- public void setCancelDownload(boolean cancelDownload)
cancelDownload
- public ReliableResourceStatus call()
call
in interface Callable<ReliableResourceStatus>
This work is licensed under a Creative Commons Attribution 4.0 International License.