|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
   package org.kuali.rice.core.api.config.property;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import org.apache.log4j.Logger;  | 
  |  20 |     | 
     | 
  |  21 |     | 
     | 
  |  22 |     | 
     | 
  |  23 |     | 
     | 
  |  24 |     | 
     | 
  |  25 |     | 
     | 
  |  26 |     | 
   public class ContextualConfigLock { | 
  |  27 |    0 |        private static final Logger LOG = Logger.getLogger(ContextualConfigLock.class);  | 
  |  28 |     | 
     | 
  |  29 |     | 
       private String name;  | 
  |  30 |     | 
       private boolean fired;  | 
  |  31 |    0 |        private Object lock = new Object();  | 
  |  32 |     | 
     | 
  |  33 |     | 
       public ContextualConfigLock() { | 
  |  34 |    0 |            this(null);  | 
  |  35 |    0 |        }  | 
  |  36 |     | 
     | 
  |  37 |    0 |        public ContextualConfigLock(String name) { | 
  |  38 |    0 |            if (name == null) { | 
  |  39 |    0 |                this.name = "<<anonymous>>";  | 
  |  40 |     | 
           } else { | 
  |  41 |    0 |                this.name = name;  | 
  |  42 |     | 
           }  | 
  |  43 |    0 |        }  | 
  |  44 |     | 
     | 
  |  45 |     | 
       public void await() { | 
  |  46 |    0 |            synchronized (this.lock) { | 
  |  47 |    0 |                while (!this.fired) { | 
  |  48 |     | 
                   try { | 
  |  49 |    0 |                        this.lock.wait();  | 
  |  50 |    0 |                    } catch (InterruptedException ie) { | 
  |  51 |    0 |                        LOG.warn("Interrupted while waiting for condition: " + this.name, ie); | 
  |  52 |    0 |                    }  | 
  |  53 |     | 
               }  | 
  |  54 |    0 |            }  | 
  |  55 |    0 |        }  | 
  |  56 |     | 
     | 
  |  57 |     | 
       public boolean hasFired() { | 
  |  58 |    0 |            synchronized (this.lock) { | 
  |  59 |    0 |                return this.fired;  | 
  |  60 |    0 |            }  | 
  |  61 |     | 
       }  | 
  |  62 |     | 
     | 
  |  63 |     | 
       public void fire() { | 
  |  64 |    0 |            synchronized (this.lock) { | 
  |  65 |    0 |                if (this.fired) return;  | 
  |  66 |    0 |                this.fired = true;  | 
  |  67 |    0 |                this.lock.notifyAll();  | 
  |  68 |    0 |            }  | 
  |  69 |    0 |        }  | 
  |  70 |     | 
     | 
  |  71 |     | 
       public void reset() { | 
  |  72 |    0 |            synchronized (this.lock) { | 
  |  73 |    0 |                this.fired = false;  | 
  |  74 |    0 |            }  | 
  |  75 |    0 |        }  | 
  |  76 |     | 
     | 
  |  77 |     | 
       public String toString() { | 
  |  78 |    0 |            return "[Condition: name=" + this.name + "]";  | 
  |  79 |     | 
       }  | 
  |  80 |     | 
   }  |