简体   繁体   English

GWT RPC机制的序列图

[英]Sequence diagram for GWT RPC mechanism

I don't fully understand the GWT RPC mechanism adn therefore I am looking for a sequence diagram. 我不完全了解GWT RPC机制,因此我正在寻找序列图。 Does anyone have a link? 有人有链接吗?

THe plumbing diagram on the GWT homepage do not describe the mechanism in every little detail: http://www.gwtproject.org/doc/latest/DevGuideServerCommunication.html#DevGuideRemoteProcedureCalls GWT主页上的管道图并未详细描述该机制: http : //www.gwtproject.org/doc/latest/DevGuideServerCommunication.html#DevGuideRemoteProcedureCalls

There is no published sequence diagram that I know of. 我没有已知的已发布序列图。 But it wouldn't really be that much of help, because it would have to deal with many levels of abstractions at the same time: 但这实际上并没有那么多帮助,因为它必须同时处理许多抽象级别:

  • the Javascript side does not really "call" the Java side (it sends a request, and that's a different thing) Javascript端并没有真正“调用” Java端(它发送了一个请求,这是另一回事)
  • the main client-side actor (the implementation of the async interface) is never visible, as it's generated during the compilation of the project. 主客户端参与者(异步接口的实现)从不可见,因为它是在项目编译期间生成的。

The points to understand are: 需要了解的要点是:

  • the server side is synchronous - pure Servlet API, with a single thread serving each request; 服务器端是同步的-纯Servlet API,只有一个线程可以处理每个请求;
  • the Javascript side is asynchronous. JavaScript方面是异步的。 When you send a HTTP request in Javascript, you cannot wait for the response, you can only provide a callback. 使用Javascript发送HTTP请求时,您无法等待响应,只能提供回调。 This is why you cannot wrap an HTTP call that returns a value in a synchronous interface. 这就是为什么您不能包装在同步接口中返回值的HTTP调用的原因。
  • in a perfect world, there would be just one interface, bridging the client and the server side. 在理想的世界中,只有一个接口可以桥接客户端和服务器端。 The server would implement the interface, and the client would somehow acquire its proxy and call it's methods. 服务器将实现该接口,客户端将以某种方式获取其代理并调用其方法。 This is how synchronous remoting usually works. 这就是同步远程通常如何工作的方式。 For the reasons stated above, it's not possible. 由于上述原因,这是不可能的。
  • So we need two different interfaces: one for the client (async) and one for the server (sync). 因此,我们需要两个不同的接口:一个用于客户端(异步),另一个用于服务器(同步)。 They are only kept together with convention, since Java's type system cannot express the relation between them (the names of the methods are the same, the parameters are related, but not identical, the return types are different)., 它们仅与约定保持在一起,因为Java的类型系统无法表达它们之间的关系(方法的名称相同,参数相关,但不相同,返回类型不同),
  • during the compilation of the GWT project a class implementing the client interface is generated. 在GWT项目的编译过程中,将生成一个实现客户端接口的类。 It's instances can call the server (in an asynchronous way). 它的实例可以调用服务器(以异步方式)。 The server then locates the implementation of the relavant method of the synchronous interface and invokes it, sending back the response (synchronously). 然后,服务器找到同步接口的relavant方法的实现并调用它,并发送回响应(同步)。 The response triggers a callback on the javascript's side (asynchronously). 响应会触发javascript端的回调(异步)。

So there you have it. 所以你有它。 The whole asynchronicity stems from how the XMLHttpRequest object works. 整个异步性源于XMLHttpRequest对象的工作方式。

Note that the diagram on the official wiki is misleading - the Javascript calls the async interface, not the synchronous one (as the image would suggest). 请注意,官方Wiki上的图表具有误导性-Javascript调用了async接口,而不是同步接口(如图所示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM