public class

PriorityNetworkFetcher

extends Object
implements NetworkFetcher<FETCH_STATE extends FetchState>
java.lang.Object
   ↳ com.facebook.imagepipeline.producers.PriorityNetworkFetcher<FETCH_STATE extends com.facebook.imagepipeline.producers.FetchState>

Class Overview

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.

Summary

Nested Classes
class PriorityNetworkFetcher.NonrecoverableException The delegate fetcher may pass an instance of this exception to its callback's onFailure to signal to a PriorityNetworkFetcher that it shouldn't retry that request. 
class PriorityNetworkFetcher.PriorityFetchState<FETCH_STATE extends FetchState>  
Fields
public static final String TAG
Public Constructors
PriorityNetworkFetcher(NetworkFetcher<FETCH_STATE> delegate, boolean isHiPriFifo, int maxOutstandingHiPri, int maxOutstandingLowPri, boolean inflightFetchesCanBeCancelled, boolean infiniteRetries)
PriorityNetworkFetcher(NetworkFetcher<FETCH_STATE> delegate, boolean isHiPriFifo, int maxOutstandingHiPri, int maxOutstandingLowPri, boolean inflightFetchesCanBeCancelled, boolean infiniteRetries, MonotonicClock clock)
Public Methods
PriorityFetchState<FETCH_STATE> createFetchState(Consumer<EncodedImage> consumer, ProducerContext producerContext)
Creates a new instance of the FetchState-derived object used to store state.
void fetch(PriorityFetchState<FETCH_STATE> fetchState, NetworkFetcher.Callback callback)
Map<String, String> getExtraMap(PriorityFetchState<FETCH_STATE> fetchState, int byteSize)
void onFetchCompletion(PriorityFetchState<FETCH_STATE> fetchState, int byteSize)
void pause()
Stop dequeuing requests until resume() is called.
void resume()
Resume dequeuing requests.
boolean shouldPropagate(PriorityFetchState<FETCH_STATE> fetchState)
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.imagepipeline.producers.NetworkFetcher

Fields

public static final String TAG

Public Constructors

public PriorityNetworkFetcher (NetworkFetcher<FETCH_STATE> delegate, boolean isHiPriFifo, int maxOutstandingHiPri, int maxOutstandingLowPri, boolean inflightFetchesCanBeCancelled, boolean infiniteRetries)

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 requests that have been delegated to 'delegate' even if they were cancelled by Fresco. The cancellation order is not propagated to 'delegate', and no other request is dequeued.
infiniteRetries if true, requests that fail are re-queued, potentially retrying immediately.

public PriorityNetworkFetcher (NetworkFetcher<FETCH_STATE> delegate, boolean isHiPriFifo, int maxOutstandingHiPri, int maxOutstandingLowPri, boolean inflightFetchesCanBeCancelled, boolean infiniteRetries, MonotonicClock clock)

Public Methods

public PriorityFetchState<FETCH_STATE> createFetchState (Consumer<EncodedImage> consumer, ProducerContext producerContext)

Creates a new instance of the FetchState-derived object used to store state.

Parameters
consumer the consumer
producerContext the producer's context
Returns
  • a new fetch state instance

public void fetch (PriorityFetchState<FETCH_STATE> fetchState, NetworkFetcher.Callback callback)

public Map<String, String> getExtraMap (PriorityFetchState<FETCH_STATE> fetchState, int byteSize)

public void onFetchCompletion (PriorityFetchState<FETCH_STATE> fetchState, int byteSize)

public void pause ()

Stop dequeuing requests until resume() is called.

public void resume ()

Resume dequeuing requests.

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

public boolean shouldPropagate (PriorityFetchState<FETCH_STATE> fetchState)