karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [1/2] karaf git commit: [KARAF-3576] Optimize GuardProxyCatalog#getServiceInvocationRoles
Date Mon, 02 Mar 2015 09:00:34 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 52c5c610c -> 5bf287ec9


[KARAF-3576] Optimize GuardProxyCatalog#getServiceInvocationRoles


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

Branch: refs/heads/master
Commit: 301f3f7b54154a22b5fd062151d35b1fef3b4f98
Parents: 52c5c61
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Sat Feb 28 13:59:58 2015 +0100
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Mon Mar 2 09:59:19 2015 +0100

----------------------------------------------------------------------
 .../service/guard/impl/GuardProxyCatalog.java   | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/301f3f7b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
----------------------------------------------------------------------
diff --git a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
index db22d01..4883126 100644
--- a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
+++ b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
@@ -27,6 +27,7 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.concurrent.BlockingQueue;
@@ -72,6 +73,7 @@ public class GuardProxyCatalog implements ServiceListener {
     private static final String ROLE_WILDCARD = "*";
 
     private final BundleContext myBundleContext;
+    private final Map<String, Filter> filters = new ConcurrentHashMap<String, Filter>();
 
     final ServiceTracker<ConfigurationAdmin, ConfigurationAdmin> configAdminTracker;
     final ServiceTracker<ProxyManager, ProxyManager> proxyManagerTracker;
@@ -299,12 +301,13 @@ public class GuardProxyCatalog implements ServiceListener {
         // This can probably be optimized. Maybe we can cache the config object relevant
instead of
         // walking through all of the ones that have 'service.guard'.
         for (Configuration config : getServiceGuardConfigs()) {
-            Object guardFilter = config.getProperties().get(SERVICE_GUARD_KEY);
+            Dictionary<String, Object> properties = config.getProperties();
+            Object guardFilter = properties.get(SERVICE_GUARD_KEY);
             if (guardFilter instanceof String) {
-                Filter filter = myBundleContext.createFilter((String) guardFilter);
+                Filter filter = getFilter((String) guardFilter);
                 if (filter.match(serviceReference)) {
                     definitionFound = true;
-                    for (Enumeration<String> e = config.getProperties().keys(); e.hasMoreElements();
) {
+                    for (Enumeration<String> e = properties.keys(); e.hasMoreElements();
) {
                         String key = e.nextElement();
                         String bareKey = key;
                         int idx = bareKey.indexOf('(');
@@ -322,7 +325,7 @@ public class GuardProxyCatalog implements ServiceListener {
                         if (!isValidMethodName(bareKey)) {
                             continue;
                         }
-                        Object value = config.getProperties().get(key);
+                        Object value = properties.get(key);
                         if (value instanceof String) {
                             allRoles.addAll(ACLConfigurationParser.parseRoles((String) value));
                         }
@@ -333,6 +336,15 @@ public class GuardProxyCatalog implements ServiceListener {
         return definitionFound ? allRoles : null;
     }
 
+    private Filter getFilter(String string) throws InvalidSyntaxException {
+        Filter filter = filters.get(string);
+        if (filter == null) {
+            filter = myBundleContext.createFilter(string);
+            filters.put(string, filter);
+        }
+        return filter;
+    }
+
     // Ensures that it never returns null
     private Configuration[] getServiceGuardConfigs() throws IOException, InvalidSyntaxException
{
         ConfigurationAdmin ca = null;


Mime
View raw message