Package 

Class BaseConsumer

  • 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 boolean isLast(int status) Checks whether the provided status includes the `IS_LAST` flag, marking this as the last resultthe consumer will receive.
      static boolean isNotLast(int status) Checks whether the provided status includes the `IS_LAST` flag, marking this as the last resultthe consumer will receive.
      static int turnOnStatusFlag(int status, int flag) Updates a provided status by ensuring the specified flag is turned on.
      static int turnOffStatusFlag(int status, int flag) Updates a provided status by ensuring the specified flag is turned off.
      static boolean statusHasFlag(int status, int flag) Checks whether the provided status contains a specified flag.
      static boolean statusHasAnyFlag(int status, int flag) Checks whether the provided status contains any of the specified flags.
      static int simpleStatusForIsLast(boolean isLast) Creates a simple status value which only identifies whether this is the last result.
      synchronized void onNewResult(@Nullable() T newResult, int status) Called by a producer whenever new data is produced.
      synchronized void onFailure(Throwable t) Called by a producer whenever it terminates further work due to Throwable being thrown.
      synchronized void onCancellation() Called by a producer whenever it is cancelled and won't produce any more results
      synchronized void onProgressUpdate(float progress) Called when the progress updates.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BaseConsumer

        BaseConsumer()
    • 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]