Many GWT applications use GWT RPC to communicate with the backend server. Each RPC service must define a pair of interfaces: the synchronous interface, which is implemented on the server, and the asynchronous interface, which is called by the client-side code. The Google Plugin for Eclipse can help you create and maintain these RPC interfaces via custom errors and quick fixes.
Creating an Asynchronous Interface From a Synchronous Interface
An asynchronous (client-side) RPC interface is very similar to its synchronous (server-side) counterpart. It will usually contain the same methods as the synchronous interface, but the asynchronous methods must each include an additional parameter that represents a callback that is invoked upon completion of the remote call. If your application contains a synchronous interface without a corresponding asynchronous interface, it will be flagged with an error. A set of quick fixes are provided to generate the correct asynchronous interface.
Note: You can change the default severity of any type of problem with Preferences > Google > Errors/Warnings .
The first quick fix will launch the New Asynchronous Remote Service Interface wizard, pre-populated with the correct name and location.
When you click Finish , the asynchronous interface will be generated automatically.
Maintaining Synchronous/Asynchronous Interface Pairs
Correcting mismatched interfaces
If you already have an existing asynchronous interface, the plugin helps you keep it in sync with the synchronous version.
For example, if your synchronous interface contains a method that is not defined on the asynchronous interface, it will generate an error and provide a quick fix to create the asynchronous version of the method. If, however, the method is no longer needed, the second quick fix can remove the unnecessary synchronous method.
The quick fixes also work in the opposite direction, allowing you to generate synchronous methods from existing methods in the asynchronous interface.
Renaming interfaces or methods
If you need to rename an RPC interface or any of its methods, use the built-in Eclipse rename refactoring and the the plugin will take care of renaming the paired interface or its methods.
Missing or invalid asynchronous callbacks
Every asynchronous method must contain an
AsyncCallback
as the last
parameter.
AsyncCallback
is a generic type, in which the parameterization must be assignment-compatible with the return type of the
synchronous version of the method. The plugin will create an error if the callback parameter is missing or invalid.
Invalid async return type
When an RPC method is invoked from client-side code, the result (i.e. the return value of the server-side implementation) is returned as a
parameter to the
onSuccess
method of
AsyncCallback
.
Thus, the return type of the asynchronous interface method itself is typically
void
. However, if you want to have more control over
the pending RPC request (e.g. to support cancellation), the asynchronous method can return a
Request
or
RequestBuilder
instead.
The plugin will detect any asynchronous methods with invalid return types. The provided quick fix lets you change it to one of the allowed types.