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
|
private static MBeanServerConnection connect() {
JMXConnector connector = null;
MBeanServerConnection connection = null;
try {
Map<String,String[]> env = new HashMap<String,String[]>();
String[] credentials = new String[] { "mon_role", "mon_mdp" };
env.put(JMXConnector.CREDENTIALS, credentials);
connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(Configuration.getProperty("activemq.jmxrmiURL")), env);
connector.connect();
connection = connector.getMBeanServerConnection();
} catch (Exception e) {
logger.log(Level.INFO, e.getMessage());
}
return connection;
}
private static void purgeQueue(String queueName) {
ObjectName brokerObjName;
try {
MBeanServerConnection connection = connect();
long start = System.currentTimeMillis();
brokerObjName = assertRegisteredObjectName("org.apache.activemq:Type=Queue,Destination=" + queueName + ",BrokerName=localhost", connection);
QueueViewMBean proxy = (QueueViewMBean)MBeanServerInvocationHandler.newProxyInstance(connection, brokerObjName, QueueViewMBean.class, true);
logger.log(Level.INFO, "[Queue Purge] Begin Queue " + queueName + " of " + proxy.getQueueSize() + " items purge ... / Memory : " + proxy.getMemoryPercentUsage());
proxy.purge();
logger.log(Level.INFO, "[Queue Purge] Queue " + queueName + " after : " + proxy.getQueueSize() + " / purge end in " + (System.currentTimeMillis() - start) + " ms ! Now memory : " + proxy.getMemoryPercentUsage());
} catch (Exception e) {
logger.log(Level.INFO, e.getMessage());
}
}
private static ObjectName assertRegisteredObjectName(String name, MBeanServerConnection connection) throws MalformedObjectNameException, NullPointerException, IOException {
ObjectName objectName = new ObjectName(name);
if (!connection.isRegistered(objectName)) {
logger.log(Level.INFO, "[JMX Bean Registration] Could not find MBean " + objectName + " - Purge cannot work !");
}
return objectName;
} |
Partager