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