Cannot access mbean when objectname uses wildcard

I am having a problem accessing mbean using ObjectName expression matching. The following code successfully installs boolean b:

ObjectName objName = new ObjectName("UnifiedSystem-search Cluster Control lc:class=myclass"); boolean b = (boolean)myMBeanServer.invoke(objName, "areAlertsSuppressed"); 

The problem is that mbeanname varies depending on the encoding environment. However, the name does not change much, which is easy to do with the help of the built-in expression corresponding to ObjectNames support. The following code (in the same environment as above) raises 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?

+4
source share
1 answer

Cannot access mbean when objectname uses wildcard

As far as I know, ObjectName does not handle wildcard patterns using the invoke method. You will need to use the myMBeanServer.queryNames(...) method to find the beans that matches your template. You can then invoke with a 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") 
+13
source

Source: https://habr.com/ru/post/1446527/


All Articles