Coverage Report - net.admin4j.util.ExpiringCacheCleanupTask
 
Classes in this File Line Coverage Branch Coverage Complexity
ExpiringCacheCleanupTask
36%
7/19
16%
1/6
2.333
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.util;
 15  
 
 16  
 
 17  
 import java.util.ArrayList;
 18  
 
 19  
 /**
 20  
  * Daemon cleaning up expired entries in registered ExpiringCache objects.
 21  
  * 
 22  
  * @author D. Ashmore
 23  
  *
 24  
  * 
 25  
  */
 26  21
 class ExpiringCacheCleanupTask implements Runnable
 27  
 {
 28  
     
 29  21
     private ArrayList<ExpiringCache> expiringCacheList = new ArrayList<ExpiringCache>();
 30  
     
 31  
     /**
 32  
      * Registers cache for periodic cleanup. 
 33  
      * @param cache
 34  
      */
 35  
     protected void registerCache(ExpiringCache cache)
 36  
     {
 37  21
         if (cache == null)  throw new IllegalArgumentException("Null cache not allowed.");
 38  21
         synchronized (this.expiringCacheList)
 39  
         {
 40  21
             this.expiringCacheList.add(cache);
 41  21
         }
 42  21
     }
 43  
     
 44  
     /* (non-Javadoc)
 45  
      * @see java.lang.Runnable#run()
 46  
      */
 47  
     public void run()
 48  
     {
 49  
         ExpiringCache cache;
 50  
         
 51  0
         synchronized (this.expiringCacheList)
 52  
         {
 53  0
             for (int i = 0; i < this.expiringCacheList.size(); i++)
 54  
             {
 55  0
                 cache = (ExpiringCache) this.expiringCacheList.get(i);
 56  0
                 cache.purgeExpiredContent();
 57  
             }
 58  0
         }
 59  0
     }
 60  
     
 61  
     /**
 62  
      * Clears all entries in all caches.  This is needed for admin and testing use.
 63  
      *
 64  
      */
 65  
     public void clearAllCacheContent()
 66  
     {
 67  
         ExpiringCache cache;
 68  
         
 69  0
         synchronized (this.expiringCacheList)
 70  
         {
 71  0
             for (int i = 0; i < this.expiringCacheList.size(); i++)
 72  
             {
 73  0
                 cache = (ExpiringCache) this.expiringCacheList.get(i);
 74  0
                 cache.clear();
 75  
             }
 76  0
         }
 77  0
     }
 78  
 }