Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8624C200D29 for ; Thu, 26 Oct 2017 12:18:40 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 84ABC160BF7; Thu, 26 Oct 2017 10:18:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CB60C1609E8 for ; Thu, 26 Oct 2017 12:18:39 +0200 (CEST) Received: (qmail 34066 invoked by uid 500); 26 Oct 2017 10:18:38 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 34016 invoked by uid 99); 26 Oct 2017 10:18:38 -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; Thu, 26 Oct 2017 10:18:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CF8C2DFBD3; Thu, 26 Oct 2017 10:18:35 +0000 (UTC) From: aledsage To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #868: allow types from different bundles if equ... Content-Type: text/plain Message-Id: <20171026101836.CF8C2DFBD3@git1-us-west.apache.org> Date: Thu, 26 Oct 2017 10:18:35 +0000 (UTC) archived-at: Thu, 26 Oct 2017 10:18:40 -0000 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 getAllWithoutCatalog(Predicate 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 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 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 getMatching(Predicate 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! ---