-
- All Implemented Interfaces:
-
com.facebook.imagepipeline.producers.Consumer
@ThreadSafe() public abstract class BaseConsumer<T> implements Consumer<T>
Base implementation of Consumer that implements error handling conforming to the Consumer's contract.
This class also prevents execution of callbacks if one of final methods was called before: onFinish(isLast = true), onFailure or onCancellation.
All callbacks are executed within a synchronized block, so that clients can act as if all callbacks are called on single thread.
-
-
Constructor Summary
Constructors Constructor Description BaseConsumer()
-
Method Summary
Modifier and Type Method Description static booleanisLast(int status)Checks whether the provided status includes the `IS_LAST` flag, marking this as the last resultthe consumer will receive. static booleanisNotLast(int status)Checks whether the provided status includes the `IS_LAST` flag, marking this as the last resultthe consumer will receive. static intturnOnStatusFlag(int status, int flag)Updates a provided status by ensuring the specified flag is turned on. static intturnOffStatusFlag(int status, int flag)Updates a provided status by ensuring the specified flag is turned off. static booleanstatusHasFlag(int status, int flag)Checks whether the provided status contains a specified flag. static booleanstatusHasAnyFlag(int status, int flag)Checks whether the provided status contains any of the specified flags. static intsimpleStatusForIsLast(boolean isLast)Creates a simple status value which only identifies whether this is the last result. synchronized voidonNewResult(@Nullable() T newResult, int status)Called by a producer whenever new data is produced. synchronized voidonFailure(Throwable t)Called by a producer whenever it terminates further work due to Throwable being thrown. synchronized voidonCancellation()Called by a producer whenever it is cancelled and won't produce any more results synchronized voidonProgressUpdate(float progress)Called when the progress updates. -
-
Method Detail
-
isLast
static boolean isLast(int status)
Checks whether the provided status includes the `IS_LAST` flag, marking this as the last resultthe consumer will receive.
-
isNotLast
static boolean isNotLast(int status)
Checks whether the provided status includes the `IS_LAST` flag, marking this as the last resultthe consumer will receive.
-
turnOnStatusFlag
static int turnOnStatusFlag(int status, int flag)
Updates a provided status by ensuring the specified flag is turned on.
-
turnOffStatusFlag
static int turnOffStatusFlag(int status, int flag)
Updates a provided status by ensuring the specified flag is turned off.
-
statusHasFlag
static boolean statusHasFlag(int status, int flag)
Checks whether the provided status contains a specified flag.
-
statusHasAnyFlag
static boolean statusHasAnyFlag(int status, int flag)
Checks whether the provided status contains any of the specified flags.
-
simpleStatusForIsLast
static int simpleStatusForIsLast(boolean isLast)
Creates a simple status value which only identifies whether this is the last result.
-
onNewResult
synchronized 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
synchronized 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
synchronized void onCancellation()
Called by a producer whenever it is cancelled and won't produce any more results
-
onProgressUpdate
synchronized void onProgressUpdate(float progress)
Called when the progress updates.
- Parameters:
progress- in range [0, 1]
-
-
-
-