public abstract class

BaseConsumer

extends Object
implements Consumer<T>
java.lang.Object
   ↳ com.facebook.imagepipeline.producers.BaseConsumer<T>
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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.

Summary

[Expand]
Inherited Constants
From interface com.facebook.imagepipeline.producers.Consumer
Public Constructors
BaseConsumer()
Public Methods
static boolean isLast(int status)
Checks whether the provided status includes the `IS_LAST` flag, marking this as the last result the consumer will receive.
static boolean isNotLast(int status)
Checks whether the provided status includes the `IS_LAST` flag, marking this as the last result the consumer will receive.
synchronized void onCancellation()
Called by a producer whenever it is cancelled and won't produce any more results
synchronized void onFailure(Throwable t)
Called by a producer whenever it terminates further work due to Throwable being thrown.
synchronized void onNewResult(T newResult, int status)
Called by a producer whenever new data is produced.
synchronized void onProgressUpdate(float progress)
Called when the progress updates.
static int simpleStatusForIsLast(boolean isLast)
Creates a simple status value which only identifies whether this is the last result.
static boolean statusHasAnyFlag(int status, int flag)
Checks whether the provided status contains any of the specified flags.
static boolean statusHasFlag(int status, int flag)
Checks whether the provided status contains a specified flag.
static int turnOffStatusFlag(int status, int flag)
Updates a provided status by ensuring the specified flag is turned off.
static int turnOnStatusFlag(int status, int flag)
Updates a provided status by ensuring the specified flag is turned on.
Protected Methods
abstract void onCancellationImpl()
Called by onCancellation, override this method instead
abstract void onFailureImpl(Throwable t)
Called by onFailure, override this method instead
abstract void onNewResultImpl(T newResult, int status)
Called by onNewResult, override this method instead.
void onProgressUpdateImpl(float progress)
Called when the progress updates
void onUnhandledException(Exception e)
Called whenever onNewResultImpl or onFailureImpl throw an exception
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.imagepipeline.producers.Consumer

Public Constructors

public BaseConsumer ()

Public Methods

public static boolean isLast (int status)

Checks whether the provided status includes the `IS_LAST` flag, marking this as the last result the consumer will receive.

public static boolean isNotLast (int status)

Checks whether the provided status includes the `IS_LAST` flag, marking this as the last result the consumer will receive.

public synchronized void onCancellation ()

Called by a producer whenever it is cancelled and won't produce any more results

public synchronized void onFailure (Throwable t)

Called by a producer whenever it terminates further work due to Throwable being thrown. This method should not throw an exception.

public synchronized void onNewResult (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

public synchronized void onProgressUpdate (float progress)

Called when the progress updates.

Parameters
progress in range [0, 1]

public static int simpleStatusForIsLast (boolean isLast)

Creates a simple status value which only identifies whether this is the last result.

public static boolean statusHasAnyFlag (int status, int flag)

Checks whether the provided status contains any of the specified flags.

public static boolean statusHasFlag (int status, int flag)

Checks whether the provided status contains a specified flag.

public static int turnOffStatusFlag (int status, int flag)

Updates a provided status by ensuring the specified flag is turned off.

public static int turnOnStatusFlag (int status, int flag)

Updates a provided status by ensuring the specified flag is turned on.

Protected Methods

protected abstract void onCancellationImpl ()

Called by onCancellation, override this method instead

protected abstract void onFailureImpl (Throwable t)

Called by onFailure, override this method instead

protected abstract void onNewResultImpl (T newResult, int status)

Called by onNewResult, override this method instead.

protected void onProgressUpdateImpl (float progress)

Called when the progress updates

protected void onUnhandledException (Exception e)

Called whenever onNewResultImpl or onFailureImpl throw an exception