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 08:57:50 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-3.0.x 6b513a55b -> bfd0db0e7


[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/a3ceb475
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a3ceb475
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a3ceb475

Branch: refs/heads/karaf-3.0.x
Commit: a3ceb475d29ff66bf1292d1e30b98dbb83b0ff96
Parents: 6b513a5
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:13:52 2015 +0100

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


http://git-wip-us.apache.org/repos/asf/karaf/blob/a3ceb475/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 92e0ec6..396a768 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
@@ -22,16 +22,7 @@ import java.lang.reflect.Modifier;
 import java.security.AccessControlContext;
 import java.security.AccessController;
 import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeMap;
+import java.util.*;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -77,6 +68,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;
@@ -304,12 +296,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('(');
@@ -327,7 +320,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));
                         }
@@ -338,6 +331,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