Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 192   Methods: 16
NCLOC: 120   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Interceptor.java 62.5% 80.6% 87.5% 80%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    * Copyright 2005, JBoss Inc., and individual contributors as indicated
 4    * by the @authors tag. See the copyright.txt in the distribution for a
 5    * full listing of individual contributors.
 6    *
 7    * This is free software; you can redistribute it and/or modify it
 8    * under the terms of the GNU Lesser General Public License as
 9    * published by the Free Software Foundation; either version 2.1 of
 10    * the License, or (at your option) any later version.
 11    *
 12    * This software is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15    * Lesser General Public License for more details.
 16    *
 17    * You should have received a copy of the GNU Lesser General Public
 18    * License along with this software; if not, write to the Free
 19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21    */
 22    package org.jboss.cache.interceptors;
 23   
 24    import org.apache.commons.logging.Log;
 25    import org.apache.commons.logging.LogFactory;
 26    import org.jboss.cache.CacheSPI;
 27    import org.jboss.cache.InvocationContext;
 28    import org.jboss.cache.config.Configuration;
 29    import org.jboss.cache.marshall.MethodCall;
 30    import org.jboss.cache.marshall.MethodDeclarations;
 31   
 32    import javax.transaction.Status;
 33    import javax.transaction.SystemException;
 34    import javax.transaction.Transaction;
 35    import java.util.Collections;
 36    import java.util.Map;
 37   
 38    /**
 39    * Class representing an interceptor.
 40    * <em>Note that this will be replaced by {@link org.jboss.aop.advice.Interceptor} in one of the next releases</em>
 41    *
 42    * @author Bela Ban
 43    * @version $Id: Interceptor.java,v 1.28 2007/05/23 15:22:03 msurtani Exp $
 44    */
 45    public abstract class Interceptor implements InterceptorMBean
 46    {
 47    protected Interceptor next = null, last = null;
 48    protected CacheSPI<?, ?> cache;
 49    protected Log log = null;
 50    protected Configuration configuration;
 51    private boolean statsEnabled = false;
 52   
 53  24877 public Interceptor()
 54    {
 55  24877 log = LogFactory.getLog(getClass());
 56    }
 57   
 58  22559 public void setNext(Interceptor i)
 59    {
 60  22559 next = i;
 61    }
 62   
 63  364908 public Interceptor getNext()
 64    {
 65  364908 return next;
 66    }
 67   
 68  49174 public void setCache(CacheSPI cache)
 69    {
 70  49174 this.cache = cache;
 71  49174 this.configuration = cache.getConfiguration();
 72    }
 73   
 74  23925645 public Object invoke(InvocationContext ctx) throws Throwable
 75    {
 76  23925814 return next.invoke(ctx);
 77    }
 78   
 79  2656550 public boolean getStatisticsEnabled()
 80    {
 81  2656550 return statsEnabled;
 82    }
 83   
 84  24511 public void setStatisticsEnabled(boolean enabled)
 85    {
 86  24511 statsEnabled = enabled;
 87    }
 88   
 89  2040 public Interceptor getLast()
 90    {
 91  2040 return last;
 92    }
 93   
 94  24603 public void setLast(Interceptor last)
 95    {
 96  24603 this.last = last;
 97    }
 98   
 99    /**
 100    * This implementation returns an empty Map. If individual Interceptors wish to expose statistics, they can override this
 101    * method.
 102    */
 103  0 public Map<String, Object> dumpStatistics()
 104    {
 105  0 return Collections.emptyMap();
 106    }
 107   
 108    /**
 109    * This implementation is a no-op. If individual Interceptors wish to expose statistics, they can override this
 110    * method.
 111    */
 112  0 public void resetStatistics()
 113    {
 114    }
 115   
 116    /**
 117    * Returns true if transaction is ACTIVE, false otherwise
 118    */
 119  3781440 protected boolean isActive(Transaction tx)
 120    {
 121  0 if (tx == null) return false;
 122  3781440 int status = -1;
 123  3781440 try
 124    {
 125  3781440 status = tx.getStatus();
 126  3781440 return status == Status.STATUS_ACTIVE;
 127    }
 128    catch (SystemException e)
 129    {
 130  0 log.error("failed getting transaction status", e);
 131  0 return false;
 132    }
 133    }
 134   
 135    /**
 136    * Returns true if transaction is PREPARING, false otherwise
 137    */
 138  272486 protected boolean isPreparing(Transaction tx)
 139    {
 140  0 if (tx == null) return false;
 141  272486 int status = -1;
 142  272486 try
 143    {
 144  272486 status = tx.getStatus();
 145  272486 return status == Status.STATUS_PREPARING;
 146    }
 147    catch (SystemException e)
 148    {
 149  0 log.error("failed getting transaction status", e);
 150  0 return false;
 151    }
 152    }
 153   
 154    /**
 155    * Return s true of tx's status is ACTIVE or PREPARING
 156    *
 157    * @param tx
 158    * @return true if the tx is active or preparing
 159    */
 160  3776629 protected boolean isValid(Transaction tx)
 161    {
 162  3776628 return isActive(tx) || isPreparing(tx);
 163    }
 164   
 165    /**
 166    * This only works for prepare() and optimisticPrepare() method calls.
 167    *
 168    * @param m
 169    */
 170  1585403 protected boolean isOnePhaseCommitPrepareMehod(MethodCall m)
 171    {
 172  1585403 switch (m.getMethodId())
 173    {
 174  154609 case MethodDeclarations.prepareMethod_id:
 175  154609 return (Boolean) m.getArgs()[3];
 176  60 case MethodDeclarations.optimisticPrepareMethod_id:
 177  60 return (Boolean) m.getArgs()[4];
 178  1430734 default:
 179  1430734 return false;
 180    }
 181    }
 182   
 183  913 public String toString()
 184    {
 185  913 return getClass()
 186    + "{next: "
 187  913 + (getNext() == null ? null : getNext().getClass())
 188    + "; last: "
 189  913 + (getLast() == null ? null : getLast().getClass())
 190    + "}";
 191    }
 192    }