-
public interface Consumer<T>Consumes data produced by Producer.
The producer uses this interface to notify its client when new data is ready or an error occurs. Execution of the image request is structured as a sequence of Producers. Each one consumes data produced by producer preceding it in the sequence.
For example decode is a producer that consumes data produced by the disk cache get producer.
The consumer is passed new intermediate results via onNewResult(isLast = false) method. Each consumer should expect that one of the following methods will be called exactly once, as the very last producer call:
- onNewResult(isLast = true) if producer finishes successfully with a final result
- onFailure if producer failed to produce a final result
- onCancellation if producer was cancelled before a final result could be created
Implementations of this interface must be thread safe, as callback methods might be called on different threads.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public @interfaceConsumer.StatusStatus flag used by producers and consumers to supply additional information.
-
Method Summary
Modifier and Type Method Description abstract voidonNewResult(@Nullable() T newResult, int status)Called by a producer whenever new data is produced. abstract voidonFailure(Throwable t)Called by a producer whenever it terminates further work due to Throwable being thrown. abstract voidonCancellation()Called by a producer whenever it is cancelled and won't produce any more results abstract voidonProgressUpdate(float progress)Called when the progress updates. -
-
Method Detail
-
onNewResult
abstract void onNewResult(@Nullable() T newResult, int status)
Called by a producer whenever new data is produced. This method should not throw an exception.
In case when result is closeable resource producer will close it after onNewResult returns.Consumer needs to make copy of it if the resource must be accessed after that. Fortunately,with CloseableReferences, that should not impose too much overhead.
- Parameters:
status- bitwise values describing the returned result
-
onFailure
abstract void onFailure(Throwable t)
Called by a producer whenever it terminates further work due to Throwable being thrown. Thismethod should not throw an exception.
-
onCancellation
abstract void onCancellation()
Called by a producer whenever it is cancelled and won't produce any more results
-
onProgressUpdate
abstract void onProgressUpdate(float progress)
Called when the progress updates.
- Parameters:
progress- in range [0, 1]
-
-
-
-