List of usage examples for org.springframework.jmx.support MBeanServerConnectionFactoryBean destroy
@Override public void destroy() throws IOException
From source file:com.haulmont.cuba.web.jmx.JmxConnectionHelper.java
protected static <T> T withConnection(JmxInstance instance, JmxAction<T> action) { try {//w w w .j ava2s . c o m if (Objects.equals(instance.getId(), LOCAL_JMX_INSTANCE_ID)) { return action.perform(instance, getLocalConnection()); } else { MBeanServerConnectionFactoryBean factoryBean = new MBeanServerConnectionFactoryBean(); String address = instance.getAddress(); if (!address.startsWith("service:")) { address = "service:jmx:rmi:///jndi/rmi://" + address + "/jmxrmi"; } factoryBean.setServiceUrl(address); String username = instance.getLogin(); if (StringUtils.isNotEmpty(username)) { Properties properties = new Properties(); properties.put("jmx.remote.credentials", new String[] { username, instance.getPassword() }); factoryBean.setEnvironment(properties); } factoryBean.afterPropertiesSet(); MBeanServerConnection connection = factoryBean.getObject(); T result; try { result = action.perform(instance, connection); } finally { try { factoryBean.destroy(); } catch (Exception ignored) { } } return result; } } catch (Exception e) { throw new JmxControlException(e); } }