Java Doc for UtilCache.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » base » util » cache » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » ofbiz » org.ofbiz.base.util.cache 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.ofbiz.base.util.cache.UtilCache

UtilCache
public class UtilCache implements Serializable(Code)
Generalized caching utility. Provides a number of caching features:
  • Limited or unlimited element capacity
  • If limited, removes elements with the LRU (Least Recently Used) algorithm
  • Keeps track of when each element was loaded into the cache
  • Using the expireTime can report whether a given element has expired
  • Counts misses and hits


Field Summary
public  CacheLineTablecacheLineTable
     A hashtable containing a CacheLine object with a value and a loadTime for each element.
protected static  MapdefaultIndices
     An index number appended to utilCacheTable names when there are conflicts.
protected  longexpireTime
     Specifies the amount of time since initial loading before an element will be reported as expired.
protected  longhitCount
    
protected  Setlisteners
     The set of listeners to receive notifcations when items are modidfied(either delibrately or because they were expired).
protected  intmaxInMemory
    
protected  intmaxSize
     The maximum number of elements in the cache.
protected  longmissCountExpired
    
protected  longmissCountNotFound
    
protected  longmissCountSoftRef
    
final public static  Stringmodule
    
protected  Stringname
     The name of the UtilCache instance, is also the key for the instance in utilCacheTable.
protected  longremoveHitCount
    
protected  longremoveMissCount
    
protected  booleanuseFileSystemStore
    
protected  booleanuseSoftReference
    
public static  MaputilCacheTable
     A static Map to keep track of all of the UtilCache instances.

Constructor Summary
public  UtilCache(String cacheName, int maxSize, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore)
     Constructor which specifies the cacheName as well as the maxSize, expireTime and useSoftReference.
public  UtilCache(String cacheName, int maxSize, long expireTime, boolean useSoftReference)
    
public  UtilCache(String cacheName, int maxSize, long expireTime)
     Constructor which specifies the cacheName as well as the maxSize and expireTime.
public  UtilCache(int maxSize, long expireTime)
     Constructor which specifies the maxSize and expireTime.
public  UtilCache(String cacheName, boolean useSoftReference)
     This constructor takes a name for the cache, puts itself in the utilCacheTable.
public  UtilCache(String cacheName)
     This constructor takes a name for the cache, puts itself in the utilCacheTable.
public  UtilCache()
     Default constructor, all members stay at default values as defined in cache.properties, or the defaults in this file if cache.properties is not found, or there are no 'default' entries in it.

Method Summary
public  voidaddListener(CacheListener listener)
    
public synchronized  voidclear()
    
public static  voidclearAllCaches()
    
public static  voidclearCache(String cacheName)
    
public static  voidclearCachesThatStartWith(String startsWith)
    
public  voidclearCounters()
    
public  voidclearExpired()
    
public static  voidclearExpiredFromAllCaches()
    
public  booleancontainsKey(Object key)
     Returns a boolean specifying whether or not an element with the specified key is in the cache.
public  Objectget(Object key)
     Gets an element from the cache according to the specified key.
public  SetgetCacheLineKeys()
     NOTE: this returns an unmodifiable copy of the keySet, so removing from here won't have an effect, and calling a remove while iterating through the set will not cause a concurrent modification exception. This behavior is necessary for now for the persisted cache feature.
public  CollectiongetCacheLineValues()
    
public  longgetExpireTime()
    
public  longgetHitCount()
    
protected  CacheLinegetInternal(Object key, boolean countGet)
    
protected  CacheLinegetInternalNoCheck(Object key)
    
public  longgetMaxSize()
    
public  longgetMissCountExpired()
    
public  longgetMissCountNotFound()
    
public  longgetMissCountSoftRef()
    
public  longgetMissCountTotal()
    
public  StringgetName()
     Getter for the name of the UtilCache instance.
protected  StringgetNextDefaultIndex(String cacheName)
    
