cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject svn commit: r1514423 - in /cxf/dosgi/trunk/dsw/cxf-topology-manager/src: main/java/org/apache/cxf/dosgi/topologymanager/exporter/ test/java/org/apache/cxf/dosgi/topologymanager/exporter/
Date Thu, 15 Aug 2013 18:23:55 GMT
Author: amichai
Date: Thu Aug 15 18:23:55 2013
New Revision: 1514423

URL: http://svn.apache.org/r1514423
Log:
Fix handling of failed exports and service unregistration during export

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

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java?rev=1514423&r1=1514422&r2=1514423&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
Thu Aug 15 18:23:55 2013
@@ -90,6 +90,9 @@ public class EndpointListenerNotifier {
      * @param endpoints the endpoints the listeners should be notified about
      */
     void notifyListeners(boolean added, Collection<EndpointDescription> endpoints)
{
+        if (endpoints.isEmpty()) { // a little optimization to prevent unnecessary processing
+            return;
+        }
         ServiceReference[] listeners = stEndpointListeners.getServiceReferences();
         if (listeners != null) {
             for (ServiceReference eplReference : listeners) {
@@ -150,7 +153,7 @@ public class EndpointListenerNotifier {
                 LOG.debug("Filter {} matches endpoint {}", filter, dict);
                 matchingFilters.add(filter);
             } else {
-                LOG.debug("Filter {} does not match endpoint {}", filter, dict);
+                LOG.trace("Filter {} does not match endpoint {}", filter, dict);
             }
         }
         return matchingFilters;

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=1514423&r1=1514422&r2=1514423&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
Thu Aug 15 18:23:55 2013
@@ -149,7 +149,7 @@ public class TopologyManagerExport {
     }
 
     protected void doExportService(final ServiceReference sref) {
-        LOG.debug("Exporting service");
+        LOG.debug("Exporting service {}", sref);
         endpointRepo.addService(sref); // mark for future export even if there are currently
no RSAs
         List<RemoteServiceAdmin> rsaList = remoteServiceAdminTracker.getAllServices();
         if (rsaList.isEmpty()) {
@@ -172,22 +172,50 @@ public class TopologyManagerExport {
 
     private void exportServiceUsingRemoteServiceAdmin(final ServiceReference sref,
                                                       final RemoteServiceAdmin remoteServiceAdmin)
{
+        // abort if the service was unregistered by the time we got here
+        // (we check again at the end, but this optimization saves unnecessary heavy processing)
+        if (sref.getBundle() == null) {
+            LOG.info("TopologyManager: export aborted for {} since it was unregistered",
sref);
+            endpointRepo.removeService(sref);
+            return;
+        }
+        // do the export
+        LOG.debug("exporting {}...", sref);
         // TODO: additional parameter Map?
-        LOG.debug("exporting...");
         Collection<ExportRegistration> exportRegs = remoteServiceAdmin.exportService(sref,
null);
-        List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
-        // note: endpoints list may contain ExportRegistrations with an exception, not only
successful ones
         if (exportRegs.isEmpty()) {
-            // TODO export failed -> What should be done here?
-            LOG.error("export failed");
-        } else {
-            for (ExportRegistration exportReg : exportRegs) {
-                endpoints.add(getExportedEndpoint(exportReg));
+            LOG.warn("TopologyManager: nothing was exported for {}", sref);
+            return;
+        }
+        // process successful/failed registrations
+        List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
+        for (ExportRegistration reg : exportRegs) {
+            if (reg.getException() == null) {
+                EndpointDescription endpoint = getExportedEndpoint(reg);
+                LOG.info("TopologyManager: export succeeded for {}, endpoint ", sref, endpoint);
+                endpoints.add(endpoint);
+            } else {
+                // TODO: what should we do with failed exports?
+                LOG.error("TopologyManager: export failed for {}", sref);
+                reg.close();
+            }
+        }
+        // abort export if service was unregistered in the meanwhile (since we have a race
+        // with the unregister event which may have already been handled, so we'll miss it)
+        if (sref.getBundle() == null) {
+            LOG.info("TopologyManager: export reverted for {} since service was unregistered",
sref);
+            endpointRepo.removeService(sref);
+            for (ExportRegistration reg : exportRegs) {
+                reg.close();
             }
-            LOG.info("TopologyManager: export successful Endpoints: {}", endpoints);
+            return;
+        }
+        // add the new exported endpoints
+        if (!endpoints.isEmpty()) {
+            LOG.info("TopologyManager: export successful for {}, endpoints: {}", sref, endpoints);
             epListenerNotifier.notifyListeners(true, endpoints);
+            endpointRepo.addEndpoints(sref, remoteServiceAdmin, endpoints);
         }
-        endpointRepo.addEndpoints(sref, remoteServiceAdmin, endpoints);
     }
 
     /**

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java?rev=1514423&r1=1514422&r2=1514423&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java
Thu Aug 15 18:23:55 2013
@@ -115,6 +115,7 @@ public class ExportServiceTest {
         ExportRegistration exportRegistration = c.createMock(ExportRegistration.class);
         ExportReference exportReference = c.createMock(ExportReference.class);
         EasyMock.expect(exportRegistration.getExportReference()).andReturn(exportReference).anyTimes();
+        EasyMock.expect(exportRegistration.getException()).andReturn(null).anyTimes();
         EasyMock.expect(exportReference.getExportedEndpoint()).andReturn(endpoint).anyTimes();
         return exportRegistration;
     }



Mime
View raw message