brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #301: Test+fix DeferredSuppliers in $brooklyn:o...
Date Tue, 16 Aug 2016 09:05:30 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/301#discussion_r74899592
  
    --- Diff: camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
---
    @@ -428,28 +430,44 @@ public DslObject(
                 return DependentConfiguration.transformMultiple(flags, new Function<List<Object>,
Object>() {
                             @Override
                             public Object apply(List<Object> input) {
    -                            Iterator<Object> values = input.iterator();
    +                            Map<String, Object> resolvedFields = Maps.newLinkedHashMap();
    +                            Map<String, Object> resolvedConfig = Maps.newLinkedHashMap();
    +                            List<Object> resolvedConstructorArgs = Lists.newArrayList();
    +                            List<Object> resolvedFactoryMethodArgs = Lists.newArrayList();
    +                            
    +                            Iterator<Object> taskValues = input.iterator();
                                 for (String name : fields.keySet()) {
                                     Object value = fields.get(name);
    -                                if (value instanceof TaskAdaptable || value instanceof
TaskFactory) {
    -                                    fields.put(name, values.next());
    -                                } else if (value instanceof DeferredSupplier) {
    -                                    fields.put(name, ((DeferredSupplier<?>) value).get());
    -                                }
    +                                Object resolvedValue = requiresTask(value) ? taskValues.next()
: resolveValue(value);
    +                                resolvedFields.put(name, resolvedValue);
                                 }
                                 for (String name : config.keySet()) {
                                     Object value = config.get(name);
    -                                if (value instanceof TaskAdaptable || value instanceof
TaskFactory) {
    -                                    config.put(name, values.next());
    -                                } else if (value instanceof DeferredSupplier) {
    -                                    config.put(name, ((DeferredSupplier<?>) value).get());
    -                                }
    +                                Object resolvedValue = requiresTask(value) ? taskValues.next()
: resolveValue(value);
    +                                resolvedConfig.put(name, resolvedValue);
    +                            }
    +                            for (Object value : constructorArgs) {
    +                                Object resolvedValue = requiresTask(value) ? taskValues.next()
: resolveValue(value);
    +                                resolvedConstructorArgs.add(resolvedValue);
    +                            }
    +                            for (Object value : factoryMethodArgs) {
    +                                Object resolvedValue = requiresTask(value) ? taskValues.next()
: resolveValue(value);
    +                                resolvedFactoryMethodArgs.add(resolvedValue);
                                 }
                                 if (factoryMethodName == null) {
    -                                return create(clazz, constructorArgs, fields, config);
    +                                return create(clazz, resolvedConstructorArgs, resolvedFields,
resolvedConfig);
                                 } else {
    -                                return create(clazz, factoryMethodName, factoryMethodArgs,
fields, config);
    +                                return create(clazz, factoryMethodName, resolvedFactoryMethodArgs,
resolvedFields, resolvedConfig);
    +                            }
    +                        }
    +                        protected boolean requiresTask(Object value) {
    +                            return (value instanceof TaskAdaptable || value instanceof
TaskFactory);
    +                        }
    +                        protected Object resolveValue(Object value) {
    +                            if (value instanceof DeferredSupplier) {
    +                                return ((DeferredSupplier<?>) value).get();
                                 }
    +                            return value;
                             }
    --- End diff --
    
    yes, nice :-)


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message