如何对 gwt-rpc 调用进行分组?

发布于 2024-07-07 12:39:33 字数 216 浏览 9 评论 0原文

使用 DWR,可以将多个服务调用组合到一个 HTTP 请求中:
dwr 批处理功能

此功能对于减少 ajax 应用程序的延迟非常有用。 有没有办法用 GWT / GWT-RPC 做类似的事情?
感谢您的帮助

With DWR it is possible to group together several service calls into one single HTTP request :
dwr batch feature

This feature is very useful to reduce the latency of an ajax application.
Is there a way to do something similar with GWT / GWT-RPC ?
Thanks for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

财迷小姐 2024-07-14 12:39:33

Google 的 Ray Ryan 做了一个关于构建 GWT 应用的最佳实践的演示,他谈到使用命令模式。 您可能想要发送恰好通过 RPC 的异步命令。 一旦您发送命令而不是 RPC,就很容易对它们进行批处理。

请参阅 gwt-dispatch 了解为您实现此模式的库。 我刚刚开始使用它,所以我不知道它是否自动批处理,但它都是开源的,有许可,所以如果没有,你可以修复它。

Google's Ray Ryan did a presentation about Best Practices For Architecting Your GWT App, where he talked about using a command pattern. Sending asynchronous commands that happen to go over RPC is what you probably want. Once you're sending commands instead of RPCs, it's very easy to batch them.

See gwt-dispatch for a library that implements this pattern for you. I'm just starting to use it, so I don't know if it batches automatically, but it's all open source with a permissive licence, so you can fix it if it doesn't.

岁月无声 2024-07-14 12:39:33

GWT 不提供用于批量处理多个任意 RPC 的一步式解决方案。 但是,请记住,GWT 的自动序列化使得编写每个 RPC 方法的串行版本和批处理版本变得非常容易。 例如,假设您已经定义了此 RPC:

FooResponse callFoo(FooRequest request);

自己编写同一 RPC 的“批量”版本非常容易:

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

GWT doesn't provide a one-step solution for batching several arbitrary RPCs. However, keep in mind that GWT's automatic serialization makes it quite easy to write both serial and batched versions of each of your RPC methods. For example, suppose you've defined this RPC:

FooResponse callFoo(FooRequest request);

It's this easy to write a "batch" version of the same RPC yourself:

ArrayList<FooResponse> batchCallFoo(ArrayList<FooRequest> requests) {
  ArrayList<FooResponse> responses = new ArrayList<FooResponse>();
  for (FooRequest request : requests) {
    responses.add(callFoo(request));
  }
}
海之角 2024-07-14 12:39:33

这是一个很好的问题,但我认为没有一个简单的解决方案。

我相信您必须创建一个单独的方法,将您的方法组合在一起,以与 DWR 类似的方式实现批处理。

即,如果您有:

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

您将创建一个新方法来组合它们:

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

当然,您仍然需要在同一回调方法中处理整个响应。

我意识到这可能不是最优雅的解决方案,但由于 GWT RPC 的工作方式,我认为这是可行的方法。 对于 GWT,我认为您通常应该尝试编写您的方法,这样批处理甚至不会成为您需要考虑的问题。

It's a good question but I don't think there's an easy solution.

I believe you'll have to create a separate method that groups together your methods to achieve batching in a similiar way to DWR.

Ie if you have:

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

You'd create a new method to combine them:

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

You will still need to handle the whole response in the same callback method of course.

I realize it might not be the most elegant solution but due to the way GWTs RPC work I think it's the way to go. With GWT I think you should generally try to write your methods so that batching won't even be an issue you need to consider.

ぇ气 2024-07-14 12:39:33

如果您的应用程序适合 Comet 域(服务器端-推):

GWTEventService 是一个基于事件的客户端-服务器通信框架。 它使用 GWT-RPC 和 Comet / 服务器推送技术。 客户端提供高级 API,可以像 GUI 组件一样将侦听器注册到服务器。 事件可以添加到服务器端的上下文/域,并且客户端的侦听器会收到有关传入事件的通知。 服务器端完全独立于客户端实现,并且具有高度可配置性。

因为该事件模型提供的优点之一是:

事件被捆绑以减少服务器调用

You can also use GWTEventService if your application fits into the domain of Comet (server-side-push):

GWTEventService is an event-based client-server communication framework. It uses GWT-RPC and the Comet / server-push technique. The client side offers a high-level API with opportunities to register listeners to the server like to a GUI component. Events can be added to a context/domain on the server side and the listeners on the client side get informed about the incoming events. The server side is completely independent of the client implementation and is highly configurable.

Because one of the advantages offered by this event model is:

Events are bundled to reduce server calls

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文