You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ri...@apache.org on 2014/06/13 18:45:17 UTC
[4/7] git commit: Move renderer hint function to delegate interface
Move renderer hint function to delegate interface
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/a9fa54e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/a9fa54e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/a9fa54e1
Branch: refs/heads/master
Commit: a9fa54e1708131361e5dd3fcce43b88c7eddc3af
Parents: 98bb084
Author: Andrew Donald Kennedy <gr...@apache.org>
Authored: Thu Jun 12 19:07:37 2014 +0100
Committer: Andrew Donald Kennedy <gr...@apache.org>
Committed: Thu Jun 12 19:54:02 2014 +0100
----------------------------------------------------------------------
.../brooklyn/entity/basic/DelegateEntity.java | 32 ++++++++++++++++++--
.../entity/basic/DelegateEntityImpl.java | 25 ++++-----------
2 files changed, 35 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a9fa54e1/core/src/main/java/brooklyn/entity/basic/DelegateEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/DelegateEntity.java b/core/src/main/java/brooklyn/entity/basic/DelegateEntity.java
index 2f4463a..c38d8c1 100644
--- a/core/src/main/java/brooklyn/entity/basic/DelegateEntity.java
+++ b/core/src/main/java/brooklyn/entity/basic/DelegateEntity.java
@@ -1,10 +1,13 @@
package brooklyn.entity.basic;
-import brooklyn.config.ConfigKey;
+import com.google.common.base.Function;
+
+import brooklyn.config.render.RendererHints;
import brooklyn.entity.Entity;
import brooklyn.entity.Group;
import brooklyn.entity.proxying.ImplementedBy;
import brooklyn.event.AttributeSensor;
+import brooklyn.event.basic.AttributeSensorAndConfigKey;
import brooklyn.event.basic.Sensors;
/**
@@ -13,8 +16,31 @@ import brooklyn.event.basic.Sensors;
@ImplementedBy(DelegateEntityImpl.class)
public interface DelegateEntity extends Entity {
- ConfigKey<Entity> DELEGATE_ENTITY = ConfigKeys.newConfigKey(Entity.class, "delegate.entity", "The delegate entity");
+ AttributeSensorAndConfigKey<Entity, Entity> DELEGATE_ENTITY = ConfigKeys.newSensorAndConfigKey(Entity.class, "delegate.entity", "The delegate entity");
+
+ AttributeSensor<String> DELEGATE_ENTITY_LINK = Sensors.newStringSensor("webapp.url", "The delegate entity link");
+
+ public static class EntityUrl {
+
+ private static final Function<Object, String> entityUrlFunction = new Function<Object, String>() {
+ @Override
+ public String apply(Object input) {
+ if (input instanceof Entity) {
+ Entity entity = (Entity) input;
+ String url = String.format("#/v1/applications/%s/entities/%s", entity.getApplicationId(), entity.getId());
+ return url;
+ } else {
+ return null;
+ }
+ }
+ };
+
+ public static Function<Object, String> entityUrl() { return entityUrlFunction; }
- AttributeSensor<Entity> DELEGATE_ENTITY_LINK = Sensors.newSensor(Entity.class, "webapp.url", "The delegate entity link");
+ static {
+ RendererHints.register(DELEGATE_ENTITY, new RendererHints.NamedActionWithUrl("Open", entityUrl()));
+ RendererHints.register(DELEGATE_ENTITY_LINK, new RendererHints.NamedActionWithUrl("Open"));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a9fa54e1/core/src/main/java/brooklyn/entity/basic/DelegateEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/DelegateEntityImpl.java b/core/src/main/java/brooklyn/entity/basic/DelegateEntityImpl.java
index b190369..25e165e 100644
--- a/core/src/main/java/brooklyn/entity/basic/DelegateEntityImpl.java
+++ b/core/src/main/java/brooklyn/entity/basic/DelegateEntityImpl.java
@@ -1,10 +1,8 @@
package brooklyn.entity.basic;
-import brooklyn.config.render.RendererHints;
import brooklyn.enricher.Enrichers;
import brooklyn.entity.Entity;
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
public class DelegateEntityImpl extends AbstractEntity implements DelegateEntity {
@@ -13,27 +11,16 @@ public class DelegateEntityImpl extends AbstractEntity implements DelegateEntity
public void init() {
Entity delegate = getConfig(DELEGATE_ENTITY);
Preconditions.checkNotNull(delegate, "delegate");
+
+ // Propagate all sensors from the delegate entity
addEnricher(Enrichers.builder()
.propagatingAll()
.from(delegate)
.build());
- setAttribute(DELEGATE_ENTITY_LINK, delegate);
- }
- static {
- RendererHints.register(DELEGATE_ENTITY_LINK, new RendererHints.NamedActionWithUrl("Open",
- new Function<Object, String>() {
- @Override
- public String apply(Object input) {
- if (input instanceof Entity) {
- Entity entity = (Entity) input;
- String url = String.format("#/v1/applications/%s/entities/%s", entity.getApplicationId(), entity.getId());
- return url;
- } else {
- return null;
- }
- }
- }));
- }
+ // Publish the entity as an attribute for linking
+ setAttribute(DELEGATE_ENTITY, delegate);
+ setAttribute(DELEGATE_ENTITY_LINK, EntityUrl.entityUrl().apply(delegate));
+ }
}