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

    https://github.com/apache/brooklyn-server/pull/868#discussion_r147359682
  
    --- 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 --
    
    It's not so much the semantics of the method as what is allowed in catalog
    
    i'm updating release notes:
    
    ```
    1. BOM files that do not declare a version now give the version of the 
bundle to their entities,
       rather than the default 0.0.0-SNAPSHOT version.
    
    1. Some catalog methods may return the same type multiple times, if 
contained in multiple bundles.
       Previously only one of the bundle's definition of the type was returned. 
       Except for anonymous bundles it is no longer allowed to have give items 
with the same name and version.
       (This is required to prevent Brooklyn from getting in to a state where 
it cannot rebind.)
    ```


---

Reply via email to