Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aledsage
Created July 19, 2012 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aledsage/3143723 to your computer and use it in GitHub Desktop.
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
// 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