Skip to content

Instantly share code, notes, and snippets.

Last active Oct 7, 2015
What would you like to do?
Application-author example
// Application authors write an "ApplicationBuilder"...
// The advantage is that it separates the Entity API from this builder API,
// allowing each API to be optimised for the appropriate role (i.e. top-level
// methods for the common operations so they are easy to find and use).
// e.g. aim of ApplicationBuilder is to make it easy to create + configure +
// wire together pre-existing types of entity, and to associate policies with them.
// It uses the "Recipes" of these pre-existing entity types to configure them,
// without worrying about how that implementation handles its children etc.
public class WebClusterDatabaseExamplePureJava2 extends ApplicationBuilder {
public static final String WAR_PATH = "classpath://hello-world-sql-webapp.war";
public static final String DB_USERNAME = "brooklyn";
public static final String DB_PASSWORD = "br00k11n";
// e.g. "jdbc:mysql://localhost/visitors?user=brooklyn&password=br00k11n"
public static final String DB_URL_FORMAT = "jdbc:%s/visitors?user="+DB_USERNAME+"&password="+DB_PASSWORD;
public static final String DB_SETUP_SQL = "create database visitors; blah blah;";
protected void doBuild() {
displayName("Brooklyn WebApp Cluster with Database example");
MySqlServer mysql = createEntity(MySqlServer.Recipe().newInstance()
createChild(new ControlledDynamicWebAppCluster.Recipe()
.javaOption("brooklyn.example.db.url", valueWhenAttributeReady(mysql,
MySqlNode.MYSQL_URL, PostProcessors.stringFormat(DB_URL_FORMAT))))
.sizeRange(1, 5)
.metricRange(10, 100)
// Or could use a generic recipe object if no strongly typed one exists
MySqlNode mysql2 = createChild(new BasicRecipe()
.configure(ImmutableMap.of("port", 1234)));
Copy link

ahgittin commented Jan 8, 2013

Somewhat concerned about the explosion of MyEntity, MyEntity.Recipe, MyEntityImpl (and MyEntityDriver and MyEntityDriverImpl). Really don't like the need for MyEntityBuilder when my entity has children. (Presumably you have ideas on this, just not reflected in the gists.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment