Android advanced light-network programming and network framework,

Source: Internet
Author: User

Android advanced light-network programming and network framework,

No1:

Volley source code analysis:

Volley. newRequestQueue->

RequestQueue. start ()->

CacheDispatcher. start ()-> CacheDispatcher. run ()->

NetworkDispatcher. start ()-> NetworkDispatcher. run ()->

RequestQueue. add ()->

BasicNetwork. receivmrequest ()->

HttpStack. receivmrequest ()->

Delivery. postResponse ()->

ExecutorDelivery. ResponseDeliveryRunnable->

Request. deliverResponse ()->

Response. Listener. onResponse ()->

Note:

Volley is divided into three types of threads: main thread, cache scheduling thread, and network scheduling thread. Four network scheduling threads are enabled by default.

First, the request is added to the cache queue, and the cache scheduling thread extracts the request from the cache queue. If the cache response of the request is found, the cached response is directly read and parsed, and then the callback is sent to the main thread;

If no cached response is found, the request is added to the network queue. Then, the network scheduling thread poll the requests in the network queue and sends the HTTP request, parse the response and save the response to the cache, and call back it to the main thread.

No2:

OkHttp source code analysis:

OkHttpClient. newCall (request)->

RealCall. enqueue->

Dispatcher. enqueue->

RealCall.exe cute->

Client. dispatcher (). finished ()-> promotecils->

AsyncCall.exe cute-> getResponseWithInterceptorChain-> getResponse ()->

HttpEngine. sendRequest-> readResponse->

RealCall. getResponse->

HttpEngine. recover->

No3:

The core of Okhttp connection pool reuse is to use Deque <RealConnection> to store connections, and perform operations on Deque through put, get, connectionBecameIdle, and evictAll, in addition, the StreamAllocation object in the connection is determined to automatically recycle the connection.

No4:

Sort fit annotation Classification

1) HTTP Request Method annotation: GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS, HTTP (the first seven types can be replaced or extended)

2) Tag annotation: FormUrlEncoded, Multipart, Streaming (Stream)

3) parameter annotation: Header, Headers, Body, Path, Field, FieldMap, Part, PartMap, Query, QueryMap

No5:

Retrofit source code analysis

Fit. Builder ()->

Platform. get ()-> findPlatform->

Keep fit. build ()->

Using Fit. create-> loadServiceMethod->

ServiceMethod. Builder->

ExecutorCallAdapterFactory. get->

ExecutorCallbackCall. enqueue->

Delegate. enqueue-> OkHttpCall. enqueue->

Okhttp3.Call. enqueue-> parseResponse-> toResponse->

GsonConverterFactory. responseBodyConverter->

GsonResponseBodyConverter. convert->

The Call. enqueue method mainly uses OkHttp to request the network, converts the returned Response data, and calls back the Response to the UI thread.

Related Article

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.