Reputation: 1728
I am new to GWT and am able to work around with GWT RPC but have problem in understanding how the control flow takes place internally. How it gets translated to AJAX?
Can we use new()
instead of GWT.create(someService.class)
to make an RPC call?
Why does Google not just use Async version instead of creating 2 interfaces?
What happens internally when we use
TaskService Async = GWT.create(TaskService.class);
I have read that it chooses the browser specific hashname.js
file but am not understanding the complete control flow. Also How is the Callback Object used.
Can someone explain the control flow by pointing out the essentials?
UPDATE : @Thomas Broyer, Everything I understood... Just confirming that in case GWT.create() there is a .rpc file in the client side which helps in the deferred(late/runtime) binding. Is that correct?
Upvotes: 1
Views: 1683
Reputation: 64561
GWT.create()
will in this case call a GWT generator; it'll generate a class implementing the Async interface (and that's why you only have to declare an interface and you never implement it yourself).
See RPC Plumbing Diagram.
Using a generator (or selecting a specific implementation, but in the case of GWT-RPC, a generator is used) is called deferred binding.
So, no, you cannot use new
.
As to why there are 2 interfaces, this is so that GWT can check that your server-side code (synchronous) is consistent with your client-side code (async). The reason you call GWT.create
on the synchronous interface and it returns an implementation of the async one is legacy. I bet they wouldn't do it that way, were they to re-implement GWT-RPC from scratch.
The generated class will be responsible of serializing the call (method name and arguments) and make an AJAX request (using a RequestBuilder
); and then deserialize the response (either of the type declared, or an exception)
Because calls are asynchronous, the callback is used to, well, call your code back when the server responds, after deserialization takes place (so either calling onSuccess
with the decoded object, or onFailure
with the decoded exception).
See Getting Used to Asynchronous Calls
Upvotes: 4