karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgoody...@apache.org
Subject [05/50] git commit: [KARAF-3017]Concurrency issues in FeaturesService related to add/remove/list operations
Date Sat, 26 Jul 2014 01:54:46 GMT
[KARAF-3017]Concurrency issues in FeaturesService related to add/remove/list operations


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/61109a0b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/61109a0b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/61109a0b

Branch: refs/heads/karaf-2.3.x
Commit: 61109a0b2f86f788f56d0f1590545a3003a25a39
Parents: 5d634aa
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Mon Jun 30 15:53:32 2014 +0800
Committer: Freeman Fang <freeman.fang@gmail.com>
Committed: Mon Jun 30 15:53:32 2014 +0800

----------------------------------------------------------------------
 .../karaf/features/internal/FeaturesServiceImpl.java      | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/61109a0b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
index 7a3bc7a..221a5ce 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
@@ -46,6 +46,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 import java.util.regex.Matcher;
@@ -106,7 +107,7 @@ public class FeaturesServiceImpl implements FeaturesService, FrameworkListener
{
     private boolean respectStartLvlDuringFeatureStartup;
     private long resolverTimeout = 5000;
     private Set<URI> uris;
-    private Map<URI, RepositoryImpl> repositories = new HashMap<URI, RepositoryImpl>();
+    private Map<URI, Repository> repositories = new ConcurrentHashMap<URI, Repository>();
     private Map<String, Map<String, Feature>> features;
     private Map<Feature, Set<Long>> installed = new HashMap<Feature, Set<Long>>();
     private String boot;
@@ -316,8 +317,8 @@ public class FeaturesServiceImpl implements FeaturesService, FrameworkListener
{
     public void removeRepository(URI uri, boolean uninstall) throws Exception {
         if (repositories.containsKey(uri)) {
             if (uninstall) {
-                RepositoryImpl repositoryImpl = repositories.get(uri);
-                for (Feature feature : repositoryImpl.getFeatures()) {
+                Repository repository = repositories.get(uri);
+                for (Feature feature : repository.getFeatures()) {
                     this.uninstallFeature(feature.getName(), feature.getVersion());
                 }
             }
@@ -356,7 +357,8 @@ public class FeaturesServiceImpl implements FeaturesService, FrameworkListener
{
      * @return the list of features repositories.
      */
     public Repository[] listRepositories() {
-        Collection<RepositoryImpl> repos = repositories.values();
+        // the constructor will iterate over ConcurrentHashMap without the risk of ConcurrentModificationException
+        Collection<Repository> repos = new ArrayList<Repository>(repositories.values());
         return repos.toArray(new Repository[repos.size()]);
     }
 


Mime
View raw message