Results 1 to 6 of 6

Thread: Parallel proxy/loader loading

  1. #1
    Ext GWT Premium Member
    Join Date
    Jun 2008
    Location
    Poland
    Posts
    306

    Question Parallel proxy/loader loading

    Hi,

    I'm using GXT2 (still..) and I have a proxy/loader/store defined. I have a navigation tree and when user click on it, we call loader.load().

    The problem is that when user clicks to fast in the tree sometimes the wrong response comes as the last one and incorrect results are displayed (from a wrong node). How to make sure that the most recent request response will be displayed and not anything else?

    Thanks in advance for any help,
    Mariusz

  2. #2
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,178

    Default

    Couple things come to mind.

    1. Mask tree onload.
    2. Listen to beforeload, loadcomplete, loadexception events and on loadcomplete, loadexception, mark a loading flag as 'false'.

    Another option is directly talk to the RequestBuilder if its being used. If a rpc or request builder is being used in the loader, the rpc async interface can return the request builder type and the request.cancel() can be called, but tracked conjunction with the load handler calls and flag.

    Would any of those help be an option?

  3. #3
    Ext GWT Premium Member
    Join Date
    Jun 2008
    Location
    Poland
    Posts
    306

    Default

    Hi,

    thank you. I cannot mask the tree as users will not accept that behavior.
    I'm using an RCP that returns PagingLoadResult so I'd need somehow cancel the previous AsyncCallback.
    Can you provide me some code sample how can I do that?

    Thank you,
    Mariusz

  4. #4
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,178

    Default

    I found one of my older test cases had something like you might want. I haven't tried this out in a while, but should provide some clues for options.

    The rpc async interface can return a Request or RequestBuilder, and this can be used to cancel the request.
    Code:
    public interface RpcServiceAsync {
      // return Request
      Request getData(String query, AsyncCallback<List<State>> callback) 
          throws IllegalArgumentException;
    }
    In this example the load is overridden and then prev request is canceled if need be. If you notice the prevRequest = rpcService.getData("1", handler); returns the Request and then is used to cancel if another comes in. In this case the later request is wanted.
    Code:
    RpcProxy<PagingLoadResult<State>> proxy = new RpcProxy<PagingLoadResult<State>>() {
          @Override
          public void load(Object loadConfig, final AsyncCallback<PagingLoadResult<State>> callback) {
            if (prevRequest != null) {
              prevRequest.cancel();
            }
    
    
            AsyncCallback<List<State>> handler = new AsyncCallback<List<State>>() {
              @Override
              public void onFailure(Throwable caught) {
                caught.printStackTrace();
              }
    
    
              @Override
              public void onSuccess(final List<State> result) {
                callback.onSuccess(new PagingLoadResult<State>() {
                  @Override
                  public List<State> getData() {
                    return result;
                  }
    
    
                  @Override
                  public void setTotalLength(int totalLength) {
                  }
    
    
                  @Override
                  public void setOffset(int offset) {
                  }
    
    
                  @Override
                  public int getTotalLength() {
                    return 100;
                  }
    
    
                  @Override
                  public int getOffset() {
                    return 0;
                  }
                });
              }
            };
    
    
            if (count == 0) {
              System.out.println("loading 1");
              prevRequest = rpcService.getData("1", handler);
            } else {
              System.out.println("loading 2");
              prevRequest = rpcService.getData("2", handler);
            }
            count++;
          }
        };
    Would this help provide some options?

  5. #5
    Ext GWT Premium Member
    Join Date
    Jun 2008
    Location
    Poland
    Posts
    306

    Default

    Thank you Brandon!!!

    The solution is simpler than I thought

    Code:
    if (previousRequest != null) {
    	if (previousRequest.isPending())
    		previousRequest.cancel();
    }
    previousRequest = ItemsServiceAsync.INSTANCE.getItems(listConfig, callback);
    Thanks again, that seems to work fine.
    Mariusz

  6. #6
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,178

    Default

    Thanks. Nice job and good to hear.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •