Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/48#discussion_r15120493
--- Diff: core/src/main/java/brooklyn/entity/effector/AddSensor.java ---
@@ -53,10 +53,43 @@ public AddSensor(T sensor) {
public void apply(EntityLocal entity) {
((EntityInternal)entity).getMutableEntityType().addSensor(sensor);
}
-
- public static <T> AttributeSensor<T> newSensor(Class<T> type,
ConfigBag params) {
+
+ public static <T> AttributeSensor<T> newSensor(Class<T> type,
ConfigBag params){
+ String name = Preconditions.checkNotNull(params.get(SENSOR_NAME),
"name must be supplied when defining a sensor");
+ return Sensors.newSensor(type, name);
+ }
+
+ public static <T> AttributeSensor<T> newSensor(ConfigBag params) {
String name = Preconditions.checkNotNull(params.get(SENSOR_NAME),
"name must be supplied when defining a sensor");
- return Sensors.newSensor(type, name);
+ String className = getFullClassName(params.get(SENSOR_TYPE));
+ Class<T> type = null;
+
+ try {
+ type = (Class<T>) Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Invalid target type for
sensor "+name+": " + className);
+ }
+ return Sensors.newSensor(type, name);
+ }
+
+ private static String getFullClassName(String className) {
+ if(className.equalsIgnoreCase("string")){
+ return "java.lang.String";
--- End diff --
`String.class.getName()` and similar below would be cleaner than these
magic strings -- but i'm not going to block this PR for that! nice to have
these conveniences. might want to move them to a shared utils if we need them
elsewhere.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---