문제

Is there a way to cancel/abort request factory requests? Using GWT 2.3

도움이 되었습니까?

해결책

Another option would be to create an alternative com.google.web.bindery.requestfactory.shared.RequestTransport type, instead of using DefaultRequestTransport. 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 least invoke, loadDomainObject(s), and getSetter, among others. This pretty clearly is to involved to ask GWT to build it for you though...

다른 팁

There is no way to cancel a request after the fire() method has been called. Consider building a custom Receiver base class such as the following:

public abstract class CancelableReceiver<V> extends Receiver<V> {
  private boolean canceled;

  public void cancel() {
    canceled = true;
  }

  @Override
  public final void onSuccess(V response) {
    if (!canceled) {
      doOnSuccess(response);
    }
  }

  protected abstract void doOnSuccess(V response);
}

The pattern can be repeated for other methods in the Receiver type.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top