I am having an issue accessing an mbean using ObjectName expression matching. The following code successfully sets boolean b:
ObjectName objName =
new ObjectName("UnifiedSystem-search Cluster Control l-c:class=myclass");
boolean b = (boolean)myMBeanServer.invoke(objName, "areAlertsSuppressed");
The problem is that the mbeanname changes depending on coding environment. The name only changes slightly, however, which can easily be handled by the built-in expression matching that ObjectNames support. The following code (in the same environment as above) throws an InstanceNotFoundException:
ObjectName objName =
new ObjectName("UnifiedSystem-search Cluster Control *:class=myclass");
boolean b = (boolean)myMBeanServer.invoke(objName, "areAlertsSuppressed")
Any ideas how I can get the result I'm looking for?
An ObjectName is a property pattern if it is either a property list pattern or a property value pattern or both. An ObjectName is a pattern if its domain contains a wildcard or if the ObjectName is a property pattern. If an ObjectName is not a pattern, it must contain at least one key with its associated value.
An MBean server is a repository of MBeans that provides management applications access to MBeans.
Can't access mbean when objectname uses a wildcard
As far as I know, ObjectName
does not handle any wildcard patterns with the invoke
method. You are going to have to use the myMBeanServer.queryNames(...)
method to find the beans that match your pattern. Then you can call invoke
with the specific name.
Set<ObjectName> nameSet = myMBeanServer.queryNames(new ObjectName(
"UnifiedSystem-search Cluster Control *:class=myclass"), null);
// then use the first name from the set
// some error checking is needed here to make sure there is a name in the set
myMBeanServer.invoke(nameSet.iterator().next(), "areAlertsSuppressed")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With