brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Make YAML more powerful
Date Thu, 16 Apr 2015 21:14:13 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/595#discussion_r28550544
  
    --- Diff: core/src/main/java/brooklyn/event/basic/MapConfigKey.java ---
    @@ -125,6 +131,25 @@ protected Object applyEntryValueToMap(Entry value, Map target) {
             } else if (k instanceof String) {
                 k = subKey((String)k);
             } else {
    +            // supplier or other unexpected value
    +            if (k instanceof Supplier) {
    +                Object mapAtRoot = target.get(this);
    +                if (mapAtRoot==null) {
    +                    mapAtRoot = new LinkedHashMap();
    +                    target.put(this, mapAtRoot);
    +                }
    +                // TODO above is not thread-safe, and below is assuming synching on map

    +                // is the best way to prevent CME's, which is often but not always true
    +                if (mapAtRoot instanceof Map) {
    +                    if (mapAtRoot instanceof ConcurrentMap) {
    +                        return ((Map)mapAtRoot).put(k, value.getValue());
    +                    } else {
    +                        synchronized (mapAtRoot) {
    --- End diff --
    
    Or the supplier of the map might have done `Collections.synchronizedMap(...)`. I'm ok
with leaving this synchornized in here, but think that we should never be relying on it -
if synchronization is important, then the map should have been created with that in mind (e.g.
`Collections.synchronizedMap(...)` means that you never need to synchronize explicitly except
for multi-call actions such as iterating).


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