can't access mbean when objectname uses a wildcard
java, jmx, objectname, regex
Solution
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")
Problem
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?