Clover coverage report -
Coverage timestamp: Sat Feb 28 2004 21:40:56 EST
file stats: LOC: 113   Methods: 7
NCLOC: 38   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
EntryUpdateState.java 50% 76.9% 100% 76.9%
coverage coverage
 1   
 /*
 2   
  * Copyright (c) 2002-2003 by OpenSymphony
 3   
  * All rights reserved.
 4   
  */
 5   
 package com.opensymphony.oscache.base;
 6   
 
 7   
 
 8   
 /**
 9   
  * Holds the state of a Cache Entry that is in the process of being (re)generated.
 10   
  * This is not synchronized; the synchronization must be handled by the calling
 11   
  * classes.
 12   
  *
 13   
  * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
 14   
  * @author Author: $
 15   
  * @version Revision: $
 16   
  */
 17   
 public class EntryUpdateState {
 18   
     /**
 19   
      * The initial state when this object is first created
 20   
      */
 21   
     public static final int NOT_YET_UPDATING = -1;
 22   
 
 23   
     /**
 24   
      * Update in progress state
 25   
      */
 26   
     public static final int UPDATE_IN_PROGRESS = 0;
 27   
 
 28   
     /**
 29   
      * Update complete state
 30   
      */
 31   
     public static final int UPDATE_COMPLETE = 1;
 32   
 
 33   
     /**
 34   
      * Update cancelled state
 35   
      */
 36   
     public static final int UPDATE_CANCELLED = 2;
 37   
 
 38   
     /**
 39   
      * Current update state
 40   
      */
 41   
     int state = NOT_YET_UPDATING;
 42   
 
 43   
     /**
 44   
      * This is the initial state when an instance this object is first created.
 45   
      * It indicates that a cache entry needs updating, but no thread has claimed
 46   
      * responsibility for updating it yet.
 47   
      */
 48  113
     public boolean isAwaitingUpdate() {
 49  113
         return state == NOT_YET_UPDATING;
 50   
     }
 51   
 
 52   
     /**
 53   
      * The thread that was responsible for updating the cache entry (ie, the thread
 54   
      * that managed to grab the update lock) has decided to give up responsibility
 55   
      * for performing the update. OSCache will notify any other threads that are
 56   
      * waiting on the update so one of them can take over the responsibility.
 57   
      */
 58  27
     public boolean isCancelled() {
 59  27
         return state == UPDATE_CANCELLED;
 60   
     }
 61   
 
 62   
     /**
 63   
      * The update of the cache entry has been completed.
 64   
      */
 65  9
     public boolean isComplete() {
 66  9
         return state == UPDATE_COMPLETE;
 67   
     }
 68   
 
 69   
     /**
 70   
      * The cache entry is currently being generated by the thread that got hold of
 71   
      * the update lock.
 72   
      */
 73  27
     public boolean isUpdating() {
 74  27
         return state == UPDATE_IN_PROGRESS;
 75   
     }
 76   
 
 77   
     /**
 78   
      * Updates the state to <code>UPDATE_CANCELLED</code>. This should <em>only<em>
 79   
      * be called by the thread that managed to get the update lock.
 80   
      */
 81  84
     public void cancelUpdate() {
 82  84
         if (state != UPDATE_IN_PROGRESS) {
 83  0
             throw new IllegalStateException("Cannot cancel cache update - current state (" + state + ") is not UPDATE_IN_PROGRESS");
 84   
         }
 85   
 
 86  84
         state = UPDATE_CANCELLED;
 87   
     }
 88   
 
 89   
     /**
 90   
      * Updates the state to <code>UPDATE_COMPLETE</code>. This should <em>only</em>
 91   
      * be called by the thread that managed to get the update lock.
 92   
      */
 93  17
     public void completeUpdate() {
 94  17
         if (state != UPDATE_IN_PROGRESS) {
 95  0
             throw new IllegalStateException("Cannot complete cache update - current state (" + state + ") is not UPDATE_IN_PROGRESS");
 96   
         }
 97   
 
 98  17
         state = UPDATE_COMPLETE;
 99   
     }
 100   
 
 101   
     /**
 102   
      * Attempt to change the state to <code>UPDATE_IN_PROGRESS</code>. Calls
 103   
      * to this method must be synchronized on the EntryUpdateState instance.
 104   
      */
 105  101
     public void startUpdate() {
 106  101
         if ((state != NOT_YET_UPDATING) && (state != UPDATE_CANCELLED)) {
 107  0
             throw new IllegalStateException("Cannot begin cache update - current state (" + state + ") is not NOT_YET_UPDATING or UPDATE_CANCELLED");
 108   
         }
 109   
 
 110  101
         state = UPDATE_IN_PROGRESS;
 111   
     }
 112   
 }
 113