You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ge...@apache.org on 2017/06/06 12:25:34 UTC
[14/17] brooklyn-server git commit: synchronize osgi bundle managers
inside dedicated package-private class
synchronize osgi bundle managers inside dedicated package-private class
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/e1b0be18
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/e1b0be18
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/e1b0be18
Branch: refs/heads/master
Commit: e1b0be1847550a40e2fb853885fca35b09a03df2
Parents: 5fad03d
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Jun 5 11:52:47 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Jun 5 11:52:47 2017 +0100
----------------------------------------------------------------------
.../core/mgmt/ha/OsgiArchiveInstaller.java | 14 ++--
.../brooklyn/core/mgmt/ha/OsgiManager.java | 71 ++++++++++++++------
2 files changed, 53 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e1b0be18/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
index 4088564..7d2267a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
@@ -280,16 +280,16 @@ class OsgiArchiveInstaller {
if (result.getMetadata()!=null) {
// already have a managed bundle - check if this is using a new/different URL
if (suppliedKnownBundleMetadata!=null && suppliedKnownBundleMetadata.getUrl()!=null) {
- String knownIdForThisUrl = osgiManager.managedBundlesByUrl.get(suppliedKnownBundleMetadata.getUrl());
+ String knownIdForThisUrl = osgiManager.managedBundlesRecord.getManagedBundleIdFromUrl(suppliedKnownBundleMetadata.getUrl());
if (knownIdForThisUrl==null) {
// it's a new URL, but a bundle we already know about
log.warn("Request to install from "+suppliedKnownBundleMetadata.getUrl()+" which is not recognized but "+
"appears to match "+result.getMetadata()+"; now associating with the latter");
- osgiManager.managedBundlesByUrl.put(suppliedKnownBundleMetadata.getUrl(), result.getMetadata().getId());
+ osgiManager.managedBundlesRecord.setManagedBundleUrl(suppliedKnownBundleMetadata.getUrl(), result.getMetadata().getId());
} else if (!knownIdForThisUrl.equals(result.getMetadata().getId())) {
log.warn("Request to install from "+suppliedKnownBundleMetadata.getUrl()+" which is associated to "+knownIdForThisUrl+" but "+
"appears to match "+result.getMetadata()+"; now associating with the latter");
- osgiManager.managedBundlesByUrl.put(suppliedKnownBundleMetadata.getUrl(), result.getMetadata().getId());
+ osgiManager.managedBundlesRecord.setManagedBundleUrl(suppliedKnownBundleMetadata.getUrl(), result.getMetadata().getId());
}
}
if (canUpdate()) {
@@ -333,13 +333,7 @@ class OsgiArchiveInstaller {
zipFile = null; // don't close/delete it here, we'll use it for uploading, then it will delete it
if (!updating) {
- synchronized (osgiManager.managedBundles) {
- osgiManager.managedBundles.put(result.getMetadata().getId(), result.getMetadata());
- osgiManager.managedBundlesByName.put(result.getMetadata().getVersionedName(), result.getMetadata().getId());
- if (Strings.isNonBlank(result.getMetadata().getUrl())) {
- osgiManager.managedBundlesByUrl.put(result.getMetadata().getUrl(), result.getMetadata().getId());
- }
- }
+ osgiManager.managedBundlesRecord.addManagedBundle(result);
result.code = OsgiBundleInstallationResult.ResultCode.INSTALLED_NEW_BUNDLE;
result.message = "Installed "+result.getMetadata().getVersionedName()+" with ID "+result.getMetadata().getId();
mgmt().getRebindManager().getChangeListener().onManaged(result.getMetadata());
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e1b0be18/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
index 6b9c526..69021fe 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
@@ -102,9 +102,47 @@ public class OsgiManager {
private boolean reuseFramework;
private Set<Bundle> bundlesAtStartup;
private File osgiCacheDir;
- Map<String, ManagedBundle> managedBundles = MutableMap.of();
- Map<VersionedName, String> managedBundlesByName = MutableMap.of();
- Map<String, String> managedBundlesByUrl = MutableMap.of();
+ final ManagedBundlesRecord managedBundlesRecord = new ManagedBundlesRecord();
+
+ static class ManagedBundlesRecord {
+ private Map<String, ManagedBundle> managedBundles = MutableMap.of();
+ private Map<VersionedName, String> managedBundlesByName = MutableMap.of();
+ private Map<String, String> managedBundlesByUrl = MutableMap.of();
+
+ synchronized Map<String, ManagedBundle> getManagedBundles() {
+ return ImmutableMap.copyOf(managedBundles);
+ }
+
+ synchronized String getManagedBundleId(VersionedName vn) {
+ return managedBundlesByName.get(vn);
+ }
+
+ synchronized ManagedBundle getManagedBundle(VersionedName vn) {
+ return managedBundles.get(managedBundlesByName.get(vn));
+ }
+
+ synchronized String getManagedBundleIdFromUrl(String url) {
+ return managedBundlesByUrl.get(url);
+ }
+
+ synchronized ManagedBundle getManagedBundleFromUrl(String url) {
+ String id = getManagedBundleIdFromUrl(url);
+ if (id==null) return null;
+ return managedBundles.get(id);
+ }
+
+ synchronized void setManagedBundleUrl(String url, String id) {
+ managedBundlesByUrl.put(url, id);
+ }
+
+ synchronized void addManagedBundle(OsgiBundleInstallationResult result) {
+ managedBundles.put(result.getMetadata().getId(), result.getMetadata());
+ managedBundlesByName.put(result.getMetadata().getVersionedName(), result.getMetadata().getId());
+ if (Strings.isNonBlank(result.getMetadata().getUrl())) {
+ managedBundlesByUrl.put(result.getMetadata().getUrl(), result.getMetadata().getId());
+ }
+ }
+ }
private static AtomicInteger numberOfReusableFrameworksCreated = new AtomicInteger();
private static final List<Framework> OSGI_FRAMEWORK_CONTAINERS_FOR_REUSE = MutableList.of();
@@ -213,30 +251,20 @@ public class OsgiManager {
}
public Map<String, ManagedBundle> getManagedBundles() {
- synchronized (managedBundles) {
- return ImmutableMap.copyOf(managedBundles);
- }
+ return managedBundlesRecord.getManagedBundles();
}
public String getManagedBundleId(VersionedName vn) {
- synchronized (managedBundles) {
- return managedBundlesByName.get(vn);
- }
+ return managedBundlesRecord.getManagedBundleId(vn);
}
public ManagedBundle getManagedBundle(VersionedName vn) {
- synchronized (managedBundles) {
- return managedBundles.get(managedBundlesByName.get(vn));
- }
+ return managedBundlesRecord.getManagedBundle(vn);
}
/** For bundles which are installed by a URL, see whether a bundle has been installed from that URL */
public ManagedBundle getManagedBundleFromUrl(String url) {
- synchronized (managedBundles) {
- String id = managedBundlesByUrl.get(url);
- if (id==null) return null;
- return managedBundles.get(id);
- }
+ return managedBundlesRecord.getManagedBundleFromUrl(url);
}
/** See {@link OsgiArchiveInstaller#install()}, using default values */
@@ -277,13 +305,13 @@ public class OsgiManager {
* Callers should typically fail if anything from this bundle is in use.
*/
public void uninstallUploadedBundle(ManagedBundle bundleMetadata) {
- synchronized (managedBundles) {
- ManagedBundle metadata = managedBundles.remove(bundleMetadata.getId());
+ synchronized (managedBundlesRecord) {
+ ManagedBundle metadata = managedBundlesRecord.managedBundles.remove(bundleMetadata.getId());
if (metadata==null) {
throw new IllegalStateException("No such bundle registered: "+bundleMetadata);
}
- managedBundlesByName.remove(bundleMetadata.getVersionedName());
- managedBundlesByUrl.remove(bundleMetadata.getUrl());
+ managedBundlesRecord.managedBundlesByName.remove(bundleMetadata.getVersionedName());
+ managedBundlesRecord.managedBundlesByUrl.remove(bundleMetadata.getUrl());
}
mgmt.getRebindManager().getChangeListener().onUnmanaged(bundleMetadata);
@@ -569,5 +597,4 @@ public class OsgiManager {
public Framework getFramework() {
return framework;
}
-
}