Skip to content

Commit 032e15e

Browse files
committed
basic service builder cache thread-safe instance
1 parent bd0ac95 commit 032e15e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package fr.adrienbrault.idea.symfony2plugin.stubs.cache;
2+
3+
import fr.adrienbrault.idea.symfony2plugin.dic.ContainerService;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
public class ServiceBuilderTimeCache {
8+
9+
private boolean isInit = false;
10+
private Boolean inWrite = false;
11+
private Map<String, ContainerService> containerMap = new HashMap<String, ContainerService>();
12+
private final Object lock = new Object();
13+
14+
synchronized public boolean isInitAndStart() {
15+
16+
if(this.isInit) {
17+
return true;
18+
}
19+
20+
this.isInit = true;
21+
22+
return false;
23+
}
24+
25+
public void startWrite() {
26+
this.inWrite = true;
27+
}
28+
29+
public void endWrite(Map<String, ContainerService> foo) {
30+
synchronized(lock){
31+
containerMap.putAll(foo);
32+
inWrite = false;
33+
lock.notify();
34+
}
35+
}
36+
37+
public Map<String, ContainerService> getContainerMap() {
38+
synchronized(lock){
39+
while (inWrite) {
40+
try {
41+
lock.wait();
42+
} catch (InterruptedException e) {
43+
return this.containerMap;
44+
}
45+
}
46+
}
47+
return this.containerMap;
48+
}
49+
50+
}

0 commit comments

Comments
 (0)