cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject svn commit: r1492237 - in /cxf/dosgi/trunk: discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ dsw/cxf-topology-manager/src/main/java/org/apache/cxf/do...
Date Wed, 12 Jun 2013 15:09:31 GMT
Author: amichai
Date: Wed Jun 12 15:09:30 2013
New Revision: 1492237

URL: http://svn.apache.org/r1492237
Log:
DOSGI-164 Fix various NullPointerExceptions when using ServiceReference.getBundle()

Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
    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/RemoteServiceAdminCore.java
    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
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java?rev=1492237&r1=1492236&r2=1492237&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
Wed Jun 12 15:09:30 2013
@@ -26,6 +26,7 @@ import java.util.concurrent.CopyOnWriteA
 
 import org.apache.cxf.dosgi.discovery.local.util.Utils;
 import org.apache.zookeeper.ZooKeeper;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
@@ -139,21 +140,12 @@ public class InterfaceMonitorManager {
         for (ServiceReference sref : relatedServiceListeners) {
             Object service = bctx.getService(sref);
             try {
-                if (!(service instanceof EndpointListener)) { // including null
-                    continue;
-                }
-                EndpointListener epl = (EndpointListener) service;
-                LOG.debug("matching {} against {}", epd, currentScope);
-                if (Utils.matchFilter(bctx, currentScope, epd)) {
-                    LOG.debug("Matched {} against {}", epd, currentScope);
-                    if (isAdded) {
-                        LOG.info("calling EndpointListener.endpointAdded: " + epl + " from
bundle "
-                            + sref.getBundle().getSymbolicName() + " for endpoint: " + epd);
-                        epl.endpointAdded(epd, currentScope);
-                    } else {
-                        LOG.info("calling EndpointListener.endpointRemoved: " + epl + " from
bundle "
-                            + sref.getBundle().getSymbolicName() + " for endpoint: " + epd);
-                        epl.endpointRemoved(epd, currentScope);
+                if (service instanceof EndpointListener) {
+                    EndpointListener epl = (EndpointListener) service;
+                    LOG.trace("matching {} against {}", epd, currentScope);
+                    if (Utils.matchFilter(bctx, currentScope, epd)) {
+                        LOG.debug("Matched {} against {}", epd, currentScope);
+                        notifyListener(epd, currentScope, isAdded, sref.getBundle(), epl);
                     }
                 }
             } finally {
@@ -164,6 +156,21 @@ public class InterfaceMonitorManager {
         }
     }
 
+    private void notifyListener(EndpointDescription epd, String currentScope, boolean isAdded,
+                                Bundle eplBundle, EndpointListener epl) {
+        if (eplBundle == null) {
+            LOG.info("listening service was unregistered, ignoring");
+        } else if (isAdded) {
+            LOG.info("calling EndpointListener.endpointAdded: " + epl + " from bundle "
+                    + eplBundle.getSymbolicName() + " for endpoint: " + epd);
+            epl.endpointAdded(epd, currentScope);
+        } else {
+            LOG.info("calling EndpointListener.endpointRemoved: " + epl + " from bundle "
+                    + eplBundle.getSymbolicName() + " for endpoint: " + epd);
+            epl.endpointRemoved(epd, currentScope);
+        }
+    }
+
     public synchronized void close() {
         for (Interest interest : interestingScopes.values()) {
             interest.im.close();

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=1492237&r1=1492236&r2=1492237&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
Wed Jun 12 15:09:30 2013
@@ -20,6 +20,7 @@ package org.apache.cxf.dosgi.dsw.service
 
 import java.util.List;
 
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -89,12 +90,15 @@ public class EventProducer {
             if (listenerRefs != null) {
                 for (ServiceReference sref : listenerRefs) {
                     RemoteServiceAdminListener rsal = (RemoteServiceAdminListener)bctx.getService(sref);
-                    try {
-                        LOG.debug("notify RemoteServiceAdminListener {} of bundle {}",
-                                rsal, sref.getBundle().getSymbolicName());
-                        rsal.remoteAdminEvent(rsae);
-                    } finally {
-                        if (rsal != null) {
+                    if (rsal != null) {
+                        try {
+                            Bundle bundle = sref.getBundle();
+                            if (bundle != null) {
+                                LOG.debug("notify RemoteServiceAdminListener {} of bundle
{}",
+                                        rsal, bundle.getSymbolicName());
+                                rsal.remoteAdminEvent(rsae);
+                            }
+                        } finally {
                             bctx.ungetService(sref);
                         }
                     }

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=1492237&r1=1492236&r2=1492237&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 Jun 12 15:09:30 2013
@@ -119,12 +119,13 @@ public class RemoteServiceAdminCore impl
         try {
             // do the export
             List<ExportRegistration> exportRegs = exportInterfaces(interfaces, serviceReference,
serviceProperties);
-
-            // enlist initial export registrations in global list of exportRegistrations
-            synchronized (exportedServices) {
-                exportedServices.put(key, new ArrayList<ExportRegistration>(exportRegs));
+            if (!exportRegs.isEmpty()) {
+                // enlist initial export registrations in global list of exportRegistrations
+                synchronized (exportedServices) {
+                    exportedServices.put(key, new ArrayList<ExportRegistration>(exportRegs));
+                }
+                eventProducer.publishNotification(exportRegs);
             }
-            eventProducer.publishNotification(exportRegs);
             return exportRegs;
         } finally {
             synchronized (exportedServices) {
@@ -147,16 +148,22 @@ public class RemoteServiceAdminCore impl
             return Collections.emptyList();
         }
         List<ExportRegistration> exportRegs = new ArrayList<ExportRegistration>(1);
-        Object serviceObject = bctx.getService(serviceReference);
-        BundleContext callingContext = serviceReference.getBundle().getBundleContext();
+        Object service = bctx.getService(serviceReference);
+        Bundle bundle = serviceReference.getBundle();
+
+        // if service has been unregistered in the meantime
+        if (service == null || bundle == null) {
+            LOG.info("service has been unregistered, aborting export");
+            return exportRegs;
+        }
 
         for (String iface : interfaces) {
             LOG.info("creating server for interface " + iface);
             // this is an extra sanity check, but do we really need it now?
-            Class<?> interfaceClass = ClassUtils.getInterfaceClass(serviceObject, iface);
+            Class<?> interfaceClass = ClassUtils.getInterfaceClass(service, iface);
             if (interfaceClass != null) {
-                ExportResult exportResult = handler.createServer(serviceReference, bctx,
callingContext,
-                    serviceProperties, interfaceClass, serviceObject);
+                ExportResult exportResult = handler.createServer(serviceReference, bctx,
bundle.getBundleContext(),
+                    serviceProperties, interfaceClass, service);
                 LOG.info("created server for interface " + iface);
                 EndpointDescription epd = new EndpointDescription(exportResult.getEndpointProps());
                 ExportRegistrationImpl exportRegistration = new ExportRegistrationImpl(serviceReference,
epd, this);
@@ -261,7 +268,7 @@ public class RemoteServiceAdminCore impl
     }
 
     private boolean isCreatedByThisRSA(ServiceReference sref) {
-        return (sref.getBundle() != null) && sref.getBundle().equals(bctx.getBundle());
+        return bctx.getBundle().equals(sref.getBundle()); // sref bundle can be null
     }
 
     public Collection<ExportReference> getExportedServices() {

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=1492237&r1=1492236&r2=1492237&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 Jun 12 15:09:30 2013
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.cxf.dosgi.topologymanager.util.Utils;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
@@ -76,9 +77,8 @@ class EndpointRepository {
 
     synchronized void addService(ServiceReference sref) {
         if (!exportedServices.containsKey(sref)) {
-            LOG.info("Marking service from bundle {} for export", sref.getBundle().getSymbolicName());
-            exportedServices.put(sref,
-                                 new LinkedHashMap<RemoteServiceAdmin, Collection<EndpointDescription>>());
+            LOG.info("Marking service from bundle {} for export", Utils.getBundleName(sref));
+            exportedServices.put(sref, new LinkedHashMap<RemoteServiceAdmin, Collection<EndpointDescription>>());
         }
     }
 

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=1492237&r1=1492236&r2=1492237&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
Wed Jun 12 15:09:30 2013
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.cxf.dosgi.topologymanager.util.SimpleServiceTracker;
 import org.apache.cxf.dosgi.topologymanager.util.SimpleServiceTrackerListener;
+import org.apache.cxf.dosgi.topologymanager.util.Utils;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
@@ -144,7 +145,7 @@ public class TopologyManagerExport {
         List<RemoteServiceAdmin> rsaList = remoteServiceAdminTracker.getAllServices();
         if (rsaList.isEmpty()) {
             LOG.error("No RemoteServiceAdmin available! Unable to export service from bundle
{}, interfaces: {}",
-                    sref.getBundle().getSymbolicName(),
+                    Utils.getBundleName(sref),
                     sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS));
         }
 

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java?rev=1492237&r1=1492236&r2=1492237&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java
Wed Jun 12 15:09:30 2013
@@ -24,8 +24,10 @@ import java.util.UUID;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 
 public final class Utils {
@@ -71,4 +73,9 @@ public final class Utils {
             return uuid;
         }
     }
+
+    public static String getBundleName(ServiceReference sref) {
+        Bundle bundle = sref.getBundle();
+        return bundle == null ? "<unregistered>" : bundle.getSymbolicName();
+    }
 }



Mime
View raw message