@Override public Object call() throws Exception { if (log.isTraceEnabled()) log.trace("jmx attribute polling for {} sensors at {} -> {}", new Object[] {getEntity(), getJmxUri(), jmxAttributeName}); return getHelper().getAttribute(objectName, jmxAttributeName); } },
@Override public void create() { log.debug("{} adding queue {} to broker {}", new Object[] {this, getName(), jmxHelper.getAttribute(brokerMBeanName, "BrokerName")}); jmxHelper.operation(brokerMBeanName, "addQueue", getName()); connectSensors(); }
@Test public void testGetAttributeUsingObjectNameWildcard() throws Exception { GeneralisedDynamicMBean mbean = jmxService.registerMBean(MutableMap.of("myattr", "myval"), objectName); assertEquals(jmxHelper.getAttribute(jmxObjectNameWithWildcard, "myattr"), "myval"); }
@Test public void testGetAttribute() throws Exception { GeneralisedDynamicMBean mbean = jmxService.registerMBean(MutableMap.of("myattr", "myval"), objectName); assertEquals(jmxHelper.getAttribute(jmxObjectName, "myattr"), "myval"); }
@Test public void testSetAttributeUsingObjectNameWildcard() throws Exception { DynamicMBean mbean = jmxService.registerMBean(MutableMap.of("myattr", "myval"), objectName); jmxHelper.setAttribute(jmxObjectNameWithWildcard, "myattr", "abc"); Object actual = jmxHelper.getAttribute(jmxObjectName, "myattr"); assertEquals(actual, "abc"); }
@Test public void testSetAttribute() throws Exception { DynamicMBean mbean = jmxService.registerMBean(MutableMap.of("myattr", "myval"), objectName); jmxHelper.setAttribute(jmxObjectName, "myattr", "abc"); Object actual = jmxHelper.getAttribute(jmxObjectName, "myattr"); assertEquals(actual, "abc"); }
@Test public void testReconnectsOnJmxServerTemporaryFailure() throws Exception { int port = jmxService.getJmxPort(); GeneralisedDynamicMBean mbean = jmxService.registerMBean(MutableMap.of("myattr", "myval"), objectName); assertEquals(jmxHelper.getAttribute(jmxObjectName, "myattr"), "myval"); // Simulate temporary network-failure jmxService.shutdown(); // Ensure that we have a failed query while the "network is down" try { jmxHelper.getAttribute(jmxObjectName, attributeName); fail(); } catch (Exception e) { if (Throwables2.getFirstThrowableOfType(e, IOException.class) == null) { throw e; } } // Simulate the network restarting jmxService = new JmxService(LOCALHOST_NAME, port); GeneralisedDynamicMBean mbean2 = jmxService.registerMBean(MutableMap.of("myattr", "myval2"), objectName); assertEquals(jmxHelper.getAttribute(jmxObjectName, "myattr"), "myval2"); }