Created
July 19, 2012 12:59
-
-
Save aledsage/3143723 to your computer and use it in GitHub Desktop.
Proposed brooklyn Java code to poll an underlying resource, to update attributes (aka sensors) - v2
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
// See v1 proposal at https://gist.github.com/3122130 | |
// | |
// This example shows use of a builder pattern to construct an immmutable JmxSensorAdapter | |
// before passing it to register(...). | |
// | |
// Most contentious issues: | |
// 1. immutability of JmxSensorAdapter | |
// 2. explicitly passing in entity(...) so can infer the jmx url from its attributes | |
// 3. use of withObjectName(...) to create a kind of sub-context so subsequent calls to pollAttribute | |
// don't need to keep repeating the object name | |
// 4. building the JmxSensorAdapter doesn't cause it to start polling; instead need to call | |
// register. Alternatives include: | |
// a. get rid of the call to register, and instead pass the registry to the builder | |
// b. pass the builder to register | |
JmxSensorAdapter.Bulder jmxBuilder = JmxSensorAdapter.builder() | |
.entity(this) | |
.period(500, TimeUnit.MILLISECONDS); | |
jmxBuilder.withObjectName("jboss.web:type=GlobalRequestProcessor,name=http-*") | |
.pollAttribute(new JmxAttributePollConfig<Integer>(ERROR_COUNT) | |
.attributeName("errorCount")) | |
.pollAttribute(new JmxAttributePollConfig<Integer>(REQUEST_COUNT) | |
.attributeName("requestCount")); | |
jmxBuilder.pollAttribute(new JmxAttributePollConfig<Integer>(SERVICE_UP) | |
.objectName("jboss.system:type=Server") | |
.attributeName("Started") | |
.period(1, TimeUnit.SECONDS) | |
.onError(Functions.constant(false)); | |
registry.register(jmxBuilder.build()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment