cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject svn commit: r1487445 - in /cxf/dosgi/trunk: discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ dsw/cxf-topolo...
Date Wed, 29 May 2013 11:55:24 GMT
Author: amichai
Date: Wed May 29 11:55:24 2013
New Revision: 1487445

URL: http://svn.apache.org/r1487445
Log:
Fix inefficient and redundant Map lookups and iterations

Modified:
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java

Modified: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java?rev=1487445&r1=1487444&r2=1487445&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
(original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
Wed May 29 11:55:24 2013
@@ -134,8 +134,9 @@ public class LocalDiscovery implements B
         
         listenerToFilters.put(listener, filters);
         for (String filter : filters) {
-            if (filterToListeners.containsKey(filter)) {
-                filterToListeners.get(filter).add(listener);
+            Collection<EndpointListener> listeners = filterToListeners.get(filter);
+            if (listeners != null) {
+                listeners.add(listener);
             } else {
                 List<EndpointListener> list = new ArrayList<EndpointListener>();
                 list.add(listener);
@@ -154,10 +155,9 @@ public class LocalDiscovery implements B
         
         for (String filter : filters) {
             Collection<EndpointListener> listeners = filterToListeners.get(filter);
-            if (listeners == null) {
-                continue;
+            if (listeners != null) {
+                listeners.remove(listener);
             }
-            listeners.remove(listener);
         }        
     }
 

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=1487445&r1=1487444&r2=1487445&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
Wed May 29 11:55:24 2013
@@ -315,9 +315,9 @@ public class RemoteServiceAdminCore impl
         LOG.debug("importService() Endpoint: {}", endpoint.getProperties());
 
         synchronized (importedServices) {
-            if (importedServices.containsKey(endpoint) && importedServices.get(endpoint).size()
> 0) {
+            Collection<ImportRegistrationImpl> imRegs = importedServices.get(endpoint);
+            if (imRegs != null && imRegs.size() > 0) {
                 LOG.debug("creating copy of existing import registrations");
-                Collection<ImportRegistrationImpl> imRegs = importedServices.get(endpoint);
                 ImportRegistrationImpl irParent = imRegs.iterator().next();
                 ImportRegistrationImpl ir = new ImportRegistrationImpl(irParent);
                 imRegs.add(ir);
@@ -325,7 +325,7 @@ public class RemoteServiceAdminCore impl
                 return ir;
             }
 
-            ConfigurationTypeHandler handler = null;
+            ConfigurationTypeHandler handler;
             try {
                 handler = configTypeHandlerFactory.getHandler(bctx, endpoint);
             } catch (RuntimeException e) {
@@ -335,8 +335,7 @@ public class RemoteServiceAdminCore impl
 
             LOG.debug("Handler: {}", handler);
 
-            // // TODO: somehow select the interfaces that should be imported ----> job
of the TopologyManager
-            // ?
+            // TODO: somehow select the interfaces that should be imported ---> job of
the TopologyManager?
             List<String> matchingInterfaces = endpoint.getInterfaces();
 
             LOG.info("Matching Interfaces for import: " + matchingInterfaces);
@@ -347,7 +346,6 @@ public class RemoteServiceAdminCore impl
                 ImportRegistrationImpl imReg = new ImportRegistrationImpl(endpoint, this);
 
                 proxifyMatchingInterface(matchingInterfaces.get(0), imReg, handler, bctx);
-                Collection<ImportRegistrationImpl> imRegs = importedServices.get(endpoint);
                 if (imRegs == null) {
                     imRegs = new ArrayList<ImportRegistrationImpl>();
                     importedServices.put(endpoint, imRegs);
@@ -359,7 +357,6 @@ public class RemoteServiceAdminCore impl
                 return null;
             }
         }
-
     }
 
     protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl
imReg,

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java?rev=1487445&r1=1487444&r2=1487445&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java
Wed May 29 11:55:24 2013
@@ -176,20 +176,22 @@ public final class OsgiUtils {
         }
 
         for (Map.Entry<String, Object> e : additionalProperties.entrySet()) {
-            String key = e.getKey().toLowerCase();
-            if (org.osgi.framework.Constants.SERVICE_ID.toLowerCase().equals(key)
-                || org.osgi.framework.Constants.OBJECTCLASS.toLowerCase().equals(key)) {
+            String key = e.getKey();
+            String lowerKey = key.toLowerCase();
+            if (org.osgi.framework.Constants.SERVICE_ID.toLowerCase().equals(lowerKey)
+                || org.osgi.framework.Constants.OBJECTCLASS.toLowerCase().equals(lowerKey))
{
                 // objectClass and service.id must not be overwritten
                 LOG.info("exportService called with additional properties map that contained
illegal key: "
-                          + key + "   The key is ignored");
-                continue;
-            } else if (keysLowerCase.containsKey(key)) {
-                String origKey = keysLowerCase.get(key);
-                serviceProperties.put(origKey, e.getValue());
-                LOG.debug("Overwriting property [{}]  with value [{}]", origKey, e.getValue());
+                          + key + ", the key is ignored");
             } else {
-                serviceProperties.put(e.getKey(), e.getValue());
-                keysLowerCase.put(e.getKey().toString().toLowerCase(), e.getKey().toString());
+                String origKey = keysLowerCase.get(lowerKey);
+                if (origKey != null) {
+                    LOG.debug("Overwriting property [{}] with value [{}]", origKey, e.getValue());
+                } else {
+                    origKey = key;
+                    keysLowerCase.put(lowerKey, origKey);
+                }
+                serviceProperties.put(origKey, e.getValue());
             }
         }
     }

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java?rev=1487445&r1=1487444&r2=1487445&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
Wed May 29 11:55:24 2013
@@ -52,8 +52,9 @@ class EndpointRepository {
     synchronized List<EndpointDescription> removeRemoteServiceAdmin(RemoteServiceAdmin
rsa) {
         List<EndpointDescription> removedEndpoints = new ArrayList<EndpointDescription>();
         for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports
: exportedServices.values()) {
-            if (exports.containsKey(rsa)) {
-                removedEndpoints.addAll(exports.get(rsa));
+            Collection<EndpointDescription> endpoints = exports.get(rsa);
+            if (endpoints != null) {
+                removedEndpoints.addAll(endpoints);
                 exports.remove(rsa);
             }
         }
@@ -62,12 +63,10 @@ class EndpointRepository {
 
     synchronized List<EndpointDescription> removeService(ServiceReference sref) {
         List<EndpointDescription> removedEndpoints = new ArrayList<EndpointDescription>();
-        if (exportedServices.containsKey(sref)) {
-            Map<RemoteServiceAdmin, Collection<EndpointDescription>> rsas = exportedServices.get(sref);
-            for (Map.Entry<RemoteServiceAdmin, Collection<EndpointDescription>>
entry : rsas.entrySet()) {
-                if (entry.getValue() != null) {
-                    removedEndpoints.addAll(entry.getValue());
-                }
+        Map<RemoteServiceAdmin, Collection<EndpointDescription>> rsas = exportedServices.get(sref);
+        if (rsas != null) {
+            for (Collection<EndpointDescription> endpoints : rsas.values()) {
+                removedEndpoints.addAll(endpoints);
             }
             exportedServices.remove(sref);
         }
@@ -84,6 +83,9 @@ class EndpointRepository {
 
     synchronized void addEndpoints(ServiceReference sref, RemoteServiceAdmin rsa,
                                    List<EndpointDescription> endpoints) {
+        if (endpoints == null) {
+            throw new NullPointerException();
+        }
         addService(sref);
         Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = exportedServices.get(sref);
         exports.put(rsa, endpoints);
@@ -98,9 +100,7 @@ class EndpointRepository {
         List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
         for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports
: exportedServices.values()) {
             for (Collection<EndpointDescription> regs : exports.values()) {
-                if (regs != null) {
-                    endpoints.addAll(regs);
-                }
+                endpoints.addAll(regs);
             }
         }
         return endpoints;
@@ -108,9 +108,10 @@ class EndpointRepository {
 
     synchronized Set<ServiceReference> getServicesToBeExportedFor(RemoteServiceAdmin
rsa) {
         Set<ServiceReference> servicesToBeExported = new HashSet<ServiceReference>();
-        for (ServiceReference sref : exportedServices.keySet()) {
-            if (!isAlreadyExportedForRsa(sref, rsa)) {
-                servicesToBeExported.add(sref);
+        for (Map.Entry<ServiceReference, Map<RemoteServiceAdmin, Collection<EndpointDescription>>>
entry
+                : exportedServices.entrySet()) {
+            if (!entry.getValue().containsKey(rsa)) {
+                servicesToBeExported.add(entry.getKey());
             }
         }
         return servicesToBeExported;



Mime
View raw message