volley總結

定義:是一個異步網絡請求框架和圖片加載框架緩存

做用:適合數據量小,通訊頻繁的網絡操做網絡

優勢:一、擴展性強,大多基於接口設計併發

          二、自動調度網絡框架

          三、高併發網絡鏈接異步

整體框架ide

volley網絡請求過程當請求被添加到請求隊列後,volley經過兩種調度線程()不斷從請求隊列中取出請求,根據是否已緩存調用Cache或Network這兩類數據獲取接口之一,從緩存中或網絡上取得數據。而後交給response delivery去作結果分發及回調處理。高併發

volley請求流程圖post

volley主要類關係圖ui

 RequestQueue:A request dispatch queue with a thread pool of dispatchers.Calling {@link  #add(Request)} will enqueue the given Request for dispatch, resolving from either cache or network on a worker thread, and then delivering a parsed response on the main thread.this

RequestQueue 中維護了兩個基於優先級的 Request 隊列,緩存請求隊列和網絡請求隊列。

CacheDispatcher:Provides a thread for performing cache triage on a queue of requests.Requests added to the specified cache queue are resolved from cache.Any deliverable response is posted back to the caller via a{@link  ResponseDelivery}.  Cache misses and responses that require refresh are enqueued on the specified network queue for processing by a { @link  NetworkDispatcher}.

NetworkDispatcher:Provides a thread for performing network dispatch from a queue of requests.Requests added to the specified queue are processed from the network via a specified {@link  Network} interface. Responses are committed to cache, if eligible, using a specified {@link  Cache} interface. Valid responses and errors are posted back to the caller via a {@link ResponseDelivery}.

Request<T>:Base class for all network requests.@param <T> The type of parsed response this request expects.

ExecutorDelivery:Delivers responses and errors.

DiskBasedCache:Cache implementation that caches files directly onto the hard disk in the specified directory. The default disk usage size is 5MB, but is configurable.

相關文章
相關標籤/搜索