Ejemplo n.º 1
0
  @Override
  public List statisticByTop(final String resourceId, final DateSeries dateSeries, TopFilter top) {
    Cache<DateSeries, Map<TopFilter, List>> cache = topCache.getIfPresent(resourceId);

    if (cache == null) {
      cache =
          CacheBuilder.newBuilder().maximumSize(1024).expireAfterWrite(1, TimeUnit.DAYS).build();
      topCache.put(resourceId, cache);
    }

    if (dateSeries != DateSeries.today) {
      try {
        Map<TopFilter, List> map =
            cache.get(
                dateSeries,
                new Callable<Map<TopFilter, List>>() {
                  @Override
                  public Map<TopFilter, List> call() throws Exception {
                    Map<TopFilter, List> map = newHashMap();
                    for (TopFilter t : TopFilter.values()) {
                      map.put(t, statisticTopReport.statisticByTop(resourceId, dateSeries, t));
                    }
                    return map;
                  }
                });
        return map.get(top);
      } catch (ExecutionException e) {
        throw new RuntimeException(e);
      }
    }
    // today data is dynamic,so don't do cache
    else {
      return statisticTopReport.statisticByTop(resourceId, dateSeries, top);
    }
  }
Ejemplo n.º 2
0
 @Override
 public Attribute getAttribute() {
   return statisticTopReport.getAttribute();
 }
Ejemplo n.º 3
0
 @Override
 public ReportAttribute reportAttribute() {
   return statisticTopReport.reportAttribute();
 }