Created
July 16, 2012 11:00
-
-
Save aledsage/3122130 to your computer and use it in GitHub Desktop.
Proposed brooklyn Java code to poll an underlying resource, to update attributes (aka sensors)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); | |
jmxAdapter.withObjectName(myJmxObjectName) | |
.pollAttribute(new JmxAttributePollConfig<Map>(MY_BROOKLYN_SENSOR) | |
.attributeName(myJmxAttributeName) | |
.period(1, TimeUnit.MINUTES) | |
.onSuccess(JmxResponseFunctions.tabularDataToMap())); | |
// 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)); | |
httpAdapter.withSubUrl("subsystem/web/connector/http/read-resource") | |
.poll(new HttpPollConfig<String>(MY_BROOKLYN_SENSOR) | |
.onSuccess(HttpResponseFunctions.stringContentsFunction()) | |
.onError("blah blah"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment