use of javax.management.DynamicMBean in project tomcat by apache.
the class BaseModelMBean method setAttribute.
/**
* Set the value of a specific attribute of this MBean.
*
* @param attribute The identification of the attribute to be set
* and the new value
*
* @exception AttributeNotFoundException if this attribute is not
* supported by this MBean
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking the getter
*/
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
if (log.isDebugEnabled())
log.debug("Setting attribute " + this + " " + attribute);
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
try {
((DynamicMBean) resource).setAttribute(attribute);
} catch (InvalidAttributeValueException e) {
throw new MBeanException(e);
}
return;
}
// Validate the input parameters
if (attribute == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null");
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
Object oldValue = null;
//if( getAttMap.get(name) != null )
// oldValue=getAttribute( name );
Method m = managedBean.getSetter(name, this, resource);
try {
if (m.getDeclaringClass().isAssignableFrom(this.getClass())) {
m.invoke(this, new Object[] { value });
} else {
m.invoke(resource, new Object[] { value });
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t == null)
t = e;
if (t instanceof RuntimeException)
throw new RuntimeOperationsException((RuntimeException) t, "Exception invoking method " + name);
else if (t instanceof Error)
throw new RuntimeErrorException((Error) t, "Error invoking method " + name);
else
throw new MBeanException(e, "Exception invoking method " + name);
} catch (Exception e) {
log.error("Exception invoking method " + name, e);
throw new MBeanException(e, "Exception invoking method " + name);
}
try {
sendAttributeChangeNotification(new Attribute(name, oldValue), attribute);
} catch (Exception ex) {
log.error("Error sending notification " + name, ex);
}
//attributes.put( name, value );
// if( source != null ) {
// // this mbean is associated with a source - maybe we want to persist
// source.updateField(oname, name, value);
// }
}
use of javax.management.DynamicMBean in project spring-framework by spring-projects.
the class JmxUtilsTests method testIsMBeanWithDynamicMBean.
@Test
public void testIsMBeanWithDynamicMBean() throws Exception {
DynamicMBean mbean = new TestDynamicMBean();
assertTrue("Dynamic MBean not detected correctly", JmxUtils.isMBean(mbean.getClass()));
}
use of javax.management.DynamicMBean in project aries by apache.
the class MBeanHolder method create.
static <T> MBeanHolder create(final T mbean, final ObjectName requestedObjectName) {
if (mbean instanceof DynamicMBean) {
return new MBeanHolder(mbean, requestedObjectName);
} else if (mbean == null) {
return null;
}
Class<?> mbeanClass = mbean.getClass();
// This is all in aid of getting new StandardMBean to work.
@SuppressWarnings("unchecked") Class<T> mbeanInterface = (Class<T>) getMBeanInterface(mbeanClass);
if (mbeanInterface == null) {
return null;
}
if (mbeanInterface.getName().equals(mbeanClass.getName().concat("MBean")) || mbeanInterface.getName().equals(mbeanClass.getName().concat("MXBean"))) {
return new MBeanHolder(mbean, requestedObjectName);
}
try {
StandardMBean stdMbean = new RegistrableStandardEmitterMBean(mbean, mbeanInterface);
return new MBeanHolder(stdMbean, requestedObjectName);
} catch (NotCompliantMBeanException e) {
LoggerFactory.getLogger(MBeanHolder.class).error("create: Cannot create StandardMBean for " + mbean + " of type " + mbeanClass + " for interface " + mbeanInterface, e);
return null;
}
}
use of javax.management.DynamicMBean in project ignite by apache.
the class IgniteUtils method registerMBean.
/**
* Registers MBean with the server.
*
* @param <T> Type of mbean.
* @param mbeanSrv MBean server.
* @param igniteInstanceName Ignite instance name.
* @param grp Name of the group.
* @param name Name of mbean.
* @param impl MBean implementation.
* @param itf MBean interface.
* @return JMX object name.
* @throws JMException If MBean creation failed.
*/
public static <T> ObjectName registerMBean(MBeanServer mbeanSrv, @Nullable String igniteInstanceName, @Nullable String grp, String name, T impl, @Nullable Class<T> itf) throws JMException {
assert mbeanSrv != null;
assert name != null;
assert itf != null;
DynamicMBean mbean = new IgniteStandardMXBean(impl, itf);
mbean.getMBeanInfo();
return mbeanSrv.registerMBean(mbean, makeMBeanName(igniteInstanceName, grp, name)).getObjectName();
}
use of javax.management.DynamicMBean in project ignite by apache.
the class IgniteUtils method registerCacheMBean.
/**
* Registers MBean with the server.
*
* @param <T> Type of mbean.
* @param mbeanSrv MBean server.
* @param igniteInstanceName Ignite instance name.
* @param cacheName Name of the cache.
* @param name Name of mbean.
* @param impl MBean implementation.
* @param itf MBean interface.
* @return JMX object name.
* @throws JMException If MBean creation failed.
*/
public static <T> ObjectName registerCacheMBean(MBeanServer mbeanSrv, @Nullable String igniteInstanceName, @Nullable String cacheName, String name, T impl, Class<T> itf) throws JMException {
assert mbeanSrv != null;
assert name != null;
assert itf != null;
DynamicMBean mbean = new IgniteStandardMXBean(impl, itf);
mbean.getMBeanInfo();
return mbeanSrv.registerMBean(mbean, makeCacheMBeanName(igniteInstanceName, cacheName, name)).getObjectName();
}
Aggregations