brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #462: Inherit config default values
Date Fri, 06 Jan 2017 17:42:48 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/462#discussion_r94975515
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
---
    @@ -28,51 +32,188 @@
     import org.apache.brooklyn.config.ConfigKey;
     import org.apache.brooklyn.config.ConfigValueAtContainer;
     import org.apache.brooklyn.util.collections.CollectionMerger;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
     import org.apache.brooklyn.util.exceptions.ReferenceWithError;
     import org.apache.brooklyn.util.guava.Maybe;
    +import org.apache.brooklyn.util.text.Strings;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
     
    +@SuppressWarnings("serial")
     public class BasicConfigInheritance implements ConfigInheritance {
     
    +    private static final Logger log = LoggerFactory.getLogger(BasicConfigInheritance.class);
    +    
         private static final long serialVersionUID = -5916548049057961051L;
     
         public static final String CONFLICT_RESOLUTION_STRATEGY_DEEP_MERGE = "deep_merge";
         public static final String CONFLICT_RESOLUTION_STRATEGY_OVERWRITE = "overwrite";
         
    +    public static abstract class DelegatingConfigInheritance implements ConfigInheritance
{
    +        protected abstract ConfigInheritance getDelegate();
    +        
    +        @Override @Deprecated public InheritanceMode isInherited(ConfigKey<?> key,
Object from, Object to) {
    +            return getDelegate().isInherited(key, from, to);
    +        }
    +        @Override public <TContainer, TValue> boolean isReinheritable(ConfigValueAtContainer<TContainer,
TValue> parent, ConfigInheritanceContext context) {
    +            return getDelegate().isReinheritable(parent, context);
    +        }
    +        @Override public <TContainer, TValue> boolean considerParent(ConfigValueAtContainer<TContainer,
TValue> local, ConfigValueAtContainer<TContainer, TValue> parent, ConfigInheritanceContext
context) {
    +            return getDelegate().considerParent(local, parent, context);
    +        }
    +        @Override
    +        public <TContainer, TValue> ReferenceWithError<ConfigValueAtContainer<TContainer,
TValue>> resolveWithParent(ConfigValueAtContainer<TContainer, TValue> local, ConfigValueAtContainer<TContainer,
TValue> resolvedParent, ConfigInheritanceContext context) {
    +            return getDelegate().resolveWithParent(local, resolvedParent, context);
    +        }
    +        @Override
    +        public boolean equals(Object obj) {
    +            return super.equals(obj) || getDelegate().equals(obj);
    +        }
    +        
    +        // standard deserialization method
    +        protected ConfigInheritance readResolve() {
    +            return returnEquivalentConstant(this);
    +        }
    +    }
    +
    +    private static ConfigInheritance returnEquivalentConstant(ConfigInheritance candidate)
{
    +        for (ConfigInheritance knownMode: Arrays.asList(
    +                NOT_REINHERITED, NOT_REINHERITED_ELSE_DEEP_MERGE, NEVER_INHERITED, OVERWRITE,
BasicConfigInheritance.DEEP_MERGE)) {
    +            if (candidate.equals(knownMode)) return knownMode;
    +        }
    +        if (candidate.equals(new BasicConfigInheritance(false, CONFLICT_RESOLUTION_STRATEGY_OVERWRITE,
true, true))) {
    --- End diff --
    
    Could make this a constant.


---
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