Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 131   Methods: 6
NCLOC: 87   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
PassivationInterceptor.java 70% 82.1% 83.3% 79.5%
coverage coverage
 1    package org.jboss.cache.interceptors;
 2   
 3    import org.jboss.cache.CacheSPI;
 4    import org.jboss.cache.Fqn;
 5    import org.jboss.cache.InvocationContext;
 6    import org.jboss.cache.NodeSPI;
 7    import org.jboss.cache.loader.CacheLoader;
 8    import org.jboss.cache.marshall.MethodCall;
 9    import org.jboss.cache.marshall.MethodDeclarations;
 10   
 11    import java.util.Collections;
 12    import java.util.HashMap;
 13    import java.util.Map;
 14    import java.util.concurrent.atomic.AtomicLong;
 15   
 16    /**
 17    * Writes evicted nodes back to the store on the way in through the
 18    * CacheLoader, either before each method call (no TXs), or at TX commit.
 19    *
 20    * @author <a href="mailto:{hmesha@novell.com}">{Hany Mesha}</a>
 21    * @version $Id: PassivationInterceptor.java,v 1.43 2007/06/28 16:53:37 msurtani Exp $
 22    */
 23    public class PassivationInterceptor extends Interceptor implements PassivationInterceptorMBean
 24    {
 25   
 26    protected CacheLoader loader = null;
 27    private AtomicLong m_passivations = new AtomicLong(0);
 28   
 29  488 public synchronized void setCache(CacheSPI cache)
 30    {
 31  488 super.setCache(cache);
 32  488 this.loader = cache.getCacheLoaderManager().getCacheLoader();
 33    }
 34   
 35    /**
 36    * Notifies the cache instance listeners that the evicted node is about to
 37    * be passivated and stores the evicted node and its attributes back to the
 38    * store using the CacheLoader.
 39    *
 40    * @return
 41    * @throws Throwable
 42    */
 43  319844 public Object invoke(InvocationContext ctx) throws Throwable
 44    {
 45  319844 MethodCall m = ctx.getMethodCall();
 46    // hmesha- We don't need to handle transaction during passivation since
 47    // passivation happens local to a node and never replicated
 48   
 49    // evict() method need to be applied to the CacheLoader before passing the call on
 50  319844 if (m.getMethodId() == MethodDeclarations.evictNodeMethodLocal_id)
 51    {
 52  1566 Object[] args = m.getArgs();
 53  1566 Fqn fqn = (Fqn) args[0];
 54  1566 try
 55    {
 56  1566 synchronized (this)
 57    {
 58    // evict method local doesn't hold attributes therefore we have
 59    // to get them manually
 60  1566 Map attributes = getNodeAttributes(fqn);
 61    // notify listeners that this node is about to be passivated
 62  1561 cache.getNotifier().notifyNodePassivated(fqn, true, attributes, ctx);
 63   
 64  1561 loader.put(fqn, attributes);
 65   
 66  1561 cache.getNotifier().notifyNodePassivated(fqn, false, Collections.emptyMap(), ctx);
 67    }
 68   
 69  1561 if (getStatisticsEnabled() && configuration.getExposeManagementStatistics())
 70    {
 71  1561 m_passivations.getAndIncrement();
 72    }
 73    }
 74    catch (NodeNotLoadedException e)
 75    {
 76  5 if (log.isTraceEnabled())
 77    {
 78  0 log.trace("Node " + fqn + " not loaded in memory; passivation skipped");
 79    }
 80    }
 81    }
 82   
 83  319844 return super.invoke(ctx);
 84    }
 85   
 86  13 public long getPassivations()
 87    {
 88  13 return m_passivations.get();
 89    }
 90   
 91  1 public void resetStatistics()
 92    {
 93  1 m_passivations.set(0);
 94    }
 95   
 96  0 public Map<String, Object> dumpStatistics()
 97    {
 98  0 Map<String, Object> retval = new HashMap<String, Object>();
 99  0 retval.put("Passivations", m_passivations.get());
 100  0 return retval;
 101    }
 102   
 103    /**
 104    * Returns attributes for a node.
 105    */
 106  1566 private Map getNodeAttributes(Fqn fqn) throws NodeNotLoadedException
 107    {
 108  1566 if (fqn == null)
 109    {
 110  0 throw new NodeNotLoadedException();
 111    }
 112  1566 NodeSPI n = cache.peek(fqn, true);
 113   
 114  1566 if (n != null)
 115    {
 116  1561 return n.getDataDirect();
 117    }
 118    else
 119    {
 120  5 throw new NodeNotLoadedException();
 121    }
 122    }
 123   
 124    private static class NodeNotLoadedException extends Exception
 125    {
 126    /**
 127    * The serialVersionUID
 128    */
 129    private static final long serialVersionUID = -4078972305344328905L;
 130    }
 131    }