Registry.java
991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package se.lil.jm;
import java.net.MalformedURLException;
import java.util.ArrayList;
public class Registry {
private static ArrayList<JmxMon> jmxList = null;
public static boolean test = true;
public static synchronized ArrayList<JmxMon> getList() {
if (jmxList == null) {
jmxList = new ArrayList<JmxMon>();
}
return jmxList;
}
public static synchronized JmxMon findOrCreate(String conStr) throws MalformedURLException {
for (JmxMon item : getList()) {
if(item.getConString().equals(conStr)) {
return item;
}
}
// Not found, create it
JmxMon monitor = new JmxMon(conStr);
jmxList.add(monitor);
return monitor;
}
public static synchronized void remove(String conStr) {
JmxMon mon = null;
for (JmxMon item : getList()) {
if(item.getConString().equals(conStr)) {
mon = item;
}
}
if(mon != null) {
try {
mon.close();
} catch (Throwable t) {}
getList().remove(mon);
}
}
}