use of javax.management.MBeanAttributeInfo 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.MBeanAttributeInfo 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.MBeanAttributeInfo in project ats-framework by Axway.
the class SystemOperations method getJvmMbeans.
/**
* @param host the address of the host machine
* @param jmxPort the jmx port
*
* @return all MBeans with their attributes and type
* @throws SystemOperationException
*/
@PublicAtsApi
public String getJvmMbeans(String host, String jmxPort) {
JMXConnector jmxCon = null;
try {
// Connect to JMXConnector
JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
jmxCon = JMXConnectorFactory.newJMXConnector(serviceUrl, null);
jmxCon.connect();
// Access the MBean
MBeanServerConnection con = jmxCon.getMBeanServerConnection();
Set<ObjectName> queryResults = con.queryNames(null, null);
StringBuilder results = new StringBuilder();
for (ObjectName theName : queryResults) {
results.append("\n---");
results.append("\nMBean name: " + theName.getCanonicalName());
MBeanAttributeInfo[] attributes = con.getMBeanInfo(theName).getAttributes();
for (MBeanAttributeInfo attribute : attributes) {
if (attribute.getType() != null) {
if (!"javax.management.openmbean.CompositeData".equals(attribute.getType())) {
if ("java.lang.Long".equals(attribute.getType()) || "java.lang.Integer".equals(attribute.getType()) || "int".equals(attribute.getType()) || "long".equals(attribute.getType()))
results.append("\r " + attribute.getName() + " | " + attribute.getType());
} else {
results.append("\r " + attribute.getName() + " | " + attribute.getType());
CompositeData comdata = (CompositeData) con.getAttribute(theName, attribute.getName());
if (comdata != null) {
for (String key : comdata.getCompositeType().keySet()) {
Object value = comdata.get(key);
if (value instanceof Integer || value instanceof Double || value instanceof Long)
results.append("\r " + key + " | " + value.getClass());
}
}
}
}
}
}
return results.toString();
} catch (Exception e) {
throw new SystemOperationException("MBeans with their attributes cannot be get.", e);
} finally {
if (jmxCon != null)
try {
jmxCon.close();
} catch (IOException e) {
log.error("JMX connection was not closed!");
}
}
}
use of javax.management.MBeanAttributeInfo in project ats-framework by Axway.
the class MBeanWrapper method getMBeanAttribute.
/**
* Gets the value of a specific attribute of a named MBean
*
* @param objectName the object name
* @param attributeName the attribute name
* @return the attribute value
*/
Object getMBeanAttribute(ObjectName objectName, String attributeName) {
try {
for (MBeanAttributeInfo attInfo : connection.getMBeanInfo(objectName).getAttributes()) {
String attName = attInfo.getName();
if (attName.equals(attributeName)) {
return connection.getAttribute(objectName, attributeName);
}
}
} catch (Exception e) {
final String errorMsg = "Error getting the value of the '" + attributeName + "' attribute of MBean with name '" + objectName + "'";
log.error(errorMsg, e);
throw new MonitorConfigurationException(errorMsg, e);
}
final String errorMsg = "Error getting the value of the '" + attributeName + "' attribute of MBean with name '" + objectName + "': The attribute is not found!";
log.error(errorMsg);
throw new MonitorConfigurationException(errorMsg);
}
use of javax.management.MBeanAttributeInfo in project geode by apache.
the class MX4JModelMBean method removeAttributeChangeNotificationListener.
// Not in the spec but needed
private void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException {
if (listener == null)
throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString()));
AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
if (attributeName != null) {
filter.enableAttribute(attributeName);
} else {
MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes();
for (int i = 0; i < ai.length; i++) {
Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor();
filter.enableAttribute((String) d.getFieldValue("name"));
}
}
getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback);
Logger logger = getLogger();
if (logger.isEnabledFor(Logger.DEBUG))
logger.debug("Listener " + listener + " for attribute " + attributeName + " removed successfully, handback is " + handback);
}
Aggregations