| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ContextualConfigLock |
|
| 1.7142857142857142;1.714 |
| 1 | /* | |
| 2 | * Copyright 2005-2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * | |
| 5 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.opensource.org/licenses/ecl2.php | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | package org.kuali.rice.core.resourceloader; | |
| 18 | ||
| 19 | import org.apache.log4j.Logger; | |
| 20 | ||
| 21 | /** | |
| 22 | * Synchronization primitive that implements a condition that can be waited upon. | |
| 23 | * | |
| 24 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 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 (lock) { |
| 47 | 0 | while (!fired) { |
| 48 | try { | |
| 49 | 0 | lock.wait(); |
| 50 | 0 | } catch (InterruptedException ie) { |
| 51 | 0 | LOG.warn("Interrupted while waiting for condition: " + name, ie); |
| 52 | 0 | } |
| 53 | } | |
| 54 | 0 | } |
| 55 | 0 | } |
| 56 | ||
| 57 | public boolean hasFired() { | |
| 58 | 0 | synchronized (lock) { |
| 59 | 0 | return fired; |
| 60 | 0 | } |
| 61 | } | |
| 62 | ||
| 63 | public void fire() { | |
| 64 | 0 | synchronized (lock) { |
| 65 | 0 | if (fired) return; |
| 66 | 0 | fired = true; |
| 67 | 0 | lock.notifyAll(); |
| 68 | 0 | } |
| 69 | 0 | } |
| 70 | ||
| 71 | public void reset() { | |
| 72 | 0 | synchronized (lock) { |
| 73 | 0 | fired = false; |
| 74 | 0 | } |
| 75 | 0 | } |
| 76 | ||
| 77 | public String toString() { | |
| 78 | 0 | return "[Condition: name=" + name + "]"; |
| 79 | } | |
| 80 | } |