Android-volley Source Analysis

Source: Internet
Author: User
Volley overview of the overall framework

Queue Dispatcher executes process Cachedispatcher process

The cache distributor, when Requestqueue.start (), starts thread in the app specifically for processing cache read operations. The key operational process for reading the cache is pseudo code as follows:

while (ture) {
    request = Mcachequeue.take ();
    Determine if the request has been canceled/
    /If there is a cache--> to determine whether the cache expires--> cache is valid--> bypass network requests, directly parse the data, complete the request
    //If no cache, cache expiration and so on--> Add the request to the Mnetworkqueue queue and wait for the network request
}

Networkdispatcher process

The network dispatcher, when Requestqueue.start (), creates 4 Networkdispatcher objects in the app and creates 4 thread threads to handle network request operations. The key process pseudocode for network requests is as follows:

while (ture) {
    request = Mnetworkqueue.take ();
    Determine if the request has been canceled
    //Call the Network object for HTTP request Operations
    //Invoke the Parsenetworkresponse () action in request to parse the data
    // To determine whether the response need to cache, through the cache implementation class will response cached
    //through the delivery implementation class, to the UI thread to send the request complete message
}


Network operations

Basicnetwork process

The Tier
performrequest () {
    //Set Request header
    //Call mhttpstack.performrequest between the true network request and the volley network request relative to the volley request layer () Network request
    /interpretation HTTP return code (302,202, etc.) according to these corresponding code for processing
    //Call Entitytobytes (), the request results into byte[] data
    // Return Networkresponse request result Object
}

Hurlstack process

The real network Request object, according to the different system, provides the different realization, also may realize the request to change the operation
Performrequest () {
    //rewrite URL
    // Use System native HttpURLConnection to implement network request operation
    //assembly data and return to Basicnetwork object
}


Data parsing

Request

Request is an abstract class, there are two abstract methods, subclasses must implement, as follows:

Parsenetworkresponse ()//parsing Data
deliverresponse ()//Distribution Request Results

Stringrequest

Stringrequest is the subclass of the request, which implements both of these abstract methods, as follows:

Parsenetworkresponse () {/
    /byte[] in the format requested by request, translate
}
deliverresponse () {
    //distribute request to Mlistener
}

Reference

Volley request entire sequential process: https://blog.csdn.net/guolin_blog/article/details/17656437

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.