Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 723E817EA1 for ; Mon, 23 Mar 2015 23:41:47 +0000 (UTC) Received: (qmail 28379 invoked by uid 500); 23 Mar 2015 23:41:47 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 28358 invoked by uid 500); 23 Mar 2015 23:41:47 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 28349 invoked by uid 99); 23 Mar 2015 23:41:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Mar 2015 23:41:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 23 Mar 2015 23:41:45 +0000 Received: (qmail 25211 invoked by uid 99); 23 Mar 2015 23:41:25 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Mar 2015 23:41:25 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 77FBBE1825; Mon, 23 Mar 2015 23:41:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.incubator.apache.org Date: Mon, 23 Mar 2015 23:41:25 -0000 Message-Id: <0775325ac5464062bfc104a1bfecdcfb@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] incubator-brooklyn git commit: Relax synchronisation in EntityManager X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-brooklyn Updated Branches: refs/heads/master e08d3208b -> 75503d9e4 Relax synchronisation in EntityManager Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/983163cb Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/983163cb Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/983163cb Branch: refs/heads/master Commit: 983163cb11a8f538f68021b301c1de4cf35c5e65 Parents: d738df9 Author: Andrew Kennedy Authored: Mon Mar 23 19:06:02 2015 +0000 Committer: Andrew Kennedy Committed: Mon Mar 23 19:06:15 2015 +0000 ---------------------------------------------------------------------- .../management/internal/LocalEntityManager.java | 31 ++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/983163cb/core/src/main/java/brooklyn/management/internal/LocalEntityManager.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/management/internal/LocalEntityManager.java b/core/src/main/java/brooklyn/management/internal/LocalEntityManager.java index 2438f57..67c0a39 100644 --- a/core/src/main/java/brooklyn/management/internal/LocalEntityManager.java +++ b/core/src/main/java/brooklyn/management/internal/LocalEntityManager.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentMap; import javax.annotation.Nullable; @@ -87,13 +88,13 @@ public class LocalEntityManager implements EntityManagerInternal { private final InternalPolicyFactory policyFactory; /** Entities that have been created, but have not yet begun to be managed */ - protected final Map preRegisteredEntitiesById = new WeakHashMap(); + protected final Map preRegisteredEntitiesById = Collections.synchronizedMap(new WeakHashMap()); /** Entities that are in the process of being managed, but where management is not yet complete */ - protected final Map preManagedEntitiesById = new WeakHashMap(); + protected final Map preManagedEntitiesById = Collections.synchronizedMap(new WeakHashMap()); /** Proxies of the managed entities */ - protected final Map entityProxiesById = Maps.newLinkedHashMap(); + protected final ConcurrentMap entityProxiesById = Maps.newConcurrentMap(); /** Real managed entities */ protected final Map entitiesById = Maps.newLinkedHashMap(); @@ -105,7 +106,7 @@ public class LocalEntityManager implements EntityManagerInternal { protected final ObservableList entities = new ObservableList(); /** Proxies of the managed entities that are applications */ - protected final Set applications = Sets.newLinkedHashSet(); + protected final Set applications = Sets.newConcurrentHashSet(); private final BrooklynStorage storage; private final Map entityTypes; @@ -177,34 +178,34 @@ public class LocalEntityManager implements EntityManagerInternal { } @Override - public synchronized Collection getEntities() { + public Collection getEntities() { return ImmutableList.copyOf(entityProxiesById.values()); } @Override - public synchronized Collection getEntityIds() { + public Collection getEntityIds() { return ImmutableList.copyOf(entityProxiesById.keySet()); } @Override - public synchronized Collection getEntitiesInApplication(Application application) { + public Collection getEntitiesInApplication(Application application) { Predicate predicate = EntityPredicates.applicationIdEqualTo(application.getId()); return ImmutableList.copyOf(Iterables.filter(entityProxiesById.values(), predicate)); } @Override - public synchronized Collection findEntities(Predicate filter) { + public Collection findEntities(Predicate filter) { return ImmutableList.copyOf(Iterables.filter(entityProxiesById.values(), filter)); } @Override - public synchronized Collection findEntitiesInApplication(Application application, Predicate filter) { + public Collection findEntitiesInApplication(Application application, Predicate filter) { Predicate predicate = Predicates.and(EntityPredicates.applicationIdEqualTo(application.getId()), filter); return ImmutableList.copyOf(Iterables.filter(entityProxiesById.values(), predicate)); } @Override - public synchronized Iterable getAllEntitiesInApplication(Application application) { + public Iterable getAllEntitiesInApplication(Application application) { Predicate predicate = EntityPredicates.applicationIdEqualTo(application.getId()); Iterable allentities = Iterables.concat(preRegisteredEntitiesById.values(), preManagedEntitiesById.values(), entityProxiesById.values()); Iterable result = Iterables.filter(allentities, predicate); @@ -215,11 +216,11 @@ public class LocalEntityManager implements EntityManagerInternal { } @Override - public synchronized Entity getEntity(String id) { + public Entity getEntity(String id) { return entityProxiesById.get(id); } - synchronized Collection getApplications() { + Collection getApplications() { return ImmutableList.copyOf(applications); } @@ -228,11 +229,11 @@ public class LocalEntityManager implements EntityManagerInternal { return (isRunning() && getEntity(e.getId()) != null); } - synchronized boolean isPreRegistered(Entity e) { + boolean isPreRegistered(Entity e) { return preRegisteredEntitiesById.containsKey(e.getId()); } - synchronized void prePreManage(Entity entity) { + void prePreManage(Entity entity) { if (isPreRegistered(entity)) { log.warn(""+this+" redundant call to pre-pre-manage entity "+entity+"; skipping", new Exception("source of duplicate pre-pre-manage of "+entity)); @@ -282,7 +283,7 @@ public class LocalEntityManager implements EntityManagerInternal { AccessController.Response access = managementContext.getAccessController().canManageEntity(item); if (!access.isAllowed()) { throw new IllegalStateException("Access controller forbids management of "+item+": "+access.getMsg()); - } + } } /* TODO we sloppily use "recursive" to ensure ordering of parent-first in many places