OkHttp3.7.0 architecture and Principle Analysis, okhttp3.7.0 Architecture
Final Summary
Realcall.exe cute
1.dispatcher.exe cute
2. get...
3. finish the output queue to boost execution
Realcall. enqueue = dispatcher. enqueue (Async)
1. get
2. Callback
3. finish the output queue to boost execution
Interceptor
Retryfollw
Retry upon failure
Redirect to directly initiate new requests (conditional permit, reuse connection)
Bridge
Translator
ContentLength, encoding
Compression and decompression
Cookie
Header, such as User-Agent, Host, Keep-alive
Cache
Find
The returned content is changed and updated.
Delete Cache
You can also specify the directory, cache size, and logic.
Cache, with disk lru. The deletion rule is the number of requests and the number of times the cache is matched. The local database maintains two statuses: DIRTY and CLEAN. Both creation and update are based on DIRTY, implementing read/write splitting. Each status corresponds to two types of data: 1. meta2. content
CacheStrategy Factorgy generates a cache policy based on the request and responds Based on the cache policy.
Connect
HttpCodec, which encapsulates Socket with okio.
Creation principle: Find an available RealConnection in the connection pool and use its BufferedSource and BufferedSink to create an HttpCodec object.
Multiplexing: Old HTTP requests require frequent handshakes, new connections are retained, compressed, and sharded.
The onpool is managed through the Count + Mark clearing mechanism, so that useless connections can be recycled and multiple healthy keep-alive connections are maintained.
Callserver
Real Portal
Requestheader
Requestbody
Responsebody
Responsebody, and then construct a new response object based on the Response object constructed above
The core work is completed by the HttpCodec object.
Body
1. Only consume once
2. close is required
Detailed principle of cache and connection pool is not analyzed in depth