public static  StringgetPropertyParam(ResourceBundle res, String[] propNames, String parameter)
    
public  longgetRemoveHitCount()
    
public  longgetRemoveMissCount()
    
public  longgetSizeInBytes()
    
public  booleangetUseFileSystemStore()
    
public  booleangetUseSoftReference()
    
public  booleanhasExpired(Object key)
     Returns a boolean specifying whether or not the element corresponding to the key has expired. Only returns true if element is in cache and has expired.
protected  booleanhasExpired(CacheLine line)
    
protected  voidnoteAddition(Object key, Object newValue)
    
protected  voidnoteRemoval(Object key, Object oldValue)
    
protected  voidnoteUpdate(Object key, Object newValue, Object oldValue)
    
public synchronized  Objectput(Object key, Object value)
    
public synchronized  Objectput(Object key, Object value, long expireTime)
    
public synchronized  Objectremove(Object key)
    
protected synchronized  ObjectremoveInternal(Object key, boolean countRemove)
    
public  voidremoveListener(CacheListener listener)
    
public  voidsetExpireTime(long expireTime)
     Sets the expire time for the cache elements.
public  voidsetMaxSize(int maxSize)
     Sets the maximum number of elements in the cache.
protected  voidsetPropertiesParams(String cacheName)
    
public  voidsetPropertiesParams(String[] propNames)
    
public  voidsetUseSoftReference(boolean useSoftReference)
    
public  longsize()
    
public static  booleanvalidKey(String cacheName, Object key)
    
public  Listvalues()
    

Field Detail
cacheLineTable
public CacheLineTable cacheLineTable(Code)
A hashtable containing a CacheLine object with a value and a loadTime for each element.



defaultIndices
protected static Map defaultIndices(Code)
An index number appended to utilCacheTable names when there are conflicts.



expireTime
protected long expireTime(Code)
Specifies the amount of time since initial loading before an element will be reported as expired. If set to 0, elements will never expire.



hitCount
protected long hitCount(Code)
A count of the number of cache hits



listeners
protected Set listeners(Code)
The set of listeners to receive notifcations when items are modidfied(either delibrately or because they were expired).



maxInMemory
protected int maxInMemory(Code)



maxSize
protected int maxSize(Code)
The maximum number of elements in the cache. If set to 0, there will be no limit on the number of elements in the cache.



missCountExpired
protected long missCountExpired(Code)
A count of the number of cache misses because it expired



missCountNotFound
protected long missCountNotFound(Code)
A count of the number of cache misses because it is not found in the cache



missCountSoftRef
protected long missCountSoftRef(Code)
A count of the number of cache misses because it was cleared from the Soft Reference (ie garbage collection, etc)



module
final public static String module(Code)



name
protected String name(Code)
The name of the UtilCache instance, is also the key for the instance in utilCacheTable.



removeHitCount
protected long removeHitCount(Code)
A count of the number of cache hits on removes



removeMissCount
protected long removeMissCount(Code)
A count of the number of cache misses on removes



useFileSystemStore
protected boolean useFileSystemStore(Code)
Specifies whether or not to use file base stored for this cache, defautls to false



useSoftReference
protected boolean useSoftReference(Code)
Specifies whether or not to use soft references for this cache, defaults to false



utilCacheTable
public static Map utilCacheTable(Code)
A static Map to keep track of all of the UtilCache instances.




Constructor Detail
UtilCache
public UtilCache(String cacheName, int maxSize, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore)(Code)
Constructor which specifies the cacheName as well as the maxSize, expireTime and useSoftReference. The passed maxSize, expireTime and useSoftReference will be overridden by values from cache.properties if found.
Parameters:
  maxSize - The maxSize member is set to this value
Parameters:
  expireTime - The expireTime member is set to this value
Parameters:
  cacheName - The name of the cache.
Parameters:
  useSoftReference - Specifies whether or not to use soft references for this cache.



