简体   繁体   中英

Sequence diagram for GWT RPC mechanism

I don't fully understand the GWT RPC mechanism adn therefore I am looking for a sequence diagram. 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

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)
  • 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;
  • the Javascript side is asynchronous. When you send a HTTP request in Javascript, you cannot wait for the response, you can only provide a callback. This is why you cannot wrap an HTTP call that returns a value in a synchronous interface.
  • 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).,
  • during the compilation of the GWT project a class implementing the client interface is generated. 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). The response triggers a callback on the javascript's side (asynchronously).

So there you have it. The whole asynchronicity stems from how the XMLHttpRequest object works.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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