Retrofit - 7 network communication process 8 steps & 7 key member variable analysis

Eight steps of network communication:
1) Create a retrofit instance.
2) Define a network request interface and add annotations to the methods in the interface.
3) Generate network request object through dynamic proxy.
4) Adapt the network request object to the platform through the network request adapter.
5) Send a network request through the network request executor.
6) Parse the data through a data converter.
7) Switch threads by returning the executor.
8) The user processes the returned result in the main thread.

[Source code analysis]


The build mode used. Seven Important Member Variables

public final class Retrofit {
  // key is Method, which is our HTTP request method.  
  // values ​​ServiceMethod, after annotating its method on behalf of the network request interface,
  // We have to pass the parsing, and then the parsed object, we call it ServiceMethod.
  // serviceMethodCache is mainly used for caching,
  // For example: store some network request related configuration, network request method, data converter, network adapter, etc.
  private final Map<Method, ServiceMethod<?, ?>> serviceMethodCache
           = new ConcurrentHashMap<>();
  // Factory for requesting network OKHTTP.
  final okhttp3.Call.Factory callFactory;
  // The base address of the network request. (The relative address is in the interface annotation).
  final HttpUrl baseUrl;
  // A collection of data converter factories. Convert to the user's java object.
  final List<Converter.Factory> converterFactories;
  // network factory adapter collection
  final List<CallAdapter.Factory> callAdapterFactories;
  // Used to execute callbacks, because asynchronous network requests are processed.
  final @Nullable Executor callbackExecutor;
  // Represents a flag bit, which means whether the methods in the interface need to be resolved immediately.
  final boolean validateEagerly;
…………



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325908114&siteId=291194637