/** * Converts from an object name pattern to a real object name, by querying with findMBean; * if no matching MBean can be found (or if more than one match found) then returns null. * If the supplied object name is not a pattern then just returns that. If the */ public ObjectName toLiteralObjectName(ObjectName objectName) { if (checkNotNull(objectName, "objectName").isPattern()) { ObjectInstance bean = findMBean(objectName); return (bean != null) ? bean.getObjectName() : null; } else { return objectName; } }
@Test public void testMBeanNotFoundLoggedOnlyOncePerUrl() throws Exception { ObjectName wrongObjectName = new ObjectName("DoesNotExist:type=DoesNotExist"); // Expect just one log message about: // JMX object DoesNotExist:type=DoesNotExist not found at service:jmx:rmi://localhost:1099/jndi/rmi://localhost:9001/jmxrmi" for (int i = 0; i < 10; i++) { jmxHelper.findMBean(wrongObjectName); } jmxService.shutdown(); jmxHelper.disconnect(); jmxService = newJmxServiceRetrying(LOCALHOST_NAME, 5); jmxHelper = new JmxHelper(jmxService.getUrl()); jmxHelper.connect(); // Expect just one log message about: // JMX object DoesNotExist:type=DoesNotExist not found at service:jmx:rmi://localhost:1099/jndi/rmi://localhost:9001/jmxrmi" for (int i = 0; i < 10; i++) { jmxHelper.findMBean(wrongObjectName); } }