⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixedsizedelaycache.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Core License version 1 published by ozone-db.org.//// Copyright (C) 2003-@year@, Leo Mekenkamp. All rights reserved.//// $Id: FixedSizeDelayCache.java,v 1.1.2.2 2004/04/10 10:06:51 per_nyfelt Exp $package org.ozoneDB.core.storage;import java.util.Collection;import java.util.Comparator;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.LinkedHashSet;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set;import java.util.Map.Entry;import java.util.SortedSet;import java.util.TreeMap;import java.util.TreeSet;import java.util.logging.Level;import java.util.logging.Logger;import org.ozoneDB.OzoneInternalException;import org.ozoneDB.core.ConfigurationException;/** * <p>A cache with a fixed maximum number of objects in it. This cache grows * until it has reached its maximum, which can be set by maxCapacity. Once that * maximum has been reached, the least recently used object is thrown away when * a new object is put in the cache. This cache has, next to that maximum number * of elements, also a maximum time an element will remain in this cache. If  * that time has expired the element will be removed from this cache also.  * Reinserting an element (using the same key) causes the time for that element * to be reset.</p> * * <p>Note: every instance creates its own thread for asynchronous removal of * items past their 'best before' time. The trimmed() method on the TrimHandler * is often but not always called asynchronously from that thread.</p> *  * @author <a href="mailto:leoATmekenkampD0Tcom">Leo Mekenkamp (mind the anti sp@m)</a> * @version $Id: FixedSizeDelayCache.java,v 1.1.2.2 2004/04/10 10:06:51 per_nyfelt Exp $ */public class FixedSizeDelayCache extends DelayCache {        private static final Logger log = Logger.getLogger(FixedSizeDelayCache.class.getName());    public static final PropertyInfo MAXCAPACITY = new PropertyInfo(        ".maxCapacity",        "int",        "1",        "number of objects that this cache should hold as a maximum",        new String[] {"100", "100000"}    );    private int maxCapacity;        public FixedSizeDelayCache(Properties properties, String prefix) {        super(properties, prefix);        try {            setMaxCapacity(Integer.parseInt(properties.getProperty(prefix + MAXCAPACITY.getKey(), MAXCAPACITY.getDefaultValue())));            log.config(getPrefix() + " using a max capacity of " + getMaxCapacity());        } catch (NumberFormatException e) {            throw new ConfigurationException(e);        }    }    public final void setMaxCapacity(int maxCapacity) {        synchronized(getSynchronizer()) {            this.maxCapacity = maxCapacity;            ourTrim();        }    }        public final int getMaxCapacity() {        // maxCapacity is an int so synchronization is not needed        return maxCapacity;    }        public Collection getPropertyInfos() {        Collection result = super.getPropertyInfos();        result.add(MAXCAPACITY);        return result;    }        public void put(Object key, Object value) {        synchronized(getSynchronizer()) {            super.put(key, value);            ourTrim();        }    }    private void ourTrim() {        while (size() > getMaxCapacity()) {            TimedEntry last = (TimedEntry) getEntries().last();            if (getTrimHandler() != null) {                getTrimHandler().trimming(last.key, last.value);            }            getEntries().remove(last);            getKeysToEntries().remove(last.key);        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -