Package net.sf.jsr107cache

Examples of net.sf.jsr107cache.Cache


   */
  public void setResult(int x, int y, Date evaluatedAt){
    long elapse = System.currentTimeMillis();
    log.info("[StatisticsManager#setResult()] (x,y)=(" + x +", " + y +")");
    // キャッシュ取得
    Cache cache =
        CacheManager.getInstance().getCache(C_NAME);
    // 集計結果キャッシュを加算
    Summary summary = (Summary) cache.get(C_KEY_SUMMARY);
    log.info("[StatisticsManager#setResult()] got summary from cache: " +
        summary);
    if(summary == null){
      summary = new Summary();
      log.info("[StatisticsManager#setResult()] summary(cache) is null " +
          "/create new summary: " + summary.toString());
    }
   
    summary = Utils.add(x, y, evaluatedAt, summary);
    log.info("[StatisticsManager#setResult()] count up summary: " +
        summary.toString());
    cache.put(C_KEY_SUMMARY, summary);

    // 結果キャッシュを更新
    Results results =
        (Results) cache.get(C_KEY_RESULTS);
    log.info("[StatisticsManager#setResult()] got results from cache: " +
        results);
    if(results == null){
      results = new Results();
      log.info("[StatisticsManager#setResult()] results(cache) is null " +
          "/create new result: " + results.toString());
    }
    results.add(x, y, evaluatedAt);
    log.info("[StatisticsManager#setResult()] count up results: " +
        results.toString());
    cache.put(C_KEY_RESULTS, results);
    log.info("[StatisticsManager#setResult()] update result cache:" +
        results.toString());
    log.info("[StatisticsManager#setResult()] end" +
        (System.currentTimeMillis() - elapse) + "mSec.");
  }


   */
  public Results getResults(){
    long elapse = System.currentTimeMillis();
    log.info("[StatisticsManager#getResults()] start");
    // キャッシュ上のすべての結果をリストへ移動
    Cache cache =
        CacheManager.getInstance().getCache(C_NAME);
    Results results =
          (Results) cache.get(C_KEY_RESULTS);
    if(results==null){
      results = new Results();
    }
    log.info("[StatisticsManager#getResults()] end: " +
        (System.currentTimeMillis() - elapse) + "mSec.");

   * @return サマリ
   */
  public Summary getSummary(){
    long elapse = System.currentTimeMillis();
    log.info("[StatisticsManager#getSummary()] start");
    Cache cache =
        CacheManager.getInstance().getCache(C_NAME);
    Summary summary = (Summary)cache.get(C_KEY_SUMMARY);
    log.info("[StatisticsManager#getSummary()] got summary from cache: " +
        summary);
    if(summary == null){
      summary = new Summary();
      log.info("[StatisticsManager#getSummary()] no summary cache/create:"
          + summary.toString());
      cache.put(C_KEY_SUMMARY, summary);
      log.info("[StatisticsManager#getSummary()] update summary cache: " +
          summary.toString());
    }
    log.info("[StatisticsManager#getSummary()] end: " +
        (System.currentTimeMillis() - elapse) + "mSec.");

   */
  public void clearResults(){
    long elapse = System.currentTimeMillis();
    log.info("[StatisticsManager#clearResults()] start");
    // キャッシュ上のすべての結果をリストへ移動
    Cache cache =
        CacheManager.getInstance().getCache(C_NAME);
    cache.put(C_KEY_RESULTS, new Results());
    log.info("[StatisticsManager#clearResults()] end: " +
        (System.currentTimeMillis() - elapse) + "mSec.");
  }

//    props.put(GCacheFactory.EXPIRATION_DELTA, C_TIMEOUT);
    CacheManager cMan = CacheManager.getInstance();
    props.put("name", C_NAME);
    try{
      CacheFactory cFac = cMan.getCacheFactory();
      Cache cache = cFac.createCache(props);
      cMan.registerCache(C_NAME, cache);
      cache.put(C_KEY_RESULTS, new Results());
      cache.put(C_KEY_SUMMARY, retrieveSummary());
    }catch(CacheException e){
     
    }
  }

            cacheCleanupTask = new CacheCleanupTask(carbonCacheManager);
            CarbonContextHolderBase.registerUnloadTenantTask(cacheCleanupTask);
        }

        public Cache getCache(String cacheName) {
            Cache cache = carbonCacheManager.getCache(getNameForTenant(cacheName));
            if (cache != null) {
                cacheCleanupTask.register(getCurrentCarbonContextHolder().getTenantId(),
                        getNameForTenant(cacheName));
            }
            if (log.isDebugEnabled()) {

    return authorizedNamespaces;
  }
 
  public boolean removeFromCache(String key) {
    try {
      Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
      cache.remove(key);
      return true;
    } catch (CacheException e) {
      return false;
    }
  }

    /**
     * Ripulisce l'intera Memcache
     */
    public static void cacheClear() {
        Cache cache;
        cache = CacheSupport.cacheInit();

        cache.clear();
    }

    /**
     * carica dalla mappa della Memcache l'oggetto la cui chiave è data in input
     */
    public static Object cacheGet(String id) {
        Cache cache;
        cache = CacheSupport.cacheInit();

        return cache.get(id);
    }

    /**
     * Salva nella Memcache l'oggetto e la relativa chiave dati in input
     */
    public static void cachePut(String id, Serializable o) {
        Cache cache;
        cache = CacheSupport.cacheInit();

        cache.put(id, o);
    }

TOP

Related Classes of net.sf.jsr107cache.Cache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.