brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geomacy <>
Subject [GitHub] brooklyn-server pull request #453: BROOKLYN-352: fix ConcurrentModification ...
Date Tue, 22 Nov 2016 12:37:46 GMT
Github user geomacy commented on a diff in the pull request:
    --- Diff: core/src/main/java/org/apache/brooklyn/core/mgmt/internal/
    @@ -212,13 +213,41 @@ public EntityTypeRegistry getEntityTypeRegistry() {
         public Iterable<Entity> getAllEntitiesInApplication(Application application)
    +        // To fix, we need to synchronize
    +        // preRegisteredEntitiesById and preManagedEntitiesById while iterating over
them (because
    +        // they are synchronizedMaps). entityProxiesById is a ConcurrentMap, so no need
    +        // synchronize on that.
    +        // Only synchronize on one at a time, to avoid the risk of deadlock.
             Predicate<Entity> predicate = EntityPredicates.applicationIdEqualTo(application.getId());
    -        Iterable<Entity> allentities = Iterables.concat(preRegisteredEntitiesById.values(),
preManagedEntitiesById.values(), entityProxiesById.values());
    -        Iterable<Entity> result = Iterables.filter(allentities, predicate);
    -        return ImmutableSet.copyOf(Iterables.transform(result, new Function<Entity,
Entity>() {
    -            @Override public Entity apply(Entity input) {
    -                return Entities.proxy(input);
    -            }}));
    +        Set<Entity> result = Sets.newLinkedHashSet();
    +        synchronized (preRegisteredEntitiesById) {
    --- End diff --
    Maybe it would be worth making `preRegisteredEntitiesById` and `preManagedEntitiesById`
private, and providing access to them with code like this loop, but put into a `protected`
method.  At the moment it's not impossible that some derived class in future would again use
one of the maps but forget the synchronization. 

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

View raw message