Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/868#discussion_r147092903
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
 ---
    @@ -74,28 +92,40 @@ public BasicBrooklynTypeRegistry(ManagementContext 
mgmt) {
         }
         
         private Iterable<RegisteredType> getAllWithoutCatalog(Predicate<? 
super RegisteredType> filter) {
    -        // TODO thread safety
             // TODO optimisation? make indexes and look up?
    -        return Iterables.filter(localRegisteredTypes.values(), filter);
    +        return Locks.withLock(localRegistryLock.readLock(), 
    +            () -> 
localRegisteredTypesAndContainingBundles.values().stream().
    +                flatMap(m -> 
m.values().stream()).filter(filter::apply).collect(Collectors.toList()) );
         }
     
         private Maybe<RegisteredType> getExactWithoutLegacyCatalog(String 
symbolicName, String version, RegisteredTypeLoadingContext constraint) {
    -        // TODO look in any nested/private registries
    -        RegisteredType item = 
localRegisteredTypes.get(symbolicName+":"+version);
    +        RegisteredType item = Locks.withLock(localRegistryLock.readLock(), 
    +            ()-> 
getBestValue(localRegisteredTypesAndContainingBundles.get(symbolicName+":"+version))
 );
             return RegisteredTypes.tryValidate(item, constraint);
         }
     
    +    private RegisteredType getBestValue(Map<String, RegisteredType> m) {
    +        if (m==null) return null;
    +        if (m.isEmpty()) return null;
    +        if (m.size()==1) return m.values().iterator().next();
    +        // get the highest version of first alphabetical - to have a 
canonical order
    +        return m.get( 
Ordering.from(VersionedNameStringComparator.INSTANCE).max(m.keySet()) );
    +    }
    +
         @SuppressWarnings("deprecation")
         @Override
         public Iterable<RegisteredType> getMatching(Predicate<? super 
RegisteredType> filter) {
    --- End diff --
    
    Worth noting that the semantics of this method have changed, and same for 
`getAll`: you might now get multiple `RegisteredType`s with the same 
name:version. Normally those will be identical (just coming from different 
bundles), but it may not be guaranteed that they are identical!


---

Reply via email to