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