Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't access mbean when objectname uses a wildcard

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?

like image 684
Kreg Avatar asked Nov 16 '12 19:11

Kreg


People also ask

What is ObjectName in Java?

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.

What is MBean server?

An MBean server is a repository of MBeans that provides management applications access to MBeans.


1 Answers

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")
like image 110
Gray Avatar answered Oct 02 '22 17:10

Gray