Code Search for Developers
 
 
  

CachingStatisticMapRepository.java from Tea Stats at Krugle


Show CachingStatisticMapRepository.java syntax highlighted

package net.time4tea.webstats.statistic.repo;

import net.time4tea.webstats.jms.EnvironmentException;
import net.time4tea.webstats.statistic.StatisticMap;
import org.joda.time.Instant;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Originally richja 24-Jul-2007
 */
public class CachingStatisticMapRepository implements StatisticMapRepository {
    private StatisticMapRepository repository;

    Map<String,StatisticMap> loaded = new HashMap<String, StatisticMap>();

    public CachingStatisticMapRepository(StatisticMapRepository repository) {
        this.repository = repository;
    }


    public StatisticMap getStatisticMapForInstant(String name, Instant instant) throws EnvironmentException {
        String key = name + instant;
        if ( loaded.containsKey(key)) {
            return loaded.get(key);
        }
        else {
            StatisticMap map = repository.getStatisticMapForInstant(name, instant);
            loaded.put(key, map);
            return map;
        }
    }

    public Collection<StatisticMap> findAll() throws EnvironmentException {
        sync();
        return repository.findAll();
    }

    public Collection<Instant> findPeriodsAvailableForNamedMap(String name) throws EnvironmentException {
        sync();
        return repository.findPeriodsAvailableForNamedMap(name);
    }

    public void sync() throws EnvironmentException {
        loaded = new HashMap<String, StatisticMap>();
        repository.sync();
    }
}




See more files for this project here

Tea Stats

Web log analyzer... Written in OO Perl, provides the usual host / page analysis. Can also do site graphing using graphviz, browser, os, worm and search engine identification, and country and session tracking.

Project homepage: http://sourceforge.net/projects/teastats
Programming language(s): Java
License: other

  CachingStatisticMapRepository.java
  DailyStatisticMapRepository.java
  DiskBasedStatisticMapRepository.java
  MonthlyStatisticMapRepository.java
  SingleStatisticMapRepository.java
  StatisticMapRepository.java