...
Code Block | ||
---|---|---|
| ||
public class Example { public static void main(String[] args) throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); // Suppose the following is an object name associated with an existing managed domain instance. ObjectName objectName = ...; MBeanInfo mbeanMetadata = server.getMBeanInfo(objectName); // List all attributes (metadata, not values) for (MBeanAttributeInfo attribute : mbeanMetadata.getAttributes()) { System.out.println("Name : "+attribute.getName()); System.out.println("Description : "+attribute.getDescription()); System.out.println("Type : "+attribute.getType()); System.out.println("Is Readable : "+attribute.isReadable()); System.out.println("Is Writable : "+attribute.isWritable()); } } } |
Operations
Note |
---|
Note that all operations that are part of the Object MBean interface are not exposed directly. According to JMX API specs, the invocation of those operations needs to be done using the MBeanServer Agent. |
getAttribute
Operation Name | Description | Return Type |
---|---|---|
getAttribute | This operation allows client to retrieve value of an mbean attribute (property or statistic). | java.lang.Object |
Argument Name | Description | Type | Nullable | Note |
---|---|---|---|---|
objectName | This is the name of the target MBean. | javax.management.ObjectName | No | N.A. |
attributeName | This is the name of the requested attribute. | java.lang.String | No | N.A. |
Code Block | ||
---|---|---|
| ||
public class Example { public static void main(String[] args) throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); // Suppose that this is an object name corresponding to a valid managed domain instance. ObjectName objectName = ...; // Suppose the mbean has an attribute (a statistic in this case) PendingMessagesCount Long attributeValue = (Long) server.getAttribute(objectName, "PendingMessagesCount"); System.out.println("Attribute Value : "+attributeValue); } } |
setAttribute
Operation Name | Description | Return Type |
---|---|---|
setAttribute | This operation allows client to set the value of an mbean attribute (property). Note that it will be possible only if the attribute is writable. You can get that information on the corresponding attribute metadata. | void |
Argument Name | Description | Type | Nullable | Note |
---|---|---|---|---|
objectName | This is the name of the target MBean. | javax.management.ObjectName | No | N.A. |
attribute | This is a data transfer object representing the attribute with the its new value. | javax.management.Attribute | Yes | N.A. |
Code Block | ||
---|---|---|
| ||
public class Example
{
public static void main(String[] args) throws Exception
{
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
// Suppose that this is an object name corresponding to a valid managed domain instance.
ObjectName objectName = ...;
// Suppose we want to set a value of 30000 for "MgmtPubInterval" attribute.
Attribute attribute = new Attribute("MgmtPubInterval",new Long(3000));
server.setAttribute(objectName, attribute);
}
}
|
invoke
Operation Name | Description | Return Type |
---|---|---|
invoke | Invokes an operation on an object MBean | org.apache.qpid.management.domain.handler.impl.InvocationResult |
Argument Name | Description | Type | Nullable | Note | ||
---|---|---|---|---|---|---|
objectName | The object name of the target object MBean | javax.management.ObjectName | No | N.A. | ||
operationName | This is the operation to be invoked on the target MBean | java.lang.String | No | N.A. | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a5863757-eb2e-49d3-a153-562a6c654a8c"><ac:plain-text-body><![CDATA[ | parameters | These are the input parameters of the operation | java.lang.Object[] | No | N.A. | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f97f1d4f-9f2d-46d3-aa49-ae7df9ace455"><ac:plain-text-body><![CDATA[ | signature | The operation signature | java.lang.String [] | No | N.A. | ]]></ac:plain-text-body></ac:structured-macro> |
While mostly the interface follows the same rules of javax.management.MBeanServer.invoke() the only difference resides on return type.
The mentioned JMX interface generally returns java.lang.Object. While this is the type that the management client see, the underlying object that is returned as result of an operation invocation on QMan is ALWAYS one of the following :
- org.apache.qpid.management.domain.handler.impl.InvocationResult : This is a simple data transfer object wrapping a java.util.Map<String, Object> that contains (optional) output parameters;
- org.apache.qpid.management.domain.services.MethodInvocationException : An exception containing a status text and a status code that ndicate whether or not the method was successful and if not, what the error was.
Code Block | ||
---|---|---|
| ||
public class Example { public static void main(String[] args) throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); // Suppose that this is an object name corresponding to a valid managed domain instance. ObjectName objectName = new ObjectName("A:N=1"); // Suppose the mbean has an operation // public int purge(int request) try { String outputParameterName = "result"; String operationName = "purge"; Object [] parameters = new Object[]{1235}; String [] signature = new String[]{int.class.getName()}; InvocationResult result = (InvocationResult) server.invoke(objectName, operationName,parameters,signature); // Output parameters map Map<String,Object> outputSection = result.getOutputSection(); // Output parameter Integer outputParameter = (Integer) outputSection.get(outputParameterName); System.out.println("Output parameter : "+outputParameter); } catch (MBeanException exception) { if (exception.getTargetException() instanceof MethodInvocationException) { MethodInvocationException invocationException = (MethodInvocationException) exception.getTargetException(); System.out.println("Status Code : "+invocationException.getReturnCode()); System.out.println("Status Text : "+invocationException.getStatusText()); } } } } |
Notifications
N.A.