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

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

Introduction

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

Prototype

@Override
    @Nullable
    public MBeanServerConnection getObject() 

Source Link

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  ww w  . ja va 2s  . 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:org.springframework.batch.sample.launch.RemoteLauncherTests.java

private static Object getMBean(MBeanServerConnectionFactoryBean connectionFactory, String objectName,
        Class<?> interfaceType) throws MalformedObjectNameException {
    MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
    factory.setObjectName(objectName);//www.  j  a  va 2s.co  m
    factory.setProxyInterface(interfaceType);
    factory.setServer(connectionFactory.getObject());
    factory.afterPropertiesSet();
    return factory.getObject();
}