문제

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?

도움이 되었습니까?

해결책

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")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top