UtilCache
public UtilCache(String cacheName, int maxSize, long expireTime, boolean useSoftReference)(Code)



UtilCache
public UtilCache(String cacheName, int maxSize, long expireTime)(Code)
Constructor which specifies the cacheName as well as the maxSize and expireTime. The passed maxSize and expireTime will be overridden by values from cache.properties if found.
Parameters:
  maxSize - The maxSize member is set to this value
Parameters:
  expireTime - The expireTime member is set to this value
Parameters:
  cacheName - The name of the cache.



UtilCache
public UtilCache(int maxSize, long expireTime)(Code)
Constructor which specifies the maxSize and expireTime.
Parameters:
  maxSize - The maxSize member is set to this value
Parameters:
  expireTime - The expireTime member is set to this value



UtilCache
public UtilCache(String cacheName, boolean useSoftReference)(Code)
This constructor takes a name for the cache, puts itself in the utilCacheTable. It also uses the cacheName to lookup the initialization parameters from cache.properties.
Parameters:
  cacheName - The name of the cache.



UtilCache
public UtilCache(String cacheName)(Code)
This constructor takes a name for the cache, puts itself in the utilCacheTable. It also uses the cacheName to lookup the initialization parameters from cache.properties.
Parameters:
  cacheName - The name of the cache.



UtilCache
public UtilCache()(Code)
Default constructor, all members stay at default values as defined in cache.properties, or the defaults in this file if cache.properties is not found, or there are no 'default' entries in it.




Method Detail
addListener
public void addListener(CacheListener listener)(Code)
Adds an event listener for key removals



clear
public synchronized void clear()(Code)
Removes all elements from this cache



clearAllCaches
public static void clearAllCaches()(Code)
Removes all elements from this cache



clearCache
public static void clearCache(String cacheName)(Code)



clearCachesThatStartWith
public static void clearCachesThatStartWith(String startsWith)(Code)



clearCounters
public void clearCounters()(Code)
Clears the hit and miss counters



clearExpired
public void clearExpired()(Code)
Clears all expired cache entries; also clear any cache entries where the SoftReference in the CacheLine object has been cleared by the gc



clearExpiredFromAllCaches
public static void clearExpiredFromAllCaches()(Code)
Clears all expired cache entries from all caches



containsKey
public boolean containsKey(Object key)(Code)
Returns a boolean specifying whether or not an element with the specified key is in the cache. If the requested element hasExpired, it is removed before it is looked up which causes the function to return false.
Parameters:
  key - The key for the element, used to reference it in the hastables and LRU linked list True is the cache contains an element corresponding to the specified key, otherwise false



get
public Object get(Object key)(Code)
Gets an element from the cache according to the specified key. If the requested element hasExpired, it is removed before it is looked up which causes the function to return null.
Parameters:
  key - The key for the element, used to reference it in the hastables and LRU linked list The value of the element specified by the key



getCacheLineKeys
public Set getCacheLineKeys()(Code)
NOTE: this returns an unmodifiable copy of the keySet, so removing from here won't have an effect, and calling a remove while iterating through the set will not cause a concurrent modification exception. This behavior is necessary for now for the persisted cache feature.



getCacheLineValues
public Collection getCacheLineValues()(Code)



getExpireTime
public long getExpireTime()(Code)
return the current expire time for the cache elements The expire time for the cache elements



getHitCount
public long getHitCount()(Code)
Returns the number of successful hits on the cache The number of successful cache hits



getInternal
protected CacheLine getInternal(Object key, boolean countGet)(Code)



getInternalNoCheck
protected CacheLine getInternalNoCheck(Object key)(Code)



getMaxSize
public long getMaxSize()(Code)
Returns the current maximum number of elements in the cache The maximum number of elements in the cache



getMissCountExpired
public long getMissCountExpired()(Code)
Returns the number of cache misses from entries that are expired The number of cache misses



