Skip to content

Instantly share code, notes, and snippets.

Last active October 7, 2015 06:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Entity-author example
* Everyone uses this interface when dealing with MySqlNode instances.
public interface MySqlNode extends Entity, Startable {
// Note needs this generic to make sub-classing simple
public static class Recipe<T extends MySqlNode> extends SoftwareProcessEntity.Recipe<T> {
private PortRange port = PortRanges.fromString("3306, 13306+");
private String creationScriptContents;
public static Recipe<MySqlNode> newInstance() {
return new Recipe<MySqlNode>(MySqlNode.class);
public Recipe(Class<T> type) {
version("5.5.25a"); // TODO Or some better way to pass in defaults?
public Recipe port(PortRange val) {
this.port = val;
return this;
public Recipe creationScriptContents(String val) {
this.creationScriptContents = val;
return this;
// TODO There could be a reflection-based method for use by groovy that takes a map
// and then looks for the similarly named methods to call. This would allow also allow
// us to easily fail early if given invalid configuration options etc.
public static final AttributeSensor<String> MYSQL_URL = new BasicAttributeSensor<String>(String.class, "mysql.url");
public static final AttributeSensor<Integer> PORT = new BasicAttributeSensor<Integer>(Integer.class, "mysql.port");
// TODO How to relate the port attribute to the Recipe.port() config?
// In the current Brooklyn, we use PortAttributeSensorAndConfigKey which is concise+nifty.
// But could we somehow make it more obvious to the entity-author that a port is being
// chosen and being set?
* Instances of the entity are only constructed by the framework...
public class MySqlNodeImpl extends SoftwareProcessEntityImpl implements MySqlNode {
final MySqlNode.Recipe recipe;
public MySqlNodeImpl(MySqlNode.Recipe recipe) {
this.recipe = recipe;
protected void connectSensors() {
// blah, blah; code is very similar to what an entity-author would currently write
Copy link

ahgittin commented Jan 8, 2013

rather than @ImplementedBy could we have Recipe have a function which returns the type the framework should implement? then say e.g.

public Recipe() { super(MySqlNodeImpl.class) }

Copy link

ahgittin commented Jan 8, 2013

can we merge this new Recipe and the existing Factory ?
not sure i like either name though. :)

EntitySpec ? (and subclass MySqlNode.Spec)

and could resuscitate @ImplementedBy when used with default EntitySpec, i.e. EntitySpec (aka Recipe) has a method

getImplementationClass() { return implementationClassInConstructor ?: getClass().getAnnotion(ImplementedBy.class)... }


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