Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 219   Methods: 7
NCLOC: 138   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CacheStatus.java 100% 65.1% 100% 69.1%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source.
 3    * Copyright 2006, Red Hat Middleware LLC, and individual contributors
 4    * as indicated by the @author tags. See the copyright.txt file in the
 5    * distribution for a 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   
 23    package org.jboss.cache;
 24   
 25    import org.apache.commons.logging.Log;
 26    import org.apache.commons.logging.LogFactory;
 27   
 28    /**
 29    * Various states that an object that has a four stage lifecycle
 30    * (i.e. <code>create()</code>, <code>start()</code>, <code>stop()</code>
 31    * and <code>destroy()</code>) might be in.
 32    *
 33    * @author <a href="brian.stansberry@jboss.com">Brian Stansberry</a>
 34    * @version $Revision: 1.1 $
 35    */
 36    public enum CacheStatus
 37    {
 38    /**
 39    * Object has been instantiated, but create() has not been called.
 40    */
 41    INSTANTIATED,
 42    /**
 43    * The <code>create()</code> method has been called but not yet completed.
 44    */
 45    CREATING,
 46    /**
 47    * The <code>create()</code> method has been completed but
 48    * <code>start()</code> has not been called.
 49    */
 50    CREATED,
 51    /**
 52    * The <code>start()</code> method has been called but has not yet completed.
 53    */
 54    STARTING,
 55    /**
 56    * The <code>start()</code> method has completed.
 57    */
 58    STARTED,
 59    /**
 60    * The <code>stop()</code> method has been called but has not yet completed.
 61    */
 62    STOPPING,
 63    /**
 64    * The <code>stop()</code> method has completed but <code>destroy()</code>
 65    * has not yet been called. Conceptually equivalent to {@link #CREATED}.
 66    */
 67    STOPPED,
 68    /**
 69    * The <code>destroy()</code> method has been called but has not yet completed.
 70    */
 71    DESTROYING,
 72    /**
 73    * The <code>destroy()</code> method has completed.
 74    * Conceptually equivalent to {@link #INSTANTIATED}.
 75    */
 76    DESTROYED,
 77    /**
 78    * A failure occurred during the execution of <code>create()</code>,
 79    * <code>start()</code>, <code>stop()</code> or <code>destroy()</code>.
 80    * The next logical transition is to call <code>destroy()</code>.
 81    */
 82    FAILED;
 83   
 84    private static final Log log = LogFactory.getLog(CacheStatus.class);
 85   
 86  2925 public boolean createAllowed()
 87    {
 88  2925 switch(this)
 89    {
 90  0 case CREATING:
 91  17 case CREATED:
 92  0 case STARTING:
 93  16 case STARTED:
 94  0 case STOPPED:
 95  33 log.debug("Ignoring call to create() as current state is " + this);
 96    // fall through
 97  0 case FAILED:
 98  33 return false;
 99  0 case STOPPING:
 100  0 case DESTROYING:
 101  0 log.warn("Ignoring call to create() while cache is " + this);
 102  0 return false;
 103  2862 case INSTANTIATED:
 104  30 case DESTROYED:
 105  0 default:
 106  2892 return true;
 107    }
 108    }
 109   
 110  1596 public boolean needToDestroyFailedCache()
 111    {
 112  1596 if (this == CacheStatus.FAILED)
 113    {
 114  3 log.debug("need to call destroy() since current state is " +
 115    this);
 116  3 return true;
 117    }
 118   
 119  1593 return false;
 120    }
 121   
 122  2910 public boolean startAllowed()
 123    {
 124  2910 switch(this)
 125    {
 126  1517 case INSTANTIATED:
 127  17 case DESTROYED:
 128  0 case STARTING:
 129  26 case STARTED:
 130  1560 log.debug("Ignoring call to start() as current state is " + this);
 131    // fall through
 132  3 case FAILED:
 133  1563 return false;
 134  0 case STOPPING:
 135  0 case DESTROYING:
 136  0 log.warn("Ignoring call to start() as current state is " + this);
 137  0 return false;
 138  1339 case CREATED:
 139  8 case STOPPED:
 140  0 default:
 141  1347 return true;
 142    }
 143    }
 144   
 145  1563 public boolean needCreateBeforeStart()
 146    {
 147  1563 switch(this)
 148    {
 149  1517 case INSTANTIATED:
 150  20 case DESTROYED:
 151  1537 log.debug("start() called while current state is " +
 152    this + " -- call create() first");
 153  1537 return true;
 154  26 default:
 155  26 return false;
 156    }
 157    }
 158   
 159  4626 public boolean stopAllowed()
 160    {
 161  4845 switch(this)
 162    {
 163  52 case INSTANTIATED:
 164  4 case CREATED:
 165  967 case STOPPED:
 166  968 case DESTROYED:
 167  1991 log.debug("Ignoring call to stop() as current state is " + this);
 168  1960 return false;
 169  0 case CREATING:
 170  0 case STARTING:
 171  0 case STOPPING:
 172  0 case DESTROYING:
 173  0 log.warn("Ignoring call to stop() as current state is " + this);
 174  0 return false;
 175  16 case FAILED:
 176  2838 case STARTED:
 177  0 default:
 178  2854 return true;
 179    }
 180   
 181    }
 182   
 183  1517 public boolean destroyAllowed()
 184    {
 185  1517 switch(this)
 186    {
 187  28 case INSTANTIATED:
 188  29 case DESTROYED:
 189  57 log.debug("Ignoring call to destroy() as current state is " + this);
 190  57 return false;
 191  0 case CREATING:
 192  0 case STARTING:
 193  0 case STOPPING:
 194  0 case DESTROYING:
 195  0 log.warn("Ignoring call to destroy() as current state iswhile cache is " + this);
 196  0 return false;
 197  10 case STARTED:
 198    // stop first
 199  10 return false;
 200  9 case CREATED:
 201  1436 case STOPPED:
 202  5 case FAILED:
 203  0 default:
 204  1450 return true;
 205    }
 206    }
 207   
 208  67 public boolean needStopBeforeDestroy()
 209    {
 210  67 if (this == CacheStatus.STARTED)
 211    {
 212  10 log.warn("destroy() called while current state is " +
 213    this + " -- call stop() first");
 214  10 return true;
 215    }
 216   
 217  57 return false;
 218    }
 219    }