brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [25/50] brooklyn-server git commit: Adds Identifiable interface
Date Mon, 01 Feb 2016 17:49:29 GMT
Adds Identifiable interface

- implemented by Entity, Location and EntityAdjunct


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/ab357177
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/ab357177
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/ab357177

Branch: refs/heads/0.6.0
Commit: ab357177bfd72287d6d01c14d834c08537936e77
Parents: 8aa09c5
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Nov 12 21:46:07 2013 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Nov 12 21:53:17 2013 +0000

----------------------------------------------------------------------
 api/src/main/java/brooklyn/entity/Entity.java   |  4 +++-
 .../main/java/brooklyn/location/Location.java   |  4 +++-
 .../java/brooklyn/policy/EntityAdjunct.java     |  5 +++-
 .../rebind/persister/XmlMementoSerializer.java  | 25 ++++++--------------
 4 files changed, 17 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab357177/api/src/main/java/brooklyn/entity/Entity.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/entity/Entity.java b/api/src/main/java/brooklyn/entity/Entity.java
index 9890e64..845be09 100644
--- a/api/src/main/java/brooklyn/entity/Entity.java
+++ b/api/src/main/java/brooklyn/entity/Entity.java
@@ -10,6 +10,7 @@ import brooklyn.config.ConfigKey.HasConfigKey;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.rebind.RebindSupport;
 import brooklyn.entity.rebind.Rebindable;
+import brooklyn.entity.trait.Identifiable;
 import brooklyn.event.AttributeSensor;
 import brooklyn.location.Location;
 import brooklyn.management.Task;
@@ -30,10 +31,11 @@ import brooklyn.policy.Policy;
  * 
  * @see brooklyn.entity.basic.AbstractEntity
  */
-public interface Entity extends Rebindable {
+public interface Entity extends Identifiable, Rebindable {
     /**
      * The unique identifier for this entity.
      */
+    @Override
     String getId();
     
     /**

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab357177/api/src/main/java/brooklyn/location/Location.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/location/Location.java b/api/src/main/java/brooklyn/location/Location.java
index 65bf193..0b2da15 100644
--- a/api/src/main/java/brooklyn/location/Location.java
+++ b/api/src/main/java/brooklyn/location/Location.java
@@ -7,6 +7,7 @@ import java.util.Map;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.rebind.RebindSupport;
 import brooklyn.entity.rebind.Rebindable;
+import brooklyn.entity.trait.Identifiable;
 import brooklyn.mementos.LocationMemento;
 
 /**
@@ -17,11 +18,12 @@ import brooklyn.mementos.LocationMemento;
  * 
  * Locations may not be {@link Serializable} in subsequent releases!
  */
-public interface Location extends Serializable, Rebindable{
+public interface Location extends Serializable, Identifiable, Rebindable {
 
     /**
      * A unique id for this location.
      */
+    @Override
     String getId();
 
     /**

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab357177/api/src/main/java/brooklyn/policy/EntityAdjunct.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/policy/EntityAdjunct.java b/api/src/main/java/brooklyn/policy/EntityAdjunct.java
index 0671fde..3368e40 100644
--- a/api/src/main/java/brooklyn/policy/EntityAdjunct.java
+++ b/api/src/main/java/brooklyn/policy/EntityAdjunct.java
@@ -1,13 +1,16 @@
 package brooklyn.policy;
 
+import brooklyn.entity.trait.Identifiable;
+
 /**
  * EntityAdjuncts are supplementary logic that can be attached to Entities, providing sensor
enrichment
  * or enabling policy
  */
-public interface EntityAdjunct {
+public interface EntityAdjunct extends Identifiable {
     /**
      * A unique id for this adjunct
      */
+    @Override
     String getId();
 
     /**

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab357177/core/src/main/java/brooklyn/entity/rebind/persister/XmlMementoSerializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/XmlMementoSerializer.java
b/core/src/main/java/brooklyn/entity/rebind/persister/XmlMementoSerializer.java
index 68d8ae1..62a2fc4 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/XmlMementoSerializer.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/XmlMementoSerializer.java
@@ -13,6 +13,7 @@ import brooklyn.entity.Entity;
 import brooklyn.entity.rebind.dto.BasicEntityMemento;
 import brooklyn.entity.rebind.dto.BasicLocationMemento;
 import brooklyn.entity.rebind.dto.MutableBrooklynMemento;
+import brooklyn.entity.trait.Identifiable;
 import brooklyn.event.basic.BasicAttributeSensor;
 import brooklyn.event.basic.BasicConfigKey;
 import brooklyn.location.Location;
@@ -20,7 +21,6 @@ import brooklyn.policy.EntityAdjunct;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.xstream.XmlSerializer;
 
-import com.google.common.base.Function;
 import com.thoughtworks.xstream.converters.Converter;
 import com.thoughtworks.xstream.converters.MarshallingContext;
 import com.thoughtworks.xstream.converters.UnmarshallingContext;
@@ -46,18 +46,9 @@ public class XmlMementoSerializer<T> extends XmlSerializer<T>
implements Memento
         xstream.alias("location", BasicLocationMemento.class);
         xstream.alias("configKey", BasicConfigKey.class);
         xstream.alias("attributeSensor", BasicAttributeSensor.class);
-        xstream.registerConverter(new ConverterImpl(Location.class, new Function<Location,String>()
{
-            @Override public String apply(Location input) {
-                return (input != null) ? input.getId() : null;
-            }}));
-        xstream.registerConverter(new ConverterImpl(Entity.class, new Function<Entity,String>()
{
-            @Override public String apply(Entity input) {
-                return (input != null) ? input.getId() : null;
-            }}));
-        xstream.registerConverter(new ConverterImpl(EntityAdjunct.class, new Function<EntityAdjunct,String>()
{
-            @Override public String apply(EntityAdjunct input) {
-                return (input != null) ? input.getId() : null;
-            }}));
+        xstream.registerConverter(new ConverterImpl(Location.class));
+        xstream.registerConverter(new ConverterImpl(Entity.class));
+        xstream.registerConverter(new ConverterImpl(EntityAdjunct.class));
     }
     
     @Override
@@ -70,14 +61,12 @@ public class XmlMementoSerializer<T> extends XmlSerializer<T>
implements Memento
         }
     }
 
-    public static class ConverterImpl<T> implements Converter {
+    public static class ConverterImpl<T extends Identifiable> implements Converter
{
         private final AtomicBoolean hasWarned = new AtomicBoolean(false);
         private final Class<?> converatable;
-        private final Function<T,String> idExtractor;
         
-        ConverterImpl(Class<T> converatable, Function<T,String> idExtractor)
{
+        ConverterImpl(Class<T> converatable) {
             this.converatable = checkNotNull(converatable, "converatable");
-            this.idExtractor = checkNotNull(idExtractor, "idExtractor");
         }
         
         @SuppressWarnings({ "rawtypes" })
@@ -98,7 +87,7 @@ public class XmlMementoSerializer<T> extends XmlSerializer<T>
implements Memento
             }
             // no-op; can't marshall this; deserializing will give null!
             writer.startNode("unserializableLocation");
-            writer.setValue(idExtractor.apply((T)source));
+            writer.setValue(((T)source).getId());
             writer.endNode();
         }
 


Mime
View raw message