如何对 gwt-rpc 调用进行分组?
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
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.
GWT 不提供用于批量处理多个任意 RPC 的一步式解决方案。 但是,请记住,GWT 的自动序列化使得编写每个 RPC 方法的串行版本和批处理版本变得非常容易。 例如,假设您已经定义了此 RPC:
自己编写同一 RPC 的“批量”版本非常容易:
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:
It's this easy to write a "batch" version of the same RPC yourself:
这是一个很好的问题,但我认为没有一个简单的解决方案。
我相信您必须创建一个单独的方法,将您的方法组合在一起,以与 DWR 类似的方式实现批处理。
即,如果您有:
您将创建一个新方法来组合它们:
当然,您仍然需要在同一回调方法中处理整个响应。
我意识到这可能不是最优雅的解决方案,但由于 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:
You'd create a new method to combine them:
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.
如果您的应用程序适合 Comet 域(服务器端-推):
因为该事件模型提供的优点之一是:
You can also use GWTEventService if your application fits into the domain of Comet (server-side-push):
Because one of the advantages offered by this event model is: