use of javax.management.modelmbean.ModelMBean in project Activiti by Activiti.
the class JobExecutorMBeanTest method testAnnotations.
@Test
public void testAnnotations() throws MalformedObjectNameException, JMException {
ModelMBean modelBean = assembler.assemble(jobExecutorMbean, new ObjectName("domain", "key", "value"));
assertNotNull(modelBean);
MBeanInfo beanInfo = modelBean.getMBeanInfo();
assertNotNull(beanInfo);
assertNotNull(beanInfo.getOperations());
assertEquals(2, beanInfo.getOperations().length);
int counter = 0;
for (MBeanOperationInfo op : beanInfo.getOperations()) {
if (op.getName().equals("setJobExecutorActivate")) {
counter++;
assertEquals("set job executor activate", op.getDescription());
assertEquals("void", op.getReturnType());
assertEquals(1, op.getSignature().length);
assertEquals("java.lang.Boolean", op.getSignature()[0].getType());
}
}
assertEquals(1, counter);
// check attributes
assertNotNull(beanInfo.getAttributes());
assertEquals(1, beanInfo.getAttributes().length);
counter = 0;
for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
if (attr.getName().equals("JobExecutorActivated")) {
counter++;
assertEquals("check if the job executor is activated", attr.getDescription());
assertEquals("boolean", attr.getType());
}
}
assertEquals(1, counter);
}
use of javax.management.modelmbean.ModelMBean in project Activiti by Activiti.
the class ProcessDefinitionsTest method testAnnotations.
@Test
public void testAnnotations() throws MalformedObjectNameException, JMException {
ModelMBean modelBean = assembler.assemble(processDefinitionsMBean, new ObjectName("domain", "key", "value"));
assertNotNull(modelBean);
MBeanInfo beanInfo = modelBean.getMBeanInfo();
assertNotNull(beanInfo);
assertNotNull(beanInfo.getOperations());
assertEquals(9, beanInfo.getOperations().length);
int counter = 0;
for (MBeanOperationInfo op : beanInfo.getOperations()) {
if (op.getName().equals("deleteDeployment")) {
counter++;
assertEquals("delete deployment", op.getDescription());
assertEquals("void", op.getReturnType());
assertEquals(1, op.getSignature().length);
assertEquals("java.lang.String", op.getSignature()[0].getType());
} else if (op.getName().equals("suspendProcessDefinitionById")) {
counter++;
assertEquals("Suspend given process ID", op.getDescription());
assertEquals("void", op.getReturnType());
assertEquals(1, op.getSignature().length);
assertEquals("java.lang.String", op.getSignature()[0].getType());
} else if (op.getName().equals("activatedProcessDefinitionById")) {
counter++;
assertEquals("Activate given process ID", op.getDescription());
assertEquals("void", op.getReturnType());
assertEquals(1, op.getSignature().length);
assertEquals("java.lang.String", op.getSignature()[0].getType());
} else if (op.getName().equals("suspendProcessDefinitionByKey")) {
counter++;
assertEquals("Suspend given process ID", op.getDescription());
assertEquals("void", op.getReturnType());
assertEquals(1, op.getSignature().length);
assertEquals("java.lang.String", op.getSignature()[0].getType());
} else if (op.getName().equals("activatedProcessDefinitionByKey")) {
counter++;
assertEquals("Activate given process ID", op.getDescription());
assertEquals("void", op.getReturnType());
assertEquals(1, op.getSignature().length);
assertEquals("java.lang.String", op.getSignature()[0].getType());
} else if (op.getName().equals("deployProcessDefinition")) {
counter++;
assertEquals("Deploy Process Definition", op.getDescription());
assertEquals("void", op.getReturnType());
assertEquals(2, op.getSignature().length);
assertEquals("java.lang.String", op.getSignature()[0].getType());
assertEquals("java.lang.String", op.getSignature()[1].getType());
}
}
assertEquals(6, counter);
// check attributes
assertNotNull(beanInfo.getAttributes());
assertEquals(2, beanInfo.getAttributes().length);
counter = 0;
for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
if (attr.getName().equals("ProcessDefinitions")) {
counter++;
assertEquals("List of Process definitions", attr.getDescription());
assertEquals("java.util.List", attr.getType());
} else if (attr.getName().equals("Deployments")) {
counter++;
assertEquals("List of deployed Processes", attr.getDescription());
assertEquals("java.util.List", attr.getType());
}
}
assertEquals(2, counter);
}
use of javax.management.modelmbean.ModelMBean in project jetty.project by eclipse.
the class ObjectMBean method mbeanFor.
/* ------------------------------------------------------------ */
/**
* Create MBean for Object. Attempts to create an MBean for the object by searching the package
* and class name space. For example an object of the type
*
* <PRE>
* class com.acme.MyClass extends com.acme.util.BaseClass implements com.acme.Iface
* </PRE>
*
* Then this method would look for the following classes:
* <UL>
* <LI>com.acme.jmx.MyClassMBean
* <LI>com.acme.util.jmx.BaseClassMBean
* <LI>org.eclipse.jetty.jmx.ObjectMBean
* </UL>
*
* @param o The object
* @return A new instance of an MBean for the object or null.
*/
public static Object mbeanFor(Object o) {
try {
Class<?> oClass = o.getClass();
Object mbean = null;
while (mbean == null && oClass != null) {
String pName = oClass.getPackage().getName();
String cName = oClass.getName().substring(pName.length() + 1);
String mName = pName + ".jmx." + cName + "MBean";
try {
Class<?> mClass;
try {
// Look for an MBean class from the same loader that loaded the original class
mClass = (Object.class.equals(oClass)) ? oClass = ObjectMBean.class : Loader.loadClass(oClass, mName);
} catch (ClassNotFoundException e) {
// Not found, so if not the same as the thread context loader, try that.
if (Thread.currentThread().getContextClassLoader() == oClass.getClassLoader())
throw e;
LOG.ignore(e);
mClass = Loader.loadClass(oClass, mName);
}
if (LOG.isDebugEnabled())
LOG.debug("ObjectMbean: mbeanFor {} mClass={}", o, mClass);
try {
Constructor<?> constructor = mClass.getConstructor(OBJ_ARG);
mbean = constructor.newInstance(new Object[] { o });
} catch (Exception e) {
LOG.ignore(e);
if (ModelMBean.class.isAssignableFrom(mClass)) {
mbean = mClass.newInstance();
((ModelMBean) mbean).setManagedResource(o, "objectReference");
}
}
if (LOG.isDebugEnabled())
LOG.debug("mbeanFor {} is {}", o, mbean);
return mbean;
} catch (ClassNotFoundException e) {
// as well as before the class name when running in JBoss.
if (e.getMessage().contains(mName))
LOG.ignore(e);
else
LOG.warn(e);
} catch (Error e) {
LOG.warn(e);
mbean = null;
} catch (Exception e) {
LOG.warn(e);
mbean = null;
}
oClass = oClass.getSuperclass();
}
} catch (Exception e) {
LOG.ignore(e);
}
return null;
}
use of javax.management.modelmbean.ModelMBean in project spring-framework by spring-projects.
the class MBeanExporter method registerBeanInstance.
/**
* Registers an existing MBean or an MBean adapter for a plain bean
* with the {@code MBeanServer}.
* @param bean the bean to register, either an MBean or a plain bean
* @param beanKey the key associated with this bean in the beans map
* @return the {@code ObjectName} under which the bean was registered
* with the {@code MBeanServer}
*/
private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException {
ObjectName objectName = getObjectName(bean, beanKey);
Object mbeanToExpose = null;
if (isMBean(bean.getClass())) {
mbeanToExpose = bean;
} else {
DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
if (adaptedBean != null) {
mbeanToExpose = adaptedBean;
}
}
if (mbeanToExpose != null) {
if (logger.isInfoEnabled()) {
logger.info("Located MBean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]");
}
doRegister(mbeanToExpose, objectName);
} else {
if (logger.isInfoEnabled()) {
logger.info("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]");
}
ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
doRegister(mbean, objectName);
injectNotificationPublisherIfNecessary(bean, mbean, objectName);
}
return objectName;
}
use of javax.management.modelmbean.ModelMBean in project voldemort by voldemort.
the class JmxUtils method createModelMBean.
/**
* Create a model mbean from an object using the description given in the
* Jmx annotation if present. Only operations are supported so far, no
* attributes, constructors, or notifications
*
* @param o The object to create an MBean for
* @return The ModelMBean for the given object
*/
public static ModelMBean createModelMBean(Object o) {
try {
ModelMBean mbean = new RequiredModelMBean();
JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class);
String description = annotation == null ? "" : annotation.description();
ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description, extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o), new ModelMBeanNotificationInfo[0]);
mbean.setModelMBeanInfo(info);
mbean.setManagedResource(o, "ObjectReference");
return mbean;
} catch (MBeanException e) {
throw new VoldemortException(e);
} catch (InvalidTargetObjectTypeException e) {
throw new VoldemortException(e);
} catch (InstanceNotFoundException e) {
throw new VoldemortException(e);
}
}
Aggregations