getMissCountNotFound
public long getMissCountNotFound()(Code)
Returns the number of cache misses from entries that are not found in the cache The number of cache misses



getMissCountSoftRef
public long getMissCountSoftRef()(Code)
Returns the number of cache misses from entries that are have had the soft reference cleared out (by garbage collector and such) The number of cache misses



getMissCountTotal
public long getMissCountTotal()(Code)
Returns the number of cache misses caused by any reason The number of cache misses



getName
public String getName()(Code)
Getter for the name of the UtilCache instance. The name of the instance



getNextDefaultIndex
protected String getNextDefaultIndex(String cacheName)(Code)



getPropertyParam
public static String getPropertyParam(ResourceBundle res, String[] propNames, String parameter)(Code)



getRemoveHitCount
public long getRemoveHitCount()(Code)



getRemoveMissCount
public long getRemoveMissCount()(Code)



getSizeInBytes
public long getSizeInBytes()(Code)



getUseFileSystemStore
public boolean getUseFileSystemStore()(Code)



getUseSoftReference
public boolean getUseSoftReference()(Code)
Return whether or not the cache lines should use a soft reference to the data



hasExpired
public boolean hasExpired(Object key)(Code)
Returns a boolean specifying whether or not the element corresponding to the key has expired. Only returns true if element is in cache and has expired. Error conditions return false, if no expireTable entry, returns true. Always returns false if expireTime <= 0. Also, if SoftReference in the CacheLine object has been cleared by the gc return true.
Parameters:
  key - The key for the element, used to reference it in the hastables and LRU linked list True is the element corresponding to the specified key has expired, otherwise false



hasExpired
protected boolean hasExpired(CacheLine line)(Code)



noteAddition
protected void noteAddition(Object key, Object newValue)(Code)
Send a key addition event to all registered listeners



noteRemoval
protected void noteRemoval(Object key, Object oldValue)(Code)
Send a key removal event to all registered listeners



noteUpdate
protected void noteUpdate(Object key, Object newValue, Object oldValue)(Code)
Send a key update event to all registered listeners



put
public synchronized Object put(Object key, Object value)(Code)
Puts or loads the passed element into the cache
Parameters:
  key - The key for the element, used to reference it in the hastables and LRU linked list
Parameters:
  value - The value of the element



put
public synchronized Object put(Object key, Object value, long expireTime)(Code)
Puts or loads the passed element into the cache
Parameters:
  key - The key for the element, used to reference it in the hastables and LRU linked list
Parameters:
  value - The value of the element
Parameters:
  expireTime - how long to keep this key in the cache



remove
public synchronized Object remove(Object key)(Code)
Removes an element from the cache according to the specified key
Parameters:
  key - The key for the element, used to reference it in the hastables and LRU linked list The value of the removed element specified by the key



removeInternal
protected synchronized Object removeInternal(Object key, boolean countRemove)(Code)
This is used for internal remove calls because we only want to count external calls



removeListener
public void removeListener(CacheListener listener)(Code)
Removes an event listener for key removals



setExpireTime
public void setExpireTime(long expireTime)(Code)
Sets the expire time for the cache elements. If 0, elements never expire.
Parameters:
  expireTime - The expire time for the cache elements



setMaxSize
public void setMaxSize(int maxSize)(Code)
Sets the maximum number of elements in the cache. If 0, there is no maximum.
Parameters:
  maxSize - The maximum number of elements in the cache



setPropertiesParams
protected void setPropertiesParams(String cacheName)(Code)



setPropertiesParams
public void setPropertiesParams(String[] propNames)(Code)



setUseSoftReference
public void setUseSoftReference(boolean useSoftReference)(Code)
Set whether or not the cache lines should use a soft reference to the data



size
public long size()(Code)
Returns the number of elements currently in the cache The number of elements currently in the cache



validKey
public static boolean validKey(String cacheName, Object key)(Code)
Checks for a non-expired key in a specific cache



values
public List values()(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.