public static JmxOperationPollConfig<Void> forMultiple() { return new JmxOperationPollConfig<Void>(PollConfig.NO_SENSOR); }
public static <T> JmxOperationPollConfig<T> forSensor(AttributeSensor<T> sensor) { return new JmxOperationPollConfig<T>(sensor); }
if (!config.isEnabled()) continue; @SuppressWarnings({ "rawtypes", "unchecked" }) JmxOperationPollConfig<?> configCopy = new JmxOperationPollConfig(config); if (configCopy.getPeriod() < 0) configCopy.period(builder.period, builder.periodUnits); operationPolls.put(configCopy.buildOperationIdentity(), configCopy);
@Test public void testJmxOperationPolledForSensor() throws Exception { // This is awful syntax... final int opReturnVal = 123; final AtomicInteger invocationCount = new AtomicInteger(); MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", new MBeanParameterInfo[0], Integer.class.getName(), MBeanOperationInfo.ACTION); GeneralisedDynamicMBean mbean = jmxService.registerMBean( Collections.emptyMap(), ImmutableMap.of(opInfo, new Function<Object[], Integer>() { @Override public Integer apply(Object[] args) { invocationCount.incrementAndGet(); return opReturnVal; }}), objectName); feed = JmxFeed.builder() .entity(entity) .pollOperation(new JmxOperationPollConfig<Integer>(intAttribute) .objectName(objectName) .operationName(opName)) .build(); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { assertTrue(invocationCount.get() > 0, "invocationCount="+invocationCount); assertEquals(entity.getAttribute(intAttribute), (Integer)opReturnVal); }}); }
@Test public void testJmxOperationWithArgPolledForSensor() throws Exception { // This is awful syntax... MBeanParameterInfo paramInfo = new MBeanParameterInfo("param1", String.class.getName(), "my param1"); MBeanParameterInfo[] paramInfos = new MBeanParameterInfo[] {paramInfo}; MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", paramInfos, String.class.getName(), MBeanOperationInfo.ACTION); GeneralisedDynamicMBean mbean = jmxService.registerMBean( Collections.emptyMap(), ImmutableMap.of(opInfo, new Function<Object[], String>() { @Override public String apply(Object[] args) { return args[0]+"suffix"; }}), objectName); feed = JmxFeed.builder() .entity(entity) .pollOperation(new JmxOperationPollConfig<String>(stringAttribute) .objectName(objectName) .operationName(opName) .operationParams(ImmutableList.of("myprefix"))) .build(); assertSensorEventually(stringAttribute, "myprefix"+"suffix", TIMEOUT_MS); }