Java Doc for Clock.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » services » 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 » Database DBMS » db derby 10.2 » org.apache.derby.impl.services.cache 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.util.Hashtable
   org.apache.derby.impl.services.cache.Clock

Clock
final class Clock extends Hashtable implements CacheManager,Serviceable(Code)
A cache manager that uses a Hashtable and a ArrayList. The ArrayList holds CachedItem objects, each with a holder object. The Hashtable is keyed by the identity of the holder object (Cacheable.getIdentity()) and the data portion is a pointer to the CachedItem. CachedItems that have holder objects with no identity do not have entries in the hashtable.

CachedItems can in various state.

  • isValid - the entry has a valid identity
  • inCreate - the entry is being created or being faulted in from persistent store
  • inClean - the entry is being written out to persistent store
  • isKept - the entry is currently being looked at/updated, do not remove or clean it.

    Multithreading considerations:
    A clock cache manager must be MT-safe. All member variables are accessed single threaded (synchronized on this) or set once or readonly. Assumptions: holders size() and addElement must be synchronized.
    CachedItem is never passed out of the clock cache manager, only the Cacheable object is. The cachedItem is responsible for the setting and clearing of its own member fields (RESOLVE: now they are done in cache manager, need to be moved to the cachedItem). The cache manager will following the following rules while accessing a cacheditem:

    • invalid item is never returned from the cache
    • setValidState and isValid() is only called single threaded through the cache manager.
    • keep() and isKept() is only called single threaded through the cache manager once the item has been added to the holders array
    • item that isKept() won't be cleaned or removed or invalidated from the cache.
    • item that is inClean() or inCreate(), the cache manager will wait on the cachedItem to finish cleaning or creating before it returns the cached item outside of the cache.

    The cacheable must be cleaned thru the cache if it is managed by a cache. On CacheItem, a inClean state is maintain to stablelize the content of the cacheable while it is being cleaned. Only unkept items are cleaned. If an item is found to be inClean, it will wait until it exits the inClean state. If a cached item calls it own clean method without notifying the cache, it has to stablize its content for the duration of the clean.
    It is assumed that the cacheable object maintain its own MT-safeness.

    See Also:   CachedItem
    See Also:   Cacheable


Field Summary
final public  CacheStatstat
    

Constructor Summary
 Clock(CacheableFactory holderFactory, String name, int initialSize, long maximumSize, boolean useByteCount)
     Construct a new clock cache manager.

MT - not needed for constructor.
Parameters:
  holderFactory - the cacheable object class
Parameters:
  name - the name of the cache
Parameters:
  initialSize - the initial number of cachable object this cacheholds.
Parameters:
  maximumSize - the maximum size of the cache.


Method Summary
public  voidageOut()
     Age as many objects as possible out of the cache.
public  voidclean(Matchable partialKey)
     Clean all objects that match a partial key.
public  voidcleanAll()
     Clean all objects in the cache.
protected  voidcleanCache(Matchable partialKey)
     Write out all dirty buffers.
public  Cacheablecreate(Object key, Object createParameter)
     Create a new object with the said key.

MT - must be MT-safe.

public  booleandiscard(Matchable partialKey)
     Discard all objects that match the partial key.
public  Cacheablefind(Object key)
     Find the object or materialize one in the cache.
public  CacheablefindCached(Object key)
     Find an object in the cache.
protected  CachedItemfindFreeItem()
    
public synchronized  long[]getCacheStats()
     Return statistics about cache that may be implemented.
public synchronized  longgetMaximumSize()
    
public synchronized  intgetNumberInUse()
    
public  intperformWork(ContextManager contextMgr)
    
protected  intperformWork(boolean shrinkOnly)
     The background cleaner tries to make sure that there are serveral cleaned or invalied buffers ahead of the clock hand so that when they are evicted, they don't need to be cleaned. The way this routine work is as follows, starting at the current clock hand position, go forward around the cache buffers, moving the same route that the clock hand moves.
public  voidrelease(Cacheable entry)
     The caller is no longer looking at or updating the entry.
protected  voidrelease(CachedItem item)
    
public  voidremove(Cacheable entry)
     Remove an object from the cache.
protected  longremoveIdentity(CachedItem item)
     Clear an item's identity.
public  voidresetCacheStats()
     Reset the statistics to 0.
public  voidresize(long newSize)
     Change the maximum size of the cache.
protected  CachedItemrotateClock(float percentOfClock)
     Go through the list of holder objects and find a free one.

MT - must be MT-safe.

public  voidscan(Matchable filter, Operator operator)
     Perform an operation on (approximately) all entries that matches the filter, or all entries if the filter is null.
public  booleanserviceASAP()
    

MT - read only.

public  booleanserviceImmediately()
    
public  voidsetUsed(Object[] keys)
     Mark a set of entries as having been used.
protected  longshrinkSize(long currentSize)
    
public  voidshutdown()
    
public  voiduseDaemonService(DaemonService daemon)
    

Field Detail
stat
final public CacheStat stat(Code)




Constructor Detail
Clock
Clock(CacheableFactory holderFactory, String name, int initialSize, long maximumSize, boolean useByteCount)(Code)
Construct a new clock cache manager.

MT - not needed for constructor.
Parameters:
  holderFactory - the cacheable object class
Parameters:
  name - the name of the cache
Parameters:
  initialSize - the initial number of cachable object this cacheholds.
Parameters:
  maximumSize - the maximum size of the cache. The cache may growfrom initialSize to maximumSize if the cache policy notices that thereis not enough free buffers availiable. Once the cache hits maximumSizeit will not grow. If the cache is full, an exception will be thrown





Method Detail
ageOut
public void ageOut()(Code)
Age as many objects as possible out of the cache.
MT - thread safe
See Also:   CacheManager.ageOut



clean
public void clean(Matchable partialKey) throws StandardException(Code)
Clean all objects that match a partial key.



cleanAll
public void cleanAll() throws StandardException(Code)
Clean all objects in the cache.



cleanCache
protected void cleanCache(Matchable partialKey) throws StandardException(Code)
Write out all dirty buffers.

MT - must be MT safe. Single thread on the part that finds the next dirty buffer to write out, the synchronization of cleaning of the individual cachable is provided by the cacheable itself.




create
public Cacheable create(Object key, Object createParameter) throws StandardException(Code)
Create a new object with the said key.

MT - must be MT-safe. Single thread thru verifying no such item exist in cache and finding a free item, keep the item and set inCreate state. The actual creating of the object is done outside the sync block and is protected by the isKept and inCreate bits.
Parameters:
  key - the key to the object a cacheable object that is kept in the cache.
exception:
  StandardException - Cloudscape Standard error policy




discard
public boolean discard(Matchable partialKey)(Code)
Discard all objects that match the partial key.
MT - thread safe



find
public Cacheable find(Object key) throws StandardException(Code)
Find the object or materialize one in the cache. If it has not been created in the persistent store yet, return null.

MT - must be MT-safe. The cache is single threaded through finding the item in cache and finding a free item if it is not in cache, thus preventing another thread from creating the same item while is is being faulted in. (RESOLVE - this is really low performance if the cache cleaner cannot keep a steady supply of free items and we have to do an I/O while blocking the cache). If it needs to be faulted in, the inCreate bit is set. The item is kept before it exits the sync block.
If the item is in cache but in the middle of being faulted in or cleaned, it needs to wait until this is done being before returning.
The keep status prevents other threads from removing this item. The inCreate status prevents other threads from looking at or writing out this item while it is being faulted in. (RESOLVE: need to handle the case where the object is marked for removal and being waited on)
Parameters:
  key - the key to the object a cacheable object that is kept in the cache.
exception:
  StandardException - Cloudscape Standard error policy




findCached
public Cacheable findCached(Object key) throws StandardException(Code)
Find an object in the cache. Do not fault in or create the object if is is not found in the cache.

MT - must be MT-safe. The cache is single threaded through finding the item in cache. If it needs to wait for it to be faulted in or cleaned it is synchronized/waited on the cached item itself.
Parameters:
  key - the key to the object a cacheable object that is kept in the cache.




findFreeItem
protected CachedItem findFreeItem() throws StandardException(Code)



getCacheStats
public synchronized long[] getCacheStats()(Code)
Return statistics about cache that may be implemented.



getMaximumSize
public synchronized long getMaximumSize()(Code)
the current maximum size of the cache.



getNumberInUse
public synchronized int getNumberInUse()(Code)



performWork
public int performWork(ContextManager contextMgr)(Code)



performWork
protected int performWork(boolean shrinkOnly)(Code)
The background cleaner tries to make sure that there are serveral cleaned or invalied buffers ahead of the clock hand so that when they are evicted, they don't need to be cleaned. The way this routine work is as follows, starting at the current clock hand position, go forward around the cache buffers, moving the same route that the clock hand moves. It keep tracks of the number of invalid or not recently used buffers it sees along the way. If it sees a not recently used buffer, it will clean it. After it has seen N invalid or not recently used buffers, or it has gone around and visited all buffers in the cache, it finished. It does not clean recently used buffers.

MT - must be MT-safe. It takes a snapshot of the current clock hand position (a synchronous call). Getting and looking at the next serveral cached item is synchronized on this (RESOLVE: probably doesn't need to be). Cleaning of the cacheable is handle by the cacheable itself.




release
public void release(Cacheable entry)(Code)
The caller is no longer looking at or updating the entry. Since there could be more than one piece of code looking at this entry, release does not mean nobody is looking at or updating the entry, just one less. If the cacheable is marked for remove (someone is waiting to remove the persistent object once nobody is looking at it), then notify the waiter if this is the last one looking at it.
Unless there is a good reason to do otherwise, release should be used to release a cachable and not directly call cachedItem unkeep, since unkeep does not handle the case of remove.

MT - must be MT-safe. Getting and deleteing item from the hashtable is in the same synchronized block. If the cacheable object is waiting to be removed, that is synchronized thru the cachedItem itself (RESOLVE: need to move this sync block to cachedItem instead)
Parameters:
  entry - the cached entry




release
protected void release(CachedItem item)(Code)



remove
public void remove(Cacheable entry) throws StandardException(Code)
Remove an object from the cache. The item will be placed into the NoIdentity state through clean() (if required) and clearIdentity(). The removal of the object will be delayed until it is not kept by anyone. After this call the caller must throw away the reference to item.

MT - must be MT-safe. Single thread thru finding and setting the remove state of the item, the actual removal of the cacheable is synchronized on the cachedItem itself.
exception:
  StandardException - Standard Cloudscape error policy.




removeIdentity
protected long removeIdentity(CachedItem item)(Code)
Clear an item's identity. Item must be unkept and valid. This is called for dirty items from the discard code. Caller must hold the cache synchronization. the amount by which this shrinks the cache.



resetCacheStats
public void resetCacheStats()(Code)
Reset the statistics to 0.



resize
public void resize(long newSize) throws StandardException(Code)
Change the maximum size of the cache. If the size is decreased then cache entries will be thrown out.
Parameters:
  newSize - the new maximum cache size
exception:
  StandardException - Cloudscape Standard error policy



rotateClock
protected CachedItem rotateClock(float percentOfClock) throws StandardException(Code)
Go through the list of holder objects and find a free one.

MT - must be MT-safe. The moving of the clockHand and finding of an eviction candidate is synchronized. The cleaning of the cachable is handled by the cacheable itself.




scan
public void scan(Matchable filter, Operator operator)(Code)
Perform an operation on (approximately) all entries that matches the filter, or all entries if the filter is null. Entries that are added while the cache is being scanned might or might not be missed.
Parameters:
  filter -
Parameters:
  operator -



serviceASAP
public boolean serviceASAP()(Code)

MT - read only.




serviceImmediately
public boolean serviceImmediately()(Code)



setUsed
public void setUsed(Object[] keys)(Code)
Mark a set of entries as having been used. Normally this is done as a side effect of find() or findCached. Entries that are no longer in the cache are ignored.
Parameters:
  keys - the key of the used entry.



shrinkSize
protected long shrinkSize(long currentSize)(Code)



shutdown
public void shutdown() throws StandardException(Code)
MT - synchronization provided by caller
exception:
  StandardException - Standard Cloudscape error policy.



useDaemonService
public void useDaemonService(DaemonService daemon)(Code)
MT - synchronization provided by caller can use this Daemomn service if needed



Methods inherited from java.util.Hashtable
public synchronized void clear()(Code)(Java Doc)
public synchronized Object clone()(Code)(Java Doc)
public synchronized boolean contains(Object value)(Code)(Java Doc)
public synchronized boolean containsKey(Object key)(Code)(Java Doc)
public boolean containsValue(Object value)(Code)(Java Doc)
public synchronized Enumeration<V> elements()(Code)(Java Doc)
public Set<Map.Entry<K, V>> entrySet()(Code)(Java Doc)
public synchronized boolean equals(Object o)(Code)(Java Doc)
public synchronized V get(Object key)(Code)(Java Doc)
public synchronized int hashCode()(Code)(Java Doc)
public synchronized boolean isEmpty()(Code)(Java Doc)
public Set<K> keySet()(Code)(Java Doc)
public synchronized Enumeration<K> keys()(Code)(Java Doc)
public synchronized V put(K key, V value)(Code)(Java Doc)
public synchronized void putAll(Map<? extends K, ? extends V> t)(Code)(Java Doc)
protected void rehash()(Code)(Java Doc)
public synchronized V remove(Object key)(Code)(Java Doc)
public synchronized int size()(Code)(Java Doc)
public synchronized String toString()(Code)(Java Doc)
public Collection<V> values()(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.