How to group gwt-rpc calls?

With DWR, you can combine multiple service calls into a single HTTP request:
dwr batch function

This feature is very useful for reducing ajax application latency. Is there a way to do something similar with GWT / GWT-RPC?
Thank you for your help.

+7
ajax gwt dwr gwt-rpc
source share
4 answers

Google Ray Ryan made a presentation on "Best Practices for Archiving Your GWT Application," where he talked about using the team template. Sending asynchronous commands that happen to the RPC is what you probably want. Once you send commands instead of RPCs, they are very easy to execute.

See gwt-dispatch for a library that implements this template for you. I'm just starting to use it, so I don’t know if it will download automatically, but it's all open source with a permissive license, so you can fix it if it isn’t.

+8
source share

GWT does not provide a one-step solution for batch processing multiple arbitrary RPCs. However, keep in mind that automatic GWT serialization makes it easy to record both serial and batch versions of each of your RPC methods. For example, suppose you defined this RPC:

FooResponse callFoo(FooRequest request); 

It is easy to write a "batch" version of the same RPC:

 ArrayList<FooResponse> batchCallFoo(ArrayList<FooRequest> requests) { ArrayList<FooResponse> responses = new ArrayList<FooResponse>(); for (FooRequest request : requests) { responses.add(callFoo(request)); } } 
+1
source share

This is a good question, but I do not think this is a simple solution.

I believe that you will need to create a separate method that combines your methods to ensure batch processing in accordance with the DWR.

Those. if you have:

 public int add(int x, int y); public int sub(int i, int j); 

Create a new method to combine them:

 public Map<String, Integer> addAndSub(Map methodsAndArguments) { // Call add and sub methods with it arguments } 

You still have to handle the entire response in the same callback method, of course.

I understand that this may not be the most elegant solution, but because of how the GWTs RPC works, I think this is the way to go. With GWT, I think that you are usually trying to write your methods so that batch processing is not even a problem that you have to consider.

+1
source share

You can also use GWTEventService if your application fits into the comet domain (server side):

GWTEventService is an event-based client-server communication infrastructure. It uses GWT-RPC and Comet / Server-push technology. The client side offers a high-level API with the ability to register listeners on the server like a GUI component. Events can be added to the server-side context / domain, and client-side listeners receive information about incoming events. The server side is completely independent of the client implementation and has a high degree of configuration.

Because one of the advantages of this event model is:

Events combine to reduce server calls

+1
source share

All Articles