Skip to content

Instantly share code, notes, and snippets.

View aledsage's full-sized avatar

Aled Sage aledsage

View GitHub Profile
@aledsage
aledsage / gist:3122130
Created July 16, 2012 11:00
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());
jmxAdapter.withObjectName(myJmxObjectName)
.pollAttribute(new JmxAttributePollConfig<Map>(MY_BROOKLYN_SENSOR)
.attributeName(myJmxAttributeName)
.period(1, TimeUnit.MINUTES)
.onSuccess(JmxResponseFunctions.tabularDataToMap()));
@aledsage
aledsage / gist:3122026
Created July 16, 2012 10:31
Example brooklyn groovy code to poll an underlying resource, to update attributes (aka sensors)
// Polls a given URL, and uses the HTTP response to set the
// two Brooklyn entity attributes SERVICE_UP and REQUEST_COUNT
def http = sensorRegistry.register(
new HttpSensorAdapter("http://$host:$port/management/subsystem/web/connector/http/read-resource",
period: 200*TimeUnit.MILLISECONDS).
vars("include-runtime":true) )
with(http) {
poll(SERVICE_UP) { responseCode==200 }
@aledsage
aledsage / WebClusterDatabaseExamplePureJava.java
Created May 25, 2012 14:11
First stab at pure-java brooklyn application syntax
package brooklyn.demo;
import static brooklyn.event.basic.DependentConfiguration.valueWhenAttributeReady;
import brooklyn.entity.basic.AbstractApplication;
import brooklyn.entity.database.mysql.MySqlNode;
import brooklyn.entity.proxy.nginx.NginxController;
import brooklyn.entity.webapp.ControlledDynamicWebAppCluster;
import brooklyn.entity.webapp.DynamicWebAppCluster;
import brooklyn.entity.webapp.jboss.JBoss7Server;