Skip to content

Instantly share code, notes, and snippets.

Avatar

Aled Sage aledsage

View GitHub Profile
@aledsage
aledsage / gist:3122130
Created Jul 16, 2012
Proposed brooklyn Java code to poll an underlying resource, to update attributes (aka sensors)
View gist:3122130
// 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 Jul 16, 2012
Example brooklyn groovy code to poll an underlying resource, to update attributes (aka sensors)
View gist:3122026
// 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
First stab at pure-java brooklyn application syntax
View WebClusterDatabaseExamplePureJava.java
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;