public static JmxOperationPollConfig<Void> forMultiple() { return new JmxOperationPollConfig<Void>(PollConfig.NO_SENSOR); }
public JmxOperationPollConfig<T> objectName(String val) { try { return objectName(new ObjectName(val)); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Invalid object name ("+val+")", e); } }
public List<?> buildOperationIdentity() { // FIXME Have a build() method for ensuring signature is set, and making class subsequently immutable? return ImmutableList.of(operationName, buildSignature(), params); }
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 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); }
long minPeriod = Integer.MAX_VALUE; final ObjectName objectName = Iterables.get(configs, 0).getObjectName(); final String operationName = Iterables.get(configs, 0).getOperationName(); final List<String> signature = Iterables.get(configs, 0).getSignature(); final List<?> params = Iterables.get(configs, 0).getParams(); if (config.getPeriod() > 0) minPeriod = Math.min(minPeriod, config.getPeriod());
@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); }}); }
public static <T> JmxOperationPollConfig<T> forSensor(AttributeSensor<T> sensor) { return new JmxOperationPollConfig<T>(sensor); }