brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [01/13] incubator-brooklyn git commit: force catalog to load on access of getCatalogItems()
Date Wed, 19 Nov 2014 17:47:56 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 1241ee175 -> b8bda2eae


force catalog to load on access of getCatalogItems()

some callers use that to force catalog load, so support that behaviour. in time maybe we can
throw this away or simplify it hugely.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/aae521ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/aae521ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/aae521ec

Branch: refs/heads/master
Commit: aae521ec39db74ebed60005623ae8648e6606be8
Parents: 911fb37
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Nov 18 13:08:12 2014 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Nov 19 13:53:06 2014 +0000

----------------------------------------------------------------------
 .../brooklyn/catalog/internal/BasicBrooklynCatalog.java     | 7 ++++++-
 core/src/main/java/brooklyn/catalog/internal/CatalogDo.java | 9 ++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/aae521ec/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
index 4c53ecf..9db1940 100644
--- a/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
@@ -274,7 +274,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
     }
 
     /**
-     * Loads this catalog
+     * Loads this catalog. No effect if already loaded.
      */
     public void load() {
         log.debug("Loading catalog for " + mgmt);
@@ -668,6 +668,11 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
     @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
     public <T,SpecT> Iterable<CatalogItem<T,SpecT>> getCatalogItems() {
+        if (!getCatalog().isLoaded()) {
+            // some callers use this to force the catalog to load (maybe when starting as
hot_backup without a catalog ?)
+            log.debug("Forcing catalog load on access of catalog items");
+            load();
+        }
         return ImmutableList.copyOf((Iterable)catalog.getIdCache().values());
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/aae521ec/core/src/main/java/brooklyn/catalog/internal/CatalogDo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogDo.java b/core/src/main/java/brooklyn/catalog/internal/CatalogDo.java
index 0ea741d..1988516 100644
--- a/core/src/main/java/brooklyn/catalog/internal/CatalogDo.java
+++ b/core/src/main/java/brooklyn/catalog/internal/CatalogDo.java
@@ -37,6 +37,7 @@ import brooklyn.util.net.Urls;
 import brooklyn.util.time.CountdownTimer;
 import brooklyn.util.time.Duration;
 
+import com.google.api.client.util.Objects;
 import com.google.common.base.Preconditions;
 
 public class CatalogDo {
@@ -83,7 +84,13 @@ public class CatalogDo {
      * (but does not load all JARs)
      */
     public synchronized CatalogDo load(ManagementContext mgmt, CatalogDo parent) {
-        if (isLoaded()) return this;
+        if (isLoaded()) {
+            if (mgmt!=null && !Objects.equal(mgmt, this.mgmt)) {
+                throw new IllegalStateException("Cannot set mgmt "+mgmt+" on "+this+" after
catalog is loaded");
+            }
+            log.debug("Catalog "+this+" is already loaded");
+            return this;
+        }
         loadThisCatalog(mgmt, parent);
         loadChildrenCatalogs();
         buildCaches();


Mime
View raw message