cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject svn commit: r1491087 - in /cxf/dosgi/trunk/dsw: cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/
Date Sat, 08 Jun 2013 22:25:01 GMT
Author: amichai
Date: Sat Jun  8 22:24:59 2013
New Revision: 1491087

URL: http://svn.apache.org/r1491087
Log:
DOSGI-188 Fix imported services not released when RemoteServiceAdmin is closed

Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.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/service/RemoteServiceAdminInstance.java
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java?rev=1491087&r1=1491086&r2=1491087&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
Sat Jun  8 22:24:59 2013
@@ -71,11 +71,15 @@ public class EventProducer {
 
     // only one of ir or er must be set, and the other must be null
     private void notify(int type, ImportRegistration ir, ExportRegistration er) {
-        RemoteServiceAdminEvent event = ir != null
-            ? new RemoteServiceAdminEvent(type, bctx.getBundle(), ir.getImportReference(),
ir.getException())
-            : new RemoteServiceAdminEvent(type, bctx.getBundle(), er.getExportReference(),
er.getException());
-        notifyListeners(event);
-        eaHelper.notifyEventAdmin(event);
+        try {
+            RemoteServiceAdminEvent event = ir != null
+                ? new RemoteServiceAdminEvent(type, bctx.getBundle(), ir.getImportReference(),
ir.getException())
+                : new RemoteServiceAdminEvent(type, bctx.getBundle(), er.getExportReference(),
er.getException());
+            notifyListeners(event);
+            eaHelper.notifyEventAdmin(event);
+        } catch (IllegalStateException ise) {
+            LOG.debug("can't send notifications since bundle context is no longer valid");
+        }
     }
 
     private void notifyListeners(RemoteServiceAdminEvent rsae) {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java?rev=1491087&r1=1491086&r2=1491087&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
Sat Jun  8 22:24:59 2013
@@ -103,7 +103,12 @@ public class ImportRegistrationImpl impl
             clientServiceFactory.setCloseable(true);
         }
         if (importedService != null) {
-            importedService.unregister();
+            try {
+                importedService.unregister();
+            } catch (IllegalStateException ise) {
+                LOG.debug("imported service is already unregistered");
+            }
+            importedService = null;
         }
     }
 

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=1491087&r1=1491086&r2=1491087&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
Sat Jun  8 22:24:59 2013
@@ -423,6 +423,19 @@ public class RemoteServiceAdminCore impl
         }
     }
 
+    // remove all import registrations associated with the given bundle
+    protected void removeImportRegistrations() {
+        Collection<ImportRegistrationImpl> copy = new ArrayList<ImportRegistrationImpl>();
+        synchronized (importedServices) {
+            for (Collection<ImportRegistrationImpl> irs : importedServices.values())
{
+                copy.addAll(irs);
+            }
+        }
+        for (ImportRegistrationImpl ir : copy) {
+            removeImportRegistration(ir);
+        }
+    }
+
     private List<ExportRegistration> getExportsForBundle(Bundle exportingBundle) {
         synchronized (exportedServices) {
             List<ExportRegistration> bundleRegs = new ArrayList<ExportRegistration>();

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java?rev=1491087&r1=1491086&r2=1491087&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
Sat Jun  8 22:24:59 2013
@@ -102,5 +102,6 @@ public class RemoteServiceAdminInstance 
     public void close() {
         closed = true;
         rsaCore.removeExportRegistrations(bctx.getBundle());
+        rsaCore.removeImportRegistrations();
     }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java?rev=1491087&r1=1491086&r2=1491087&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java
Sat Jun  8 22:24:59 2013
@@ -19,6 +19,7 @@
 package org.apache.cxf.dosgi.topologymanager.importer;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -97,6 +98,7 @@ public class TopologyManagerImport imple
             }
 
             public void removed(RemoteServiceAdmin rsa) {
+                // the RSA's imports will be closed by its shutdown, so nothing to do here
             }
         });
         endpointListenerManager = new EndpointListenerManager(bctx, this);
@@ -305,12 +307,22 @@ public class TopologyManagerImport imple
         return null;
     }
 
-    /**
-     * This method is called once a RemoteServiceAdminEvent for an removed import reference
is received.
-     * However the current implementation has no special support for multiple topology managers,
therefore this method
-     * does nothing for the moment.
-     */
-    public void removeImportReference(ImportReference anyObject) {
+    public void removeImportReference(ImportReference importReference) {
+        synchronized (importedServices) {
+            for (Iterator<List<ImportRegistration>> it1 = importedServices.values().iterator();
it1.hasNext();) {
+                Collection<ImportRegistration> irs = it1.next();
+                for (Iterator<ImportRegistration> it2 = irs.iterator(); it2.hasNext();)
{
+                    ImportRegistration ir = it2.next();
+                    if (ir.getImportReference().equals(importReference)) {
+                        ir.close();
+                        it2.remove();
+                    }
+                }
+                if (irs.isEmpty()) {
+                    it1.remove();
+                }
+            }
+        }
     }
 
     public void remoteAdminEvent(RemoteServiceAdminEvent event) {



Mime
View raw message