Search in sources :

Example 51 with DynamicMBean

use of javax.management.DynamicMBean in project controller by opendaylight.

the class DynamicWritableWrapperTest method setNumberOfThreads.

private void setNumberOfThreads(final int numberOfThreads) throws Exception {
    DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);
    proxy.setAttribute(new Attribute(THREAD_COUNT, numberOfThreads));
}
Also used : DynamicMBean(javax.management.DynamicMBean) Attribute(javax.management.Attribute)

Example 52 with DynamicMBean

use of javax.management.DynamicMBean in project controller by opendaylight.

the class DynamicWritableWrapperTest method testSetAttribute.

@Test
public void testSetAttribute() throws Exception {
    DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);
    proxy.setAttribute(new Attribute(THREAD_COUNT, newThreadCount));
    assertEquals(newThreadCount, proxy.getAttribute(THREAD_COUNT));
    assertEquals(newThreadCount, threadPoolConfigBean.getThreadCount());
    AttributeList attributeList = new AttributeList();
    attributeList.add(new Attribute(THREAD_COUNT, threadCount));
    boolean bool = true;
    attributeList.add(new Attribute(TRIGGER_NEW_INSTANCE_CREATION, bool));
    proxy.setAttributes(attributeList);
    assertEquals(threadCount, threadPoolConfigBean.getThreadCount());
    assertEquals(bool, threadPoolConfigBean.isTriggerNewInstanceCreation());
}
Also used : DynamicMBean(javax.management.DynamicMBean) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) Test(org.junit.Test)

Example 53 with DynamicMBean

use of javax.management.DynamicMBean in project tomcat70 by apache.

the class MBeanUtils method createMBean.

/**
 * Create, register, and return an MBean for this
 * <code>Group</code> object.
 *
 * @param group The Group to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Group group) throws Exception {
    String mname = createManagedName(group);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(group);
    ObjectName oname = createObjectName(domain, group);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanException(javax.management.MBeanException) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 54 with DynamicMBean

use of javax.management.DynamicMBean in project tomcat70 by apache.

the class MBeanUtils method createMBean.

/**
 * Create, register, and return an MBean for this
 * <code>Role</code> object.
 *
 * @param role The Role to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Role role) throws Exception {
    String mname = createManagedName(role);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(role);
    ObjectName oname = createObjectName(domain, role);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanException(javax.management.MBeanException) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 55 with DynamicMBean

use of javax.management.DynamicMBean in project tomcat70 by apache.

the class MBeanUtils method createMBean.

/**
 * Create, register, and return an MBean for this
 * <code>User</code> object.
 *
 * @param user The User to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(User user) throws Exception {
    String mname = createManagedName(user);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(user);
    ObjectName oname = createObjectName(domain, user);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanException(javax.management.MBeanException) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Aggregations

DynamicMBean (javax.management.DynamicMBean)78 MBeanException (javax.management.MBeanException)29 ObjectName (javax.management.ObjectName)24 MalformedObjectNameException (javax.management.MalformedObjectNameException)20 ManagedBean (org.apache.tomcat.util.modeler.ManagedBean)18 RuntimeOperationsException (javax.management.RuntimeOperationsException)16 Test (org.junit.Test)15 AttributeNotFoundException (javax.management.AttributeNotFoundException)14 InstanceNotFoundException (javax.management.InstanceNotFoundException)13 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)13 ListenerNotFoundException (javax.management.ListenerNotFoundException)13 ReflectionException (javax.management.ReflectionException)12 RuntimeErrorException (javax.management.RuntimeErrorException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Attribute (javax.management.Attribute)8 JMRuntimeException (javax.management.JMRuntimeException)7 MBeanRegistrationException (javax.management.MBeanRegistrationException)7 NamedObject (com.sun.jmx.mbeanserver.NamedObject)6 Method (java.lang.reflect.Method)6 RuntimeMBeanException (javax.management.RuntimeMBeanException)6