Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Proposed brooklyn Java code to poll an underlying resource, to update attributes (aka sensors)
// Polls the given JMX attribute every minute; transforms the result from tabular data
// into a java.util.Map and sets the given brooklyn sensor (aka attribute) accordingly.
// The onSuccess is passed the JMX attribute's value.
JmxSensorAdapter jmxAdapter = registry.register(new JmxSensorAdapter());
.pollAttribute(new JmxAttributePollConfig<Map>(MY_BROOKLYN_SENSOR)
.period(1, TimeUnit.MINUTES)
// Polls URLs, and uses the HTTP response to set a Brooklyn entity attribute (aka sensor).
// The argument to onSuccess is a HttpPollResponse, which has things like:
// getStatusLine (which as getStatusCode, getReasonPhrase, getProtocolVersion)
// getHeaderLists (which returns Map<String,List<String>>)
// getContents (which returns byte[])
String baseUrl = "http://"+host+":"+port+"/management/";
HttpSensorAdapter httpAdapter = registry.register(new HttpSensorAdapter2(baseUrl));
.poll(new HttpPollConfig<String>(MY_BROOKLYN_SENSOR)
.onError("blah blah");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment