Package 

Class PriorityNetworkFetcher

  • All Implemented Interfaces:
    com.facebook.imagepipeline.producers.NetworkFetcher

    
    public class PriorityNetworkFetcher<FETCH_STATE extends FetchState>
     implements NetworkFetcher<PriorityNetworkFetcher.PriorityFetchState<FETCH_STATE>>
                        

    PriorityNetworkFetcher fetches images using a priority queue.

    Fetches are delegated to another fetcher.

    • Two queues are maintained, one for each priority.
    • High-priority images (e.g, on-screen) are handled FIFO or LIFO, depending on a flag.
    • Low-priority images (e.g., prefetches) are handled FIFO.
    • Dequeuing is done thusly:
      • If there's an enqueued hi-pri requests, and there are less than 'maxOutstandingHiPri' currently active downloads, it is dequeued; then,
      • If there's an enqueued low-pri requests, and there are less than 'maxOutstandingLowPri' currently active downloads, it is dequeued.
    • When a request's priority changes, it is taken out of the queue and re-enqueued according to the rules above.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static String TAG
    • Constructor Summary

      Constructors 
      Constructor Description
      PriorityNetworkFetcher(NetworkFetcher<FETCH_STATE> delegate, boolean isHiPriFifo, int maxOutstandingHiPri, int maxOutstandingLowPri, boolean inflightFetchesCanBeCancelled, int maxNumberOfRequeue, boolean doNotCancelRequests, int immediateRequeueCount, int requeueDelayTimeInMillis, boolean multipleDequeue, boolean nonRecoverableExceptionPreventsRequeue, int maxConnectAttemptCount, int maxAttemptCount, boolean retryLowPriAll, boolean retryLowPriUnknownHostException, boolean retryLowPriConnectionException)
      PriorityNetworkFetcher(NetworkFetcher<FETCH_STATE> delegate, boolean isHiPriFifo, int maxOutstandingHiPri, int maxOutstandingLowPri, boolean inflightFetchesCanBeCancelled, int maxNumberOfRequeue, boolean doNotCancelRequests, int immediateRequeueCount, int requeueDelayTimeInMillis, boolean multipleDequeue, boolean nonRecoverableExceptionPreventsRequeue, int maxConnectAttemptCount, int maxAttemptCount, boolean retryLowPriAll, boolean retryLowPriUnknownHostException, boolean retryLowPriConnectionException, MonotonicClock clock)
    • Constructor Detail

      • PriorityNetworkFetcher

        PriorityNetworkFetcher(NetworkFetcher<FETCH_STATE> delegate, boolean isHiPriFifo, int maxOutstandingHiPri, int maxOutstandingLowPri, boolean inflightFetchesCanBeCancelled, int maxNumberOfRequeue, boolean doNotCancelRequests, int immediateRequeueCount, int requeueDelayTimeInMillis, boolean multipleDequeue, boolean nonRecoverableExceptionPreventsRequeue, int maxConnectAttemptCount, int maxAttemptCount, boolean retryLowPriAll, boolean retryLowPriUnknownHostException, boolean retryLowPriConnectionException)
        Parameters:
        isHiPriFifo - if true, hi-pri requests are dequeued in the order they were enqueued.Otherwise, they're dequeued in reverse order.
        inflightFetchesCanBeCancelled - if false, the fetcher waits for the completion of requeststhat have been delegated to 'delegate' even if they were cancelled by Fresco.
        maxNumberOfRequeue - requests that fail are re-queued up to maxNumberOfRequeue times,potentially retrying immediately.
        doNotCancelRequests - if true, requests will not be removed from the queue on cancellation
        immediateRequeueCount - number of immediate requeue attempts, when a request is re-queuedmore then this number, it will get re-queued again after at most requeueDelayTimeInMillis.NO_DELAYED_REQUESTS(-1) means no delay, no matter how many times the request is re-queued.
        requeueDelayTimeInMillis - the amount of time in ms a request needs to wait until gettingre-queued again after it gets re-queued more than immediateRequeueCount times.
      • PriorityNetworkFetcher

        PriorityNetworkFetcher(NetworkFetcher<FETCH_STATE> delegate, boolean isHiPriFifo, int maxOutstandingHiPri, int maxOutstandingLowPri, boolean inflightFetchesCanBeCancelled, int maxNumberOfRequeue, boolean doNotCancelRequests, int immediateRequeueCount, int requeueDelayTimeInMillis, boolean multipleDequeue, boolean nonRecoverableExceptionPreventsRequeue, int maxConnectAttemptCount, int maxAttemptCount, boolean retryLowPriAll, boolean retryLowPriUnknownHostException, boolean retryLowPriConnectionException, MonotonicClock clock)
    • Method Detail

      • pause

         void pause()

        Stop dequeuing requests until resume is called.

      • resume

         void resume()

        Resume dequeuing requests.

        Note: a request is immediately dequeued and the delegate's fetch() method is called usingthe current thread.

      • shouldPropagate

         boolean shouldPropagate(PriorityNetworkFetcher.PriorityFetchState<FETCH_STATE> fetchState)

        Gets whether the intermediate results should be propagated.

        In addition to the requirements of this method, intermediate results are throttled sothat a maximum of one every 100 ms is propagated. This is to conserve CPU and other resources.

        Not applicable if progressive rendering is disabled or not supported for this image.

        Parameters:
        fetchState - the fetch-specific state
      • shouldRetry

         static boolean shouldRetry(Throwable e, int attemptNumber, int maxConnectAttemptCount, int maxAttemptCount, boolean retryLowPriAll, boolean retryLowPriUnknownHostException, boolean retryLowPriConnectionException, Priority priority)