cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1484615 - in /cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter: EndpointRepository.java TopologyManagerExport.java
Date Mon, 20 May 2013 22:03:53 GMT
Author: cschneider
Date: Mon May 20 22:03:52 2013
New Revision: 1484615

URL: http://svn.apache.org/r1484615
Log:
DOSGI-184 Fixing concurrency issue and small refactoring

Modified:
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java

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=1484615&r1=1484614&r2=1484615&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
Mon May 20 22:03:52 2013
@@ -20,6 +20,7 @@ package org.apache.cxf.dosgi.topologyman
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -36,7 +37,7 @@ import org.slf4j.LoggerFactory;
  * For each ServiceReference that is exported a map is maintained which contains information
  * on the endpoints for each RemoteAdminService that created the endpoints 
  */
-public class EndpointRepository {
+class EndpointRepository {
 	private static final Logger LOG = LoggerFactory.getLogger(EndpointRepository.class);
 
     private final Map<ServiceReference, 
@@ -75,20 +76,22 @@ public class EndpointRepository {
     }
     
     synchronized void addService(ServiceReference sref) {
-    	LOG.info("TopologyManager: adding service to exportedServices list to export it ---
from bundle:  "
-    			+ sref.getBundle().getSymbolicName());
-    	exportedServices.put(sref,
+    	if (!exportedServices.containsKey(sref)) {
+        	LOG.info("Marking service from bundle {} for export", sref.getBundle().getSymbolicName());
+    		exportedServices.put(sref,
     			new LinkedHashMap<RemoteServiceAdmin, Collection<EndpointDescription>>());
+    	}
     }
     
     synchronized void addEndpoints(ServiceReference sref, RemoteServiceAdmin rsa, List<EndpointDescription>
endpoints) {
+    	addService(sref);
     	Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = exportedServices.get(sref);
     	exports.put(rsa, endpoints);
     }
     
     synchronized boolean isAlreadyExportedForRsa(ServiceReference sref, RemoteServiceAdmin
rsa) {
     	Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = exportedServices.get(sref);
-    	return exports.containsKey(rsa);
+    	return exports != null && exports.containsKey(rsa);
     }
     
     synchronized Collection<EndpointDescription> getAllEndpoints() {
@@ -103,8 +106,13 @@ public class EndpointRepository {
     	return endpoints;
     }
 
-    synchronized Set<ServiceReference> getServices() {
-    	return exportedServices.keySet();
-	}
-
+    synchronized Set<ServiceReference> getServicesToBeExportedFor(RemoteServiceAdmin
rsa) {
+    	Set<ServiceReference> servicesToBeExported = new HashSet<ServiceReference>();
+    	for (ServiceReference sref : exportedServices.keySet()) {
+    		if (!isAlreadyExportedForRsa(sref, rsa)) {
+				servicesToBeExported.add(sref);
+			}
+		}
+		return servicesToBeExported;
+    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java?rev=1484615&r1=1484614&r2=1484615&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
Mon May 20 22:03:52 2013
@@ -73,7 +73,9 @@ public class TopologyManagerExport {
         this.remoteServiceAdminTracker = rsaTracker;
         this.remoteServiceAdminTracker.addListener(new RemoteServiceAdminLifeCycleListener()
{
             public void added(RemoteServiceAdmin rsa) {
-                triggerExportForRemoteServiceAdmin(rsa);
+        		for (ServiceReference serviceRef : endpointRepo.getServicesToBeExportedFor(rsa))
{
+        			triggerExport(serviceRef);
+        		}
             }
 
             public void removed(RemoteServiceAdmin rsa) {
@@ -87,7 +89,7 @@ public class TopologyManagerExport {
                 if (event.getType() == ServiceEvent.REGISTERED) {
                     LOG.debug("Received REGISTERED ServiceEvent: {}", event);
                     if (shouldExportService(sref)) {
-                        exportService(sref);
+                        triggerExport(sref);
                     }
                 } else if (event.getType() == ServiceEvent.UNREGISTERING) {
                     LOG.debug("Received UNREGISTERING ServiceEvent: {}", event);
@@ -111,18 +113,6 @@ public class TopologyManagerExport {
         return sref.getProperty(RemoteConstants.SERVICE_EXPORTED_INTERFACES) != null;
     }
 
-	protected void triggerExportForRemoteServiceAdmin(RemoteServiceAdmin rsa) {
-		for (ServiceReference serviceRef : endpointRepo.getServices()) {
-			String bundleName = serviceRef.getBundle().getSymbolicName();
-			if (endpointRepo.isAlreadyExportedForRsa(serviceRef, rsa)) {
-				LOG.debug("service from bundle {} is already handled by this RSA", bundleName);
-			} else {
-				LOG.debug("service from bundle {} is to be exported by this RSA", bundleName);
-				exportService(serviceRef);
-			}
-		}
-	}
-
     public void start() {
         epListenerNotifier.start();
         bctx.addServiceListener(serviceListener);
@@ -135,11 +125,6 @@ public class TopologyManagerExport {
         epListenerNotifier.stop();
     }
     
-    protected void exportService(ServiceReference sref) {
-    	endpointRepo.addService(sref);
-        triggerExport(sref);
-    }
-
     protected void triggerExport(final ServiceReference sref) {
         execService.execute(new Runnable() {
             public void run() {
@@ -149,7 +134,7 @@ public class TopologyManagerExport {
     }
 
     protected void doExportService(final ServiceReference sref) {
-        LOG.debug("Exporting service");
+    	endpointRepo.addService(sref);
         List<RemoteServiceAdmin> rsaList = remoteServiceAdminTracker.getList();
         if (rsaList.size() == 0) {
             LOG.error(
@@ -166,25 +151,31 @@ public class TopologyManagerExport {
                 // already handled by this remoteServiceAdmin
                 LOG.debug("already handled by this remoteServiceAdmin -> skipping");
             } else {
-                // TODO: additional parameter Map ?
-                LOG.debug("exporting ...");
-                Collection<ExportRegistration> exportRegs = remoteServiceAdmin
-                        .exportService(sref, null);
-            	List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
-                if (exportRegs == null) {
-                    // TODO export failed -> What should be done here?
-                    LOG.error("export failed");
-                } else {
-                	for (ExportRegistration exportReg : exportRegs) {
-						endpoints.add(getExportedEndpoint(exportReg));
-					}
-                    LOG.info("TopologyManager: export sucessful Endpoints: {}", endpoints);
-                    epListenerNotifier.nofifyEndpointListenersOfAdding(endpoints);
-                }
-                endpointRepo.addEndpoints(sref, remoteServiceAdmin, endpoints);
+                exportServiceUsingRemoteServiceAdmin(sref, remoteServiceAdmin);
             }
         }
     }
+
+	private void exportServiceUsingRemoteServiceAdmin(
+			final ServiceReference sref,
+			final RemoteServiceAdmin remoteServiceAdmin) {
+		// TODO: additional parameter Map ?
+		LOG.debug("exporting ...");
+		Collection<ExportRegistration> exportRegs = remoteServiceAdmin
+		        .exportService(sref, null);
+		List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
+		if (exportRegs == null) {
+		    // TODO export failed -> What should be done here?
+		    LOG.error("export failed");
+		} else {
+			for (ExportRegistration exportReg : exportRegs) {
+				endpoints.add(getExportedEndpoint(exportReg));
+			}
+		    LOG.info("TopologyManager: export sucessful Endpoints: {}", endpoints);
+		    epListenerNotifier.nofifyEndpointListenersOfAdding(endpoints);
+		}
+		endpointRepo.addEndpoints(sref, remoteServiceAdmin, endpoints);
+	}
     
     /**
      * Retrieve exported Endpoint while handling null
@@ -201,7 +192,7 @@ public class TopologyManagerExport {
 			ServiceReference[] references = bctx.getServiceReferences(null, DOSGI_SERVICES);
 			if (references != null) {
 			    for (ServiceReference sref : references) {
-			        exportService(sref);
+			        triggerExport(sref);
 			    }
 			}
 		} catch (InvalidSyntaxException e) {



Mime
View raw message