取消 GWT RequestFactory 请求
有没有办法取消/中止请求工厂请求?使用 GWT 2.3
Is there a way to cancel/abort request factory requests? Using GWT 2.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有办法取消/中止请求工厂请求?使用 GWT 2.3
Is there a way to cancel/abort request factory requests? Using GWT 2.3
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
调用
fire()
方法后无法取消请求。考虑构建自定义Receiver
基类,如下所示:对于
Receiver
类型中的其他方法,可以重复该模式。There is no way to cancel a request after the
fire()
method has been called. Consider building a customReceiver
base class such as the following:The pattern can be repeated for other methods in the
Receiver
type.另一种选择是创建替代的
com.google.web.bindery.requestfactory.shared.RequestTransport
类型,而不是使用DefaultRequestTransport
。这样做的缺点(也是 BobV 方法的优点)是,您不知道服务器上的请求何时杀死它,因此它可能已经运行了您的一些方法 - 您不会从其中任何一个方法获得反馈,您只需停止传出请求即可。我怀疑这就是为什么 RF 没有像 RPC 那样具有此功能的原因。甚至考虑 RPC 或 RequestBuilder 的情况 - 它们如何通知服务器他们改变了主意,并且不运行请求?我的理解是他们没有 - 他们提前关闭的唯一方法是当他们尝试读/写响应时,并收到 TCP 错误,因为连接已关闭。 (我可能错了,另一个线程密切关注 tcp 连接的状态并调用
thread.stop(Throwable)
,但 stop 已被弃用 相当多while。)一种想法是向服务器发送一条消息,告诉它杀死来自同一会话的其他请求 - 但这需要积极参与您的服务器代码,可能会在
中通用ServiceLayerDecorator
子类型,可能至少在invoke
、loadDomainObject(s)
和getSetter
等中。很明显,这需要 GWT 为您构建它……Another option would be to create an alternative
com.google.web.bindery.requestfactory.shared.RequestTransport
type, instead of usingDefaultRequestTransport
. Downside to this (and upside to BobV's approach) is that you won't know when in the request on the server you kill it, so it might have already run some of your methods - you won't get feedback from any of them, you'll just stop the outgoing request.I suspect this is why RF doesn't have this feature already, as RPC does. Consider even the case of RPC though or RequestBuilder - how do those notify the server that they've changed their mind, and to not run the request? My understanding is that they don't - the only way they are shut down early is when they try to read/write to the response, and get a tcp error, as the connection has been closed. (It's possible I am mistaken, and that another thread keeps an eye on the state of the tcp connection and calls
thread.stop(Throwable)
, but stop has been deprecated for quite a while.)One thought would be to send a message to the server, telling it to kill off other requests from the same session - this would require active participation in your server code though, possibly made generic in a
ServiceLayerDecorator
subtype, probably in at leastinvoke
,loadDomainObject(s)
, andgetSetter
, among others. This pretty clearly is to involved to ask GWT to build it for you though...