With one months of spare time after work, read the volley source code, the front also recorded the reading process, this is designed to comb the volley workflow.
In general, we use volley, the process is very simple. Create a request, build a new requestqueue, and finally add the request to the Requestqueue, then we can wait for the requested response, and if it's stringrequest, We can directly get the string type response.
So, Requestqueue is how to round to request,request and how to send HTTP requests, and then get a response, the response step by step into response, finally, response and how to become the final string, The previous article reads the code one line at a line, and here's a small summary.
1.RequestQueue is a blocking queue, and when requested, it sends a request, and when it does not, it blocks the thread on which it is located. So, whenever a request joins Requestqueue, it will work and the queue is empty, waiting for the request.
2. The request will first complete the connection and other related processes in httpstack, including adding a cookie, judging the request type, add params to the POST request body. Will eventually get a HTtpresponse.
3.HttpResponse will give Network, the network handles the response of the HTTP request primarily, including the exception response such as 20x,304,404. Then, extract the header and content from the HttpResponse and create the networkresponse.
4. The above 2.3 methods are performed in Networkdispatcher, and after completion,response<?> Response = Request.parsenetworkresponse ( Networkresponse); The networkresponse will be converted to response, which is called in the request.
5. At the same time, in Networkdispatcher, Executordelivery will accept request and response, and call Mrequest.deliverresponse (Mresponse.result); Generates a string-type response.
The above is the approximate flow of a volley request.
done~
volley--reading carding