Guava MapMaker - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava MapMaker class.

This code example shows how to use the following methods:concurrencyLevel, initialCapacity, makeMap, softValues, expiration
            int maxConcurrentThreads) {
 
        this.name = name;
        this.expirationInMinutes = expirationInMinutes;
                 
        MapMaker mapMaker = new MapMaker();
        mapMaker.initialCapacity(initialCapacity);
        mapMaker.expiration(expirationInMinutes * 60, TimeUnit.SECONDS);
        mapMaker.concurrencyLevel(maxConcurrentThreads);
        mapMaker.softValues();
        this.cache = mapMaker.makeMap();
    } 
 
    /** 
     * Sanitize disk cache. Remove files which are older than expirationInMinutes. 
     */ 
    private void sanitizeDiskCache() { 
        File[] cachedFiles = new File(diskCacheDirectory).listFiles();
        if (cachedFiles == null) {
            return; 
8
CodeRank
This code example shows how to use the following methods:makeMap
 
    public final static String TOGGLE_PROPERTY = "org.gradle.resolution.memorycache";
 
    private final static Logger LOG = Logging.getLogger(InMemoryCachedRepositoryFactory.class); 
 
    Map<String, InMemoryModuleComponentRepositoryCaches> cachePerRepo = new MapMaker().makeMap();
 
    final InMemoryCacheStats stats = new InMemoryCacheStats();
 
    public ModuleComponentRepository cached(ModuleComponentRepository input) {
        if ("false".equalsIgnoreCase(System.getProperty(TOGGLE_PROPERTY))) {
            return input;
        } 
 
        InMemoryModuleComponentRepositoryCaches caches = cachePerRepo.get(input.getId());
        stats.reposWrapped++;
        if (caches == null) {
            LOG.debug("Creating new in-memory cache for repo '{}' [{}].", input.getName(), input.getId());
            caches = new InMemoryModuleComponentRepositoryCaches(stats);
            stats.cacheInstances++;
7
CodeRank
This code example shows how to use the following methods:
     */ 
    private final ConcurrentMap<StoreTransaction, Map<KeyColumn, S>> locks;
 
    public LockerState() { 
        // TODO this wild guess at the concurrency level should not be hardcoded 
        this(new MapMaker().concurrencyLevel(8).weakKeys()
                .<StoreTransaction, Map<KeyColumn, S>> makeMap());
    } 
 
    public LockerState(ConcurrentMap<StoreTransaction, Map<KeyColumn, S>> locks) {
        this.locks = locks;
    } 
 
    public boolean has(StoreTransaction tx, KeyColumn kc) {
        return getLocksForTx(tx).containsKey(kc);
    } 
 
    public void take(StoreTransaction tx, KeyColumn kc, S ls) {
        getLocksForTx(tx).put(kc, ls);
    } 
6
CodeRank
This code example shows how to use the following methods:makeMap
public class DefaultInterceptorHandlerFactory implements InterceptorHandlerFactory { 
 
	private Container container;
 
	private ConcurrentMap<Class<? extends Interceptor>, InterceptorHandler> cachedHandlers =
		new MapMaker().makeMap();
 
	public DefaultInterceptorHandlerFactory(Container container) {
		this.container = container;
	} 
 
	public InterceptorHandler handlerFor(Class<? extends Interceptor> type) {
		if (type.isAnnotationPresent(Lazy.class)) { 
			InterceptorHandler handler = cachedHandlers.get(type);
			if (handler == null) {
				LazyInterceptorHandler value = new LazyInterceptorHandler(container, type);
				cachedHandlers.putIfAbsent(type, value);
				return value;
			} else { 
				return handler;
7
CodeRank
This code example shows how to use the following methods:makeMap
 *  
 * @author Dhanji R. Prasanna (dhanji@gmail.com) 
 */ 
@ThreadSafe @SessionScoped 
public class HttpSessionFlashCache implements FlashCache, Serializable {
  private final ConcurrentMap<String, Object> cache = new MapMaker().makeMap();
 
  @SuppressWarnings("unchecked") 
  public <T> T get(String key) {
    return (T) cache.get(key);
  } 
 
  @SuppressWarnings("unchecked") 
  public <T> T remove(String key) {
    return (T) cache.remove(key);
  } 
 
  public <T> void put(String key, T t) {
    cache.put(key, t);
  } 
7
CodeRank
This code example shows how to use the following methods:concurrencyLevel, initialCapacity, makeMap, softValues, expiration
            int maxConcurrentThreads) {
 
        this.name = name;
        this.expirationInMinutes = expirationInMinutes;
                 
        MapMaker mapMaker = new MapMaker();
        mapMaker.initialCapacity(initialCapacity);
        mapMaker.expiration(expirationInMinutes * 60, TimeUnit.SECONDS);
        mapMaker.concurrencyLevel(maxConcurrentThreads);
        mapMaker.softValues();
        this.cache = mapMaker.makeMap();
    } 
 
    /** 
     * Sanitize disk cache. Remove files which are older than expirationInMinutes. 
     */ 
    private void sanitizeDiskCache() { 
        File[] cachedFiles = new File(diskCacheDirectory).listFiles();
        if (cachedFiles == null) {
            return; 
6
CodeRank
This code example shows how to use the following methods:makeMap
 * @author zebin.xuzb 2012-10-30 下午3:45:17 
 * @since 1.0.0 
 */ 
public abstract class AbstractCanalGroupStore<T> extends AbstractCanalLifeCycle implements CanalGroupEventStore<T> { 
 
    protected Map<String, StoreInfo> stores = new MapMaker().makeMap();
 
    @Override 
    public void addStoreInfo(StoreInfo info) {
        checkInfo(info);
        stores.put(info.getStoreName(), info);
    } 
 
    protected void checkInfo(StoreInfo info) {
        Assert.notNull(info);
        Assert.hasText(info.getStoreName());
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:
class DalvikStatsCache { 
 
  private final ConcurrentMap<FileLike, DalvikStatsTool.Stats> cache;
 
  DalvikStatsCache() { 
    cache = new MapMaker().weakKeys().makeMap();
  } 
 
  DalvikStatsTool.Stats getStats(FileLike entry) {
    String name = entry.getRelativePath();
    if (!name.endsWith(".class")) {
      // Probably something like a pom.properties file in a JAR: this does not contribute 
      // to the linear alloc size, so return zero. 
      return DalvikStatsTool.Stats.ZERO; 
    } 
 
    DalvikStatsTool.Stats stats = cache.get(entry);
    if (stats != null) {
      return stats;
    } 
6
CodeRank
This code example shows how to use the following methods:makeMap
    protected Map<String, LogPosition> positions;
 
    public void start() { 
        super.start(); 
 
        positions = new MapMaker().makeMap();
    } 
 
    public void stop() { 
        super.stop(); 
 
        positions.clear();
    } 
 
    public LogPosition getLatestIndexBy(String destination) {
        return positions.get(destination);
    } 
 
    public void persistLogPosition(String destination, LogPosition logPosition) {
        positions.put(destination, logPosition);
7
CodeRank
This code example shows how to use the following methods:makeComputingMap
 * @version 1.0.0 
 */ 
public class ZkClientx extends ZkClient { 
 
    // 对于zkclient进行一次缓存,避免一个jvm内部使用多个zk connection 
    private static Map<String, ZkClientx> clients = new MapMaker().makeComputingMap(new Function<String, ZkClientx>() {
 
                                                      public ZkClientx apply(String servers) { 
                                                          return new ZkClientx(servers); 
                                                      } 
                                                  }); 
 
    public static ZkClientx getZkClient(String servers) {
        return clients.get(servers);
    } 
 
    public ZkClientx(String serverstring){
        this(serverstring, Integer.MAX_VALUE);
    } 
 
6
CodeRank
See Code Examples for Guava MapMaker Methods: