Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 132   Methods: 8
NCLOC: 85   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
EvictionTimerTask.java 50% 77.8% 87.5% 75.6%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    * Created on March 25 2003
 7    */
 8    package org.jboss.cache.eviction;
 9   
 10    import org.apache.commons.logging.Log;
 11    import org.apache.commons.logging.LogFactory;
 12    import org.jboss.cache.Region;
 13   
 14    import java.util.Collections;
 15    import java.util.HashSet;
 16    import java.util.Set;
 17    import java.util.Timer;
 18    import java.util.TimerTask;
 19    import java.util.concurrent.atomic.AtomicInteger;
 20   
 21    /**
 22    * Timer threads to do periodic node clean up by running the eviction policy.
 23    *
 24    * @author Ben Wang 2-2004
 25    * @author Daniel Huang (dhuang@jboss.org)
 26    * @version $Revision: 1.15 $
 27    */
 28    public class EvictionTimerTask
 29    {
 30    private Log log = LogFactory.getLog(EvictionTimerTask.class);
 31   
 32    private final Set<Region> processedRegions;
 33    private static AtomicInteger tcount = new AtomicInteger();
 34    private int wakeupIntervalSeconds;
 35    private Timer evictionThread;
 36   
 37  2969 public EvictionTimerTask()
 38    {
 39    // synchronized set because we need to maintain thread safety
 40    // for dynamic configuration purposes.
 41  2969 processedRegions = Collections.synchronizedSet(new HashSet<Region>());
 42    }
 43   
 44  377 public void init(int wakeupIntervalSeconds)
 45    {
 46  377 if (log.isTraceEnabled())
 47  0 log.trace("Creating a new eviction listener with wakeupIntervalSeconds set at " + wakeupIntervalSeconds);
 48  377 this.wakeupIntervalSeconds = wakeupIntervalSeconds;
 49  377 start();
 50    }
 51   
 52    /**
 53    * Add a MarshRegion to process by the Eviction Thread.
 54    *
 55    * @param region MarshRegion to process.
 56    */
 57  1230 public void addRegionToProcess(Region region)
 58    {
 59  1230 processedRegions.add(region);
 60    }
 61   
 62    /**
 63    * Remove a MarshRegion to process from the Eviction thread.
 64    *
 65    * @param region
 66    */
 67  0 public void removeRegionToProcess(Region region)
 68    {
 69  0 processedRegions.remove(region);
 70    }
 71   
 72  6 public boolean isRegionRegisteredForProcessing(Region region)
 73    {
 74  6 return processedRegions.contains(region);
 75    }
 76   
 77  358 public void stop()
 78    {
 79  360 log.debug("Stopping eviction timer");
 80   
 81  368 if (evictionThread != null)
 82    {
 83  360 evictionThread.cancel();
 84    }
 85  360 evictionThread = null;
 86    }
 87   
 88  377 private void start()
 89    {
 90  377 evictionThread = new Timer("EvictionTimer-" + tcount.getAndIncrement(), true);
 91  377 TimerTask tt = new TimerTask()
 92    {
 93    /**
 94    * Run the eviction thread.
 95    * <p/>
 96    * This thread will synchronize the set of regions and iterate through every MarshRegion registered w/ the
 97    * Eviction thread. It also synchronizes on each individual region as it is being processed.
 98    */
 99  336 public void run()
 100    {
 101  336 synchronized (processedRegions)
 102    {
 103  336 for (Region region : processedRegions)
 104    {
 105  925 final EvictionPolicy policy = region.getEvictionPolicy();
 106   
 107  925 synchronized (region)
 108    {
 109  925 final EvictionAlgorithm algo = policy.getEvictionAlgorithm();
 110  925 if (algo == null)
 111  0 throw new NullPointerException("algorithm null");
 112  925 try
 113    {
 114  925 algo.process(region);
 115    }
 116    catch (EvictionException e)
 117    {
 118  0 log.error("run(): error processing eviction with exception: " + e.toString()
 119    + " will reset the eviction queue list.");
 120  0 region.resetEvictionQueues();
 121  0 log.debug("trace", e);
 122    }
 123    }
 124    }
 125    }
 126    }
 127    };
 128  377 evictionThread.schedule(tt, wakeupIntervalSeconds * 1000, wakeupIntervalSeconds * 1000);
 129    }
 130    }
 131   
 132