/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/**
* MultiLruCache -- in-memory bounded LRU cache with multiple LRU lists
* Underlying Hashtable is made into logical segments, with each segment
* having its own LRU list.
*/
/* an array of LRU lists; each element in this array is actually
* LruCacheItem[2] with LRU list (lru[0] is head and lru[1] the tail
*/
int segmentSize;
protected int[] listsLength;
int trimCount;
int trimIndex;
/**
* initialize the LRU cache
* @param maxCapacity maximum number of entries this cache may hold
*/
try {
} catch (NumberFormatException nfe) {}
}
}
// create the array of LRU lists
listsLength[i] = 0;
}
}
/**
* get the LRU list associated with the index
* @param index into the BaseCache hashtable
* @return the LRU list to be used
*/
}
/**
* create new item
* @param hashCode for the entry
* @param key <code>Object</code> key
* @param value <code>Object</code> value
* @param size size in bytes of the item
*
* subclasses may override to provide their own CacheItem extensions
* e.g. one that permits persistence.
*/
}
/**
* remove an lru item from one of the LRU lists
* @param the LRU segment index to trim
* @return the item that was successfully trimmed
*/
LruCacheItem l = null;
listsLength[segment]--;
l.isTrimmed = true;
trimCount++;
return l;
}
/**
* this item is just added to the cache
* @param item <code>CacheItem</code> that was created
* @return a overflow item; may be null
*
* Cache bucket is already synchronized by the caller
*/
// update the LRU
synchronized (list) {
}
else
listsLength[segment]++;
if (isThresholdReached()) {
// go round robin for the next trim
}
}
return overflow;
}
/**
* this item is accessed
* @param item <code>CacheItem</code> accessed
*
* Cache bucket is already synchronized by the caller
*/
// update the LRU list
synchronized (list) {
// put the item at the head of LRU list
// patch up the previous neighbors
else
}
}
}
/**
* item value has been refreshed
* @param item <code>CacheItem</code> that was refreshed
* @param oldSize size of the previous value that was refreshed
* Cache bucket is already synchronized by the caller
*/
}
/**
* item value has been removed from the cache
* @param item <code>CacheItem</code> that was just removed
*
* Cache bucket is already synchronized by the caller
*/
// remove the item from the LRU list
synchronized (list) {
// if the item is already trimmed from the LRU list, nothing to do.
if (l.isTrimmed)
return;
else
else
listsLength[segment]--;
}
}
/**
* cache has reached threshold so trim its size. subclasses are expected
* to provide a robust cache replacement algorithm.
*/
protected void handleOverflow() {
LruCacheItem l = null;
}
int getListsLength() {
}
protected void incrementTrimIndex() {
synchronized (trimIndexLk) {
}
}
/**
* get generic stats from subclasses
*/
/**
* get the desired statistic counter
* @param key to corresponding stat
* @return an Object corresponding to the stat
* See also: Constant.java for the key
*/
}
}
}
return stat;
}
/**
* get the stats snapshot
* @return a Map of stats
* See also: Constant.java for the keys
*/
+ i + "]:",
}
return stats;
}
/** default CacheItem class implementation ***/
// double linked LRU list
boolean isTrimmed;
}
}
}