|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.bo.load; |
|
19 |
| |
|
20 |
| import java.io.IOException; |
|
21 |
| import java.util.ArrayList; |
|
22 |
| import java.util.HashMap; |
|
23 |
| import java.util.Iterator; |
|
24 |
| import java.util.List; |
|
25 |
| import java.util.Map; |
|
26 |
| |
|
27 |
| import org.qedeq.kernel.bo.module.LoadingState; |
|
28 |
| import org.qedeq.kernel.bo.module.ModuleAddress; |
|
29 |
| import org.qedeq.kernel.bo.module.ModuleProperties; |
|
30 |
| import org.qedeq.kernel.log.ModuleEventLog; |
|
31 |
| import org.qedeq.kernel.trace.Trace; |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| class Modules { |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| private final Map moduleProperties = new HashMap(); |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
0
| final ModuleProperties getModuleProperties(final String url) throws IOException {
|
|
51 |
0
| synchronized (moduleProperties) {
|
|
52 |
0
| final ModuleAddress address = new DefaultModuleAddress(url);
|
|
53 |
0
| if (moduleProperties.containsKey(address)) {
|
|
54 |
0
| return (ModuleProperties) moduleProperties.get(address);
|
|
55 |
| } else { |
|
56 |
0
| final ModuleProperties prop = new DefaultModuleProperties(address);
|
|
57 |
0
| moduleProperties.put(address, prop);
|
|
58 |
0
| return prop;
|
|
59 |
| } |
|
60 |
| } |
|
61 |
| } |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
47
| final ModuleProperties getModuleProperties(final ModuleAddress address) {
|
|
71 |
47
| synchronized (moduleProperties) {
|
|
72 |
47
| if (moduleProperties.containsKey(address)) {
|
|
73 |
30
| return (ModuleProperties) moduleProperties.get(address);
|
|
74 |
| } else { |
|
75 |
17
| final ModuleProperties prop = new DefaultModuleProperties(address);
|
|
76 |
17
| moduleProperties.put(address, prop);
|
|
77 |
17
| return prop;
|
|
78 |
| } |
|
79 |
| } |
|
80 |
| } |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
2
| final void removeAllModules() {
|
|
87 |
2
| final String method = "removeAllModules";
|
|
88 |
2
| Trace.begin(this, method);
|
|
89 |
2
| try {
|
|
90 |
2
| synchronized (moduleProperties) {
|
|
91 |
2
| for (final Iterator iterator
|
|
92 |
| = moduleProperties.entrySet().iterator(); |
|
93 |
3
| iterator.hasNext(); ) {
|
|
94 |
1
| Map.Entry entry = (Map.Entry) iterator.next();
|
|
95 |
1
| final ModuleProperties prop = (ModuleProperties) entry.getValue();
|
|
96 |
1
| Trace.trace(this, method, "remove " + prop);
|
|
97 |
1
| ModuleEventLog.getInstance().removeModule(prop);
|
|
98 |
| } |
|
99 |
2
| moduleProperties.clear();
|
|
100 |
| } |
|
101 |
| } catch (RuntimeException e) { |
|
102 |
0
| Trace.trace(this, method, e);
|
|
103 |
| } finally { |
|
104 |
2
| Trace.end(this, method);
|
|
105 |
| } |
|
106 |
| } |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
0
| final void removeModuleAndDependents(final ModuleProperties prop) {
|
|
115 |
0
| final String method = "removeModuleAndDependents";
|
|
116 |
0
| Trace.begin(this, method);
|
|
117 |
0
| try {
|
|
118 |
0
| synchronized (moduleProperties) {
|
|
119 |
0
| Trace.trace(this, method, "remove module and dependents of "
|
|
120 |
| + prop.getAddress()); |
|
121 |
0
| if (!prop.isLoaded()) {
|
|
122 |
0
| Trace.trace(this, method, "removing " + prop.getAddress());
|
|
123 |
0
| ModuleEventLog.getInstance().removeModule(prop);
|
|
124 |
0
| moduleProperties.remove(prop.getModuleAddress());
|
|
125 |
| } else { |
|
126 |
0
| Trace.trace(this, method, "module number=" + moduleProperties.size());
|
|
127 |
0
| Trace.trace(this, method, "removing module itself: " + prop.getAddress());
|
|
128 |
0
| ModuleEventLog.getInstance().removeModule(prop);
|
|
129 |
0
| moduleProperties.remove(prop.getModuleAddress());
|
|
130 |
0
| Trace.trace(this, method, "module number=" + moduleProperties.size());
|
|
131 |
| } |
|
132 |
| } |
|
133 |
| } catch (RuntimeException e) { |
|
134 |
0
| Trace.trace(this, method, e);
|
|
135 |
| } finally { |
|
136 |
0
| Trace.end(this, method);
|
|
137 |
| } |
|
138 |
| } |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
3
| final String[] getAllLoadedModules() {
|
|
146 |
3
| final String method = "getAllModules";
|
|
147 |
3
| Trace.begin(this, method);
|
|
148 |
3
| try {
|
|
149 |
3
| final List list = new ArrayList();
|
|
150 |
3
| synchronized (moduleProperties) {
|
|
151 |
3
| for (final Iterator iterator
|
|
152 |
| = moduleProperties.entrySet().iterator(); |
|
153 |
19
| iterator.hasNext(); ) {
|
|
154 |
16
| Map.Entry entry = (Map.Entry) iterator.next();
|
|
155 |
16
| final ModuleProperties prop = (ModuleProperties) entry.getValue();
|
|
156 |
16
| if (prop.getLoadingState() == LoadingState.STATE_LOADED) {
|
|
157 |
9
| list.add(prop.getAddress());
|
|
158 |
| } |
|
159 |
| } |
|
160 |
| } |
|
161 |
3
| return (String[]) list.toArray(new String[] {});
|
|
162 |
| } finally { |
|
163 |
3
| Trace.end(this, method);
|
|
164 |
| } |
|
165 |
| } |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
0
| final int getNumberOfLoadedModules() {
|
|
173 |
0
| return getAllLoadedModules().length;
|
|
174 |
| } |
|
175 |
| |
|
176 |
| } |