Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.controller.cache.result.threads.RelaxedCacheThread Class Reference

Collaboration diagram for org.objectweb.cjdbc.controller.cache.result.threads.RelaxedCacheThread:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 RelaxedCacheThread (ResultCache cache)
 RelaxedCacheThread (ResultCache cache, int refreshCacheRate)
void run ()
long getThreadWakeUpTime ()

Package Attributes

int refreshCacheRate = 60
int refreshCacheTime = 60 / refreshCacheRate

Detailed Description

This thread manages relaxed cache entries and remove them from the cache if their deadline has expired or they are dirty.

Author:
Nicolas Modrzyk
Version:
1.0

Definition at line 42 of file RelaxedCacheThread.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.cache.result.threads.RelaxedCacheThread.RelaxedCacheThread ResultCache  cache  ) 
 

Creates a new RelaxedCacheThread object

Parameters:
cache ResultCache creating this thread

Definition at line 59 of file RelaxedCacheThread.java.

00060   {
00061     super("RelaxedCacheThread");
00062     this.cache = cache;
00063   }

org.objectweb.cjdbc.controller.cache.result.threads.RelaxedCacheThread.RelaxedCacheThread ResultCache  cache,
int  refreshCacheRate
 

Creates a new RelaxedCacheThread object

Parameters:
cache ResultCache creating this thread
refreshCacheRate cache refresh rate in seconds

Definition at line 71 of file RelaxedCacheThread.java.

00072   {
00073     this(cache);
00074     this.refreshCacheRate = refreshCacheRate;
00075   }


Member Function Documentation

long org.objectweb.cjdbc.controller.cache.result.threads.RelaxedCacheThread.getThreadWakeUpTime  ) 
 

Returns the threadWakeUpTime value.

Returns:
Returns the threadWakeUpTime.

Definition at line 168 of file RelaxedCacheThread.java.

00169   {
00170     return threadWakeUpTime;
00171   }

void org.objectweb.cjdbc.controller.cache.result.threads.RelaxedCacheThread.run  ) 
 

See also:
java.lang.Runnable#run()

Definition at line 80 of file RelaxedCacheThread.java.

References org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntryRelaxed.getDeadline(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntryRelaxed.getKeepIfNotDirty(), org.objectweb.cjdbc.controller.cache.result.ResultCache.getRelaxedCache(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getRequest(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntryRelaxed.getTimeout(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.isDirty(), and org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntryRelaxed.setDeadline().

00081   {
00082     ResultCacheEntryRelaxed entry;
00083     long now;
00084     long sleep;
00085     // Keep trace of relaxed cache entries to delete
00086     ArrayList toRemoveFromRelaxedCache = new ArrayList();
00087     while (!isKilled)
00088     {
00089       synchronized (this)
00090       {
00091         try
00092         {
00093           threadWakeUpTime = 0;
00094           if (cache.getRelaxedCache().isEmpty())
00095           { // Nothing in the cache, just sleep!
00096             if (logger.isDebugEnabled())
00097               logger.debug(Translate.get("cachethread.cache.empty.sleeping"));
00098             wait();
00099           }
00100           else
00101           { // Look for first deadline
00102             now = System.currentTimeMillis();
00103             for (Iterator iter = cache.getRelaxedCache().iterator(); iter
00104                 .hasNext();)
00105             {
00106               entry = (ResultCacheEntryRelaxed) iter.next();
00107               if (entry.getDeadline() < now)
00108               { // Deadline has expired
00109                 if (entry.isDirty() || !entry.getKeepIfNotDirty())
00110                 { // Remove this entry
00111                   toRemoveFromRelaxedCache.add(entry);
00112                   continue;
00113                 }
00114                 else
00115                   // Entry is still valid, reset deadline
00116                   entry.setDeadline(now + entry.getTimeout());
00117               }
00118 
00119               // Recompute next wakeup time if needed
00120               if (threadWakeUpTime == 0
00121                   || (entry.getDeadline() < threadWakeUpTime))
00122                 threadWakeUpTime = entry.getDeadline();
00123             }
00124 
00125             // Clean up all dirty entries from the relaxed cache
00126             int size = toRemoveFromRelaxedCache.size();
00127             for (int i = 0; i < size; i++)
00128             {
00129               entry = (ResultCacheEntryRelaxed) toRemoveFromRelaxedCache.get(i);
00130               if (logger.isDebugEnabled())
00131                 logger.debug(Translate.get(
00132                     "cachethread.remove.entry.from.cache", entry.getRequest()
00133                         .getSQL()));
00134               this.cache.removeFromCache(entry.getRequest());
00135               cache.getRelaxedCache().remove(entry);
00136             }
00137             toRemoveFromRelaxedCache.clear();
00138             if (threadWakeUpTime == 0)
00139             { // All entries were dirty and not kept in the cache, therefore
00140               // there is no next deadline. (and no cache entry to wait for)
00141               continue;
00142             }
00143             else
00144             { // Sleep until the next deadline
00145               sleep = (threadWakeUpTime - now) / 1000 + refreshCacheTime;
00146               if (logger.isDebugEnabled())
00147               {
00148                 logger.debug(Translate.get("cachethread.sleeping", sleep));
00149               }
00150               sleep = (sleep) * 1000;
00151               wait(sleep);
00152             }
00153           }
00154         }
00155         catch (Exception e)
00156         {
00157           logger.warn(e.getMessage(), e);
00158         }
00159       }
00160     }
00161   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:03:38 2005 for C-JDBC by  doxygen 1.3.9.1