Example usage for org.springframework.jmx.support MBeanServerConnectionFactoryBean afterPropertiesSet

List of usage examples for org.springframework.jmx.support MBeanServerConnectionFactoryBean afterPropertiesSet

Introduction

In this page you can find the example usage for org.springframework.jmx.support MBeanServerConnectionFactoryBean afterPropertiesSet.

Prototype

@Override
public void afterPropertiesSet() throws IOException 

Source Link

Document

Creates a JMXConnector for the given settings and exposes the associated MBeanServerConnection .

Usage

From source file:com.newlandframework.rpc.jmx.ThreadPoolMonitorProvider.java

public static void monitor(ThreadPoolStatus status) throws IOException, MalformedObjectNameException,
        ReflectionException, MBeanException, InstanceNotFoundException {
    MBeanServerConnectionFactoryBean mBeanServerConnectionFactoryBean = new MBeanServerConnectionFactoryBean();
    mBeanServerConnectionFactoryBean.setServiceUrl(url);
    mBeanServerConnectionFactoryBean.afterPropertiesSet();
    MBeanServerConnection connection = mBeanServerConnectionFactoryBean.getObject();
    ObjectName objectName = new ObjectName(
            "com.newlandframework.rpc.jmx:name=threadPoolStatus,type=ThreadPoolStatus");

    connection.invoke(objectName, jmxPoolSizeMethod, new Object[] { status.getPoolSize() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxActiveCountMethod, new Object[] { status.getActiveCount() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxCorePoolSizeMethod, new Object[] { status.getCorePoolSize() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxMaximumPoolSizeMethod, new Object[] { status.getMaximumPoolSize() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxLargestPoolSizeMethod, new Object[] { status.getLargestPoolSize() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxTaskCountMethod, new Object[] { status.getTaskCount() },
            new String[] { long.class.getName() });
    connection.invoke(objectName, jmxCompletedTaskCountMethod, new Object[] { status.getCompletedTaskCount() },
            new String[] { long.class.getName() });
}

From source file:com.haulmont.cuba.web.jmx.JmxConnectionHelper.java

protected static <T> T withConnection(JmxInstance instance, JmxAction<T> action) {
    try {/*from w  w  w  .jav  a2  s.  com*/
        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);
    }
}

From source file:com.dianping.cache.service.impl.ServiceMonitorServiceImpl.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private MBeanServerConnFactoryExtend createMBeanConnFactory(String clientIp) throws IOException {
    MBeanServerConnectionFactoryBean factory = new MBeanServerConnectionFactoryBean();
    String jmxHost = clientIp.contains(":") ? clientIp : clientIp + ":3397";
    factory.setServiceUrl("service:jmx:rmi:///jndi/rmi://" + jmxHost + "/HawkMBeanServer");
    factory.setConnectOnStartup(false);/*w  ww  .jav a 2s .  c  o  m*/
    Map environment = new HashMap();
    environment.put("jmx.remote.credentials", new String[] { this.jmxServerUser, this.jmxServerPasswd });
    factory.setEnvironmentMap(environment);
    factory.afterPropertiesSet();
    return new MBeanServerConnFactoryExtend(factory);
}