aledsage commented on a change in pull request #1046: allow the types of
parameters to be extended programmatically
URL: https://github.com/apache/brooklyn-server/pull/1046#discussion_r258415045
##########
File path:
core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
##########
@@ -197,6 +199,15 @@ public String toString() {
return type;
}
+ /** Allows extensions to define additional types that are supported for
parameters in YAML.
+ * Rules should return a TypeToken if the given name is known, null if not
handled, or
+ * throw if the name is decisively problematic. Handlers will throw if no
rules match.
+ */
+ @Beta
+ public static void addCustomTypeNameInference(String ruleName,
BiFunction<String,BrooklynClassLoadingContext,TypeToken<?>> rule) {
Review comment:
I can see why you've done this with a static field, but it feels like a code
smell. Downsides are testability (e.g. a unit test can never reverse the
effects of calling this method - all subsequent tests executed could be
affected by what it did); interaction between entities/modules (e.g. someone
could write an entity that calls this, which would affect all subsequent
blueprints); and reasoning about the code (e.g. other stateful stuff in
brooklyn will be stored by the management context (or some such), rather than
it being a static field).
However, you've marked it `@Beta` so I'm ok with going with this approach -
the code is certainly shorter (and thus simpler) than alternatives.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services