-
Notifications
You must be signed in to change notification settings - Fork 2
/
CleanupMbean.java
48 lines (41 loc) · 1.62 KB
/
CleanupMbean.java
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
44
45
46
47
48
import javax.management.remote.*;
import javax.management.*;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.net.*;
import com.sun.net.httpserver.*;
public class CleanupMbean {
public static void main(String[] args) {
try {
cleanup(args[0], args[1]);
} catch (Exception e) {
e.printStackTrace();
}
}
static void cleanup(String serverName, String port) {
try {
JMXServiceURL u = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + serverName + ":" + port + "/jmxrmi");
System.out.println("URL: "+u+", connecting");
JMXConnector c = JMXConnectorFactory.connect(u);
System.out.println("Connected: " + c.getConnectionId());
MBeanServerConnection m = c.getMBeanServerConnection();
for (ObjectInstance x : m.queryMBeans(null, null)) {
System.out.println("Checking " + x.getObjectName().toString());
if (x.getObjectName().toString().startsWith("DefaultDomain:type=MLet")
||
(x.getObjectName().toString().startsWith("MLetCompromise"))
||
(x.getObjectName().toString().startsWith("MLet"))
){
System.out.println("Removing" + x.getObjectName().toString());
m.unregisterMBean(x.getObjectName());
}
}
System.out.println("Exiting after cleanup");
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
}