protocol structure diagram
Method Description:
Export exposes the method.
Refer refers to a remote service.
Destroy destroys all Invoker (service and refer). Abstractprotocol Analysis
Attribute Analysis:
Map<string, exporter<?>> exportermap:
key is listener address (ip:port).
the exporter<?> master retains the exposure service application and provides unexport.
Method Analysis:
Destroy: Traverse Exportermap and Invokers respectively Unexport and destory. Analysis of Dubboprotocol
Dubboprotocol is the default protocol implementation. We will focus on the creation and use of it. Service End Function
Main function in:
Com.alibaba.dubbo.config.serviceconfig#doexporturlsfor1protocol method.
Call the Protocol.export method to expose the service.
Public <T> exporter<t> Export (invoker<t> invoker) throws rpcexception {URL url = invoker.g
Eturl ();
Export service.
String key = Servicekey (URL); Exporter just added Invoker key references to facilitate unexport dubboexporter<t> exporter = new Dubboexporter<t> (invoker
, key, Exportermap);
Exportermap.put (key, exporter); Export a stub service for dispatching event Boolean isstubsupportevent = Url.getparameter (constants.stub_event_
KEY, constants.default_stub_event);
Boolean Iscallbackservice = Url.getparameter (Constants.is_callback_service, false); if (isstubsupportevent &&!iscallbackservice) {String stubservicemethods = Url.getparameter (Constants .
Stub_event_methods_key);
if (Stubservicemethods = = NULL | | stubservicemethods.length () = 0) {if (logger.iswarnenabled ()) { Logger.warn (New IllegalStateException ("consumer")"+ url.getparameter (Constants.interface_key) +"], has set Stubproxy support event, but no St UB methods founded. "));}
else {stubservicemethodsmap.put (Url.getservicekey (), stubservicemethods);
(a)//create a service-side port to listen for OpenServer (URL);
Optimizing the serialization process for Kryo, FST optimizeserialization (URL);
return exporter;
}
OpenServer:
Determine whether the server has been created based on the current URL (ip:port). None is created (called Createserver) to join the Servermap.
Createserver Source:
Private exchangeserver createserver (url url) {//Send ReadOnly event when server closes, it's enabled by DEFA
Ult url = url.addparameterifabsent (Constants.channel_readonlyevent_sent_key, Boolean.TRUE.toString ()); Enable heartbeat by default URL = url.addparameterifabsent (Constants.heartbeat_key, string.valueof (constants.de
Fault_heartbeat));
String str = url.getparameter (Constants.server_key, constants.default_remoting_server); if (str!= null && str.length () > 0 &&! Extensionloader.getextensionloader (Transporter.class). Hasextension (str)) throw new Rpcexception ("Unsupported s
Erver type: "+ str +", url: "+ url";
url = url.addparameter (Constants.codec_key, dubbocodec.name);
ExchangeServer server;
try {//Here starts the listening port, RequestHandler contains the communication protocol server = Exchangers.bind (URL, RequestHandler) that handles the request specifically; catch (RemotingException e) {throw new Rpcexception ("Fail to start server (URL:" + URL + ")" + e.getmessage (), E);
str = Url.getparameter (Constants.client_key); if (str!= null && str.length () > 0) {set<string> supportedtypes = Extensionloader.getextens
Ionloader (Transporter.class). Getsupportedextensions ();
if (!supportedtypes.contains (str)) {throw new Rpcexception ("Unsupported client type:" + str);
} return server;
}
Description: Exchangers is a tool class that contains the bind and connect methods.
Exchangeclient and ExchangeServer have also implemented both Client and server. Why not just use low-level nettyserver and nettyclient, I think here exchangexxx here is a decorative pattern.
There is also a need to note that Java objects are implemented in remote transport serialization.
Dubboprotocol is using Dubbocodec to keep track of the discovery.
serialization s = codecsupport.getserialization (Channel.geturl (), Proto);
Inside the default adopted hessian2
PS:
Dubbo URL Sample:
dubbo://10.62.0.117:20880/com.alibaba.dubbo.demo.demoservice?anyhost=true&application=demo-provider& bind.ip=10.62.0.117&bind.port=20880&channel.readonly.sent=true&codec=dubbo&dubbo=2.0.0& generic=false&heartbeat=60000&interface=com.alibaba.dubbo.demo.demoservice&methods=sayhello& pid=14232&qos.port=22222&side=provider×tamp=1523155912417