net.obsearch.cache
Class OBCacheLong<O>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<K,O>
              extended by net.obsearch.cache.AbstractOBCache<Long,O>
                  extended by net.obsearch.cache.OBCacheLong<O>
Type Parameters:
O - The type of object that will be stored in the Cache.
All Implemented Interfaces:
Serializable, Cloneable, Map<Long,O>

public final class OBCacheLong<O>
extends AbstractOBCache<Long,O>

By using soft references, an OB cache is implemented The garbage collector decides based on the access patterns of each reference, which elements are released and which are kept. The cache controls the loading of items. For this purpose an OBCacheLoader is provided to control the loading and instantiation of the objects from secondary storage. That is why this cache does not have a put method. It assumes that all the requested items exist in secondary storage otherwise it returns an error. Loading operations generate a lock but reading operations do not generate any locks.

Since:
0.7
Author:
Arnoldo Jose Muller Molina
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
 
Fields inherited from class net.obsearch.cache.AbstractOBCache
cacheSize
 
Constructor Summary
OBCacheLong(OBCacheHandlerLong<O> handler, int cacheSize)
          Initialize the cache with the given amount of elements.
 
Method Summary
 void clearAll()
          Makes sure the cache is cleaned and each object is stored.
 O get(long id)
          Gets the given object, returns null if the object is not found.
protected  boolean removeEldestEntry(Map.Entry<Long,O> eldest)
           
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

OBCacheLong

public OBCacheLong(OBCacheHandlerLong<O> handler,
                   int cacheSize)
            throws OBException
Initialize the cache with the given amount of elements.

Parameters:
size - Number of elements that the internal hash table will be initialized with.
Throws:
OBException
Method Detail

get

public O get(long id)
      throws OutOfRangeException,
             OBException,
             InstantiationException,
             IllegalAccessException
Gets the given object, returns null if the object is not found.

Parameters:
id - internal id.
Returns:
null if no object is found
Throws:
OutOfRangeException
OBException
InstantiationException
IllegalAccessException

removeEldestEntry

protected boolean removeEldestEntry(Map.Entry<Long,O> eldest)
Overrides:
removeEldestEntry in class LinkedHashMap<Long,O>

clearAll

public void clearAll()
              throws OBException
Description copied from class: AbstractOBCache
Makes sure the cache is cleaned and each object is stored.

Specified by:
clearAll in class AbstractOBCache<Long,O>
Throws:
OBException


Copyright © 2007-2011 Arnoldo Jose Muller Molina. All Rights Reserved.