🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.java
Article #154025

{JAVA} CachingDispatchAsync problem

#154025
From: J-23
Date: Fri, 13 Jun 2014 17:07
82 lines
2978 bytes
Witam,
Mam klasę CachingDispatchAsync, mam biblioteki GWTDispatch, Gin, Guice

import java.util.HashMap;
import java.util.Map;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
import net.customware.gwt.dispatch.client.DispatchAsync;
import net.customware.gwt.dispatch.shared.Action;
import net.customware.gwt.dispatch.shared.Result;

/**
* Dispatcher which support caching of data in memory
*
*/
public class CachingDispatchAsync implements DispatchAsync {
  private DispatchAsync dispatcher;
  private Map, Result> cache = new HashMap, Result>(); - tutaj jakoś to 
dziwnie skonstruowane (sypie błędami)

  @Inject
  public CachingDispatchAsync(final DispatchAsync dispatcher) {
   this.dispatcher = dispatcher;
  }

  /*
   * (non-Javadoc)
   * @see net.customware.gwt.dispatch.client.DispatchAsync#execute(A, 
com.google.gwt.user.client.rpc.AsyncCallback)
   */
  public , R extends Result> void execute(final A action, final 
AsyncCallback callback) { -- tutaj mnie zastanawia ten "," przed "R"
   dispatcher.execute(action, callback);
  }

  /**
   * Execute the give Action. If the Action was executed before it will 
get fetched from the cache
   *
   * @param Action implementation
   * @param Result implementation
   * @param action the action
   * @param callback the callback
   */
  @SuppressWarnings("unchecked")
  public , R extends Result> void executeWithCache(final A action, final 
AsyncCallback callback) {
   final Result r = cache.get(action);

   if (r != null) {
    callback.onSuccess((R) r);
   }
   else {
    dispatcher.execute(action, new AsyncCallback() {

     public void onFailure(Throwable caught) {
      callback.onFailure(caught);
     }

     public void onSuccess(R result) {
      cache.put((Action) action, (Result) result);
      callback.onSuccess(result);
     }

    });
   }
  }

  /**
   * Clear the cache
   */
  public void clear() {
   cache.clear();
  }
}


klasa pochodzi stąd 
http://blog.hivedevelopment.co.uk/2009/08/google-web-toolkit-gwt-mvp-example.html 
jak ją poprawić by to poprawnie działało?

Pozdrawiam
Technical Details
Message-ID: <lnfb43$qeq$1@node1.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: J-23 <baczeklu@o2.pl>
Newsgroups: pl.comp.lang.java,pl.comp.lang.delphi
Subject: {JAVA} CachingDispatchAsync problem
Date: Fri, 13 Jun 2014 19:07:15 +0200
Organization: ATMAN - ATM S.A.
Lines: 82
Message-ID: <lnfb43$qeq$1@node1.news.atman.pl>
NNTP-Posting-Host: 77-255-40-198.adsl.inetia.pl
Mime-Version: 1.0
X-Trace: node1.news.atman.pl 1402679235 27098 77.255.40.198 (13 Jun 2014 17:07:15 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Fri, 13 Jun 2014 17:07:15 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit