|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.mit.jwi.CachingDictionary.ItemCache
public static class CachingDictionary.ItemCache
An LRU cache for objects in JWI.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface edu.mit.jwi.data.IHasLifecycle |
|---|
IHasLifecycle.LifecycleState, IHasLifecycle.ObjectClosedException, IHasLifecycle.ObjectOpenException |
| Field Summary | |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY
|
static float |
DEFAULT_LOAD_FACTOR
|
static int |
DEFAULT_MAXIMUM_CAPACITY
|
protected java.util.Map<IItemID<?>,IItem<?>> |
itemCache
|
protected java.util.Map<ISenseKey,IWord> |
keyCache
|
protected java.util.concurrent.locks.Lock |
lifecycleLock
|
protected java.util.Map<ISenseKey,ISenseEntry> |
senseCache
|
| Constructor Summary | |
|---|---|
CachingDictionary.ItemCache()
Default constructor that initializes the dictionary with caching enabled. |
|
CachingDictionary.ItemCache(int initialCapacity,
int maxCapacity,
boolean enabled)
Caller can specify both the initial size, maximum size, and the initial state of caching. |
|
| Method Summary | ||
|---|---|---|
void |
cacheItem(IItem<?> item)
Caches the specified item, if this cache is enabled. |
|
void |
cacheSenseEntry(ISenseEntry entry)
Caches the specified entry. |
|
void |
cacheWordByKey(IWord word)
Caches the specified word, indexed by its sense key. |
|
protected void |
checkOpen()
An internal method for assuring compliance with the dictionary interface that says that methods will throw ObjectClosedExceptions if the dictionary has not yet been
opened. |
|
void |
clear()
Removes all entries from the cache. |
|
void |
close()
This closes the object by disposing of data backing objects or connections. |
|
int |
getInitialCapacity()
Returns the initial capacity of this cache. |
|
int |
getMaximumCapacity()
Returns the maximum capacity of this cache. |
|
boolean |
isEnabled()
Returns true if this cache is enabled;
false otherwise. |
|
boolean |
isOpen()
Returns true if the dictionary is open, that is, ready to
accept queries; returns false otherwise |
|
protected
|
makeCache(int initialCapacity)
Creates the map that backs this cache. |
|
boolean |
open()
This opens the object by performing any required initialization steps. |
|
protected void |
reduceCacheSize(java.util.Map<?,?> cache)
Brings the map size into line with the specified maximum capacity of this cache. |
|
|
retrieveItem(D id)
Retrieves the item identified by the specified id. |
|
ISenseEntry |
retrieveSenseEntry(ISenseKey key)
Retrieves the sense entry identified by the specified sense key. |
|
IWord |
retrieveWord(ISenseKey key)
Retrieves the word identified by the specified sense key. |
|
void |
setEnabled(boolean isEnabled)
Enables ( true) or disables (false) caching. |
|
void |
setInitialCapacity(int capacity)
Sets the initial capacity of the cache |
|
void |
setMaximumCapacity(int capacity)
Sets the maximum capacity of the cache |
|
int |
size()
Returns the number of items in the cache. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_INITIAL_CAPACITY
public static final int DEFAULT_MAXIMUM_CAPACITY
public static final float DEFAULT_LOAD_FACTOR
protected java.util.concurrent.locks.Lock lifecycleLock
protected java.util.Map<IItemID<?>,IItem<?>> itemCache
protected java.util.Map<ISenseKey,IWord> keyCache
protected java.util.Map<ISenseKey,ISenseEntry> senseCache
| Constructor Detail |
|---|
public CachingDictionary.ItemCache()
public CachingDictionary.ItemCache(int initialCapacity,
int maxCapacity,
boolean enabled)
initialCapacity - the initial capacity of the cachemaxCapacity - the maximum capacity of the cacheenabled - whether the cache starts out enabled| Method Detail |
|---|
public boolean open()
throws java.io.IOException
IHasLifecyclefalse, then subsequent calls to
IHasLifecycle.isOpen() will return false.
open in interface IHasLifecycletrue if there were no errors in initialization;
false otherwise.
java.io.IOException - if there was IO error while performing initializataionprotected <K,V> java.util.Map<K,V> makeCache(int initialCapacity)
K - the key typeV - the value typeinitialCapacity - the initial capacity
public boolean isOpen()
IHasLifecycletrue if the dictionary is open, that is, ready to
accept queries; returns false otherwise
isOpen in interface IHasLifecycletrue if the object is open; false
otherwiseprotected void checkOpen()
ObjectClosedExceptions if the dictionary has not yet been
opened.
ObjectClosedException - if the dictionary is closed.public void close()
IClosable
close in interface IClosablepublic void clear()
ICachingDictionary.IItemCache
clear in interface ICachingDictionary.IItemCachepublic boolean isEnabled()
ICachingDictionary.IItemCachetrue if this cache is enabled;
false otherwise. If a cache is enabled, it will cache an
item passed to its cache methods.
isEnabled in interface ICachingDictionary.IItemCachetrue if this cache is enabled;
false otherwisepublic void setEnabled(boolean isEnabled)
ICachingDictionary.IItemCachetrue) or disables (false) caching.
setEnabled in interface ICachingDictionary.IItemCacheisEnabled - if true, caching is enabled; if
false, caching is disabled.public int getInitialCapacity()
public void setInitialCapacity(int capacity)
capacity - the initial capacitypublic int getMaximumCapacity()
ICachingDictionary.IItemCache
getMaximumCapacity in interface ICachingDictionary.IItemCachepublic void setMaximumCapacity(int capacity)
ICachingDictionary.IItemCache
setMaximumCapacity in interface ICachingDictionary.IItemCachecapacity - the maximum capacitypublic int size()
ICachingDictionary.IItemCache
size in interface ICachingDictionary.IItemCachepublic void cacheItem(IItem<?> item)
ICachingDictionary.IItemCache
cacheItem in interface ICachingDictionary.IItemCacheitem - the item to be cached; may not be nullpublic void cacheWordByKey(IWord word)
ICachingDictionary.IItemCache
cacheWordByKey in interface ICachingDictionary.IItemCacheword - the word to be cached; may not be nullpublic void cacheSenseEntry(ISenseEntry entry)
ICachingDictionary.IItemCache
cacheSenseEntry in interface ICachingDictionary.IItemCacheentry - the entry to be cached; may not be nullprotected void reduceCacheSize(java.util.Map<?,?> cache)
cache - the map to be trimmedpublic <T extends IItem<D>,D extends IItemID<T>> T retrieveItem(D id)
ICachingDictionary.IItemCache
retrieveItem in interface ICachingDictionary.IItemCacheT - the type of the itemD - the type of the item idid - the id for the requested item
null if not
present in the cachepublic IWord retrieveWord(ISenseKey key)
ICachingDictionary.IItemCache
retrieveWord in interface ICachingDictionary.IItemCachekey - the sense key for the requested word
null if not
present in the cachepublic ISenseEntry retrieveSenseEntry(ISenseKey key)
ICachingDictionary.IItemCache
retrieveSenseEntry in interface ICachingDictionary.IItemCachekey - the sense key for the requested sense entry
null if not
present in the cache
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||