db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r572953 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
Date Wed, 05 Sep 2007 13:43:08 GMT
Author: kahatlen
Date: Wed Sep  5 06:43:07 2007
New Revision: 572953

URL: http://svn.apache.org/viewvc?rev=572953&view=rev
Log:
DERBY-2911 (partial) Implemented CacheManager.shutdown() in ConcurrentCache

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java?rev=572953&r1=572952&r2=572953&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
Wed Sep  5 06:43:07 2007
@@ -59,6 +59,15 @@
     private final String name;
 
     /**
+     * Flag that indicates whether this cache instance has been shut down. When
+     * it has been stopped, <code>find()</code>, <code>findCached()</code>
and
+     * <code>create()</code> will return <code>null</code>. The flag
is
+     * declared <code>volatile</code> so that no synchronization is needed when
+     * it is accessed by concurrent threads.
+     */
+    private volatile boolean stopped;
+
+    /**
      * Creates a new cache manager.
      *
      * @param holderFactory factory which creates <code>Cacheable</code>s
@@ -154,6 +163,11 @@
      * @return the cached object, or <code>null</code> if it cannot be found
      */
     public Cacheable find(Object key) throws StandardException {
+
+        if (stopped) {
+            return null;
+        }
+
         CacheEntry entry = getEntry(key);
         try {
             Cacheable item = entry.getCacheable();
@@ -192,6 +206,11 @@
      * @return the cached object, or <code>null</code> if it's not in the cache
      */
     public Cacheable findCached(Object key) throws StandardException {
+
+        if (stopped) {
+            return null;
+        }
+
         // We don't want to insert it if it's not there, so there's no need to
         // use getEntry().
         CacheEntry entry = cache.get(key);
@@ -228,6 +247,11 @@
      */
     public Cacheable create(Object key, Object createParameter)
             throws StandardException {
+
+        if (stopped) {
+            return null;
+        }
+
         CacheEntry entry = getEntry(key);
         try {
             if (entry.isValid()) {
@@ -358,8 +382,14 @@
         }
     }
 
+    /**
+     * Shut down the cache.
+     */
     public void shutdown() throws StandardException {
-        // TODO
+        // TODO - unsubscribe background writer
+        stopped = true;
+        cleanAll();
+        ageOut();
     }
 
     public void useDaemonService(DaemonService daemon) {



Mime
View raw message