Invoker

Take a look at the official documentation for Inoker:



  • Invoker is a callable Service abstraction of Provider. The Invoker encapsulates the Provider address and Service interface information.

  • Directory represents multiple Invokers and can be thought of as a list collection of invokers, but unlike list, its value can change dynamically, such as when the registry pushes changes.
  • Cluster masquerade multiple Invokers in a Directory as one Invoker and is transparent to the upper layer. The masquerade process contains fault-tolerant logic, and when the call fails, another Invoker is retried.
  • The Router is responsible for selecting subsets of invokers based on routing rules, such as read/write separation, application isolation, and so on.
  • LoadBalance selects a specific Invoker from multiple invokers for this invocation. The selection process includes the load balancing algorithm. If the invocation fails, the Invoker must be selected again.

Take a look at inovker-related abstractions:

  • Invocation: A specific Invocation with the method name, parameter type, and parameter
  • Result, the Result of a call, including value and exception

The above is the relevant definition of INVoker, and WE will use Invoker in combination with SANOrecovery next.

Exchanger

The component responsible for data exchange and network communication in a framework is usually called Sano11003. Each Invoker in Dubbo maintains a reference to ExchangeClient through which it communicates with a remote Server. The entire class diagram associated with ExchangeClient is as follows:



ExchangeClient only a common implementation class, HeaderExchangeClient (and other implement LazyConnectExchangeClient and ReferenceCountExchangeClient), The generation process is generated by the Exchangers utility class:



The URL is used first, and a HeaderExchanger is returned by default, and its CONNECT () is used to create a HeaderExchangeClient.

When Invoker needs to send data, one-way send uses ExchangeClient’s Send method, and request method is used to return results:



In the implementation this call is passed to the HeaderExchangeChannel object maintained by headerexchange eclient, and subsequent operations on the channel depend on the Client passed in the constructor, which is actually a channel interface. Let’s look at the constructor for HeaderExchangeClient:

this.channel = new HeaderExchangeChannel(client);Copy the code

The final send method is passed to the Channel’s Send, while the Request method is implemented by building ResponseFuture and calling send.

For clarification, the implementation mentioned above is a headerRECOVERY (1100ac) by default, and the actual application is a headerRECOVERY (1100AC) CONNECT. Let’s look at the implementation:

public ExchangeClient connect(URL url, ExchangeHandler handler) throws RemotingException {
	return new HeaderExchangeClient(Transporters.connect(url, new DecodeHandler(new HeaderExchangeHandler(handler))));
}
Copy the code

It comes from the Transporters connect method. The Transporter comes from the ExtensionLoader, which defaults to NettyTransporter and builds NettyClient. Again, the NettyClient maintains a Channel reference from the getOrAddChannel() method of NettyChannel, which creates the NettyChannel. Finally, the send method implemented by the base class AbstractClient calls NettyChannel:



The Boolean sent parameter is used to determine whether to wait for the data to be sent and whether to perform a timeout.