cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject svn commit: r1488780 - in /cxf/dosgi/trunk: discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/ ...
Date Sun, 02 Jun 2013 20:15:51 GMT
Author: amichai
Date: Sun Jun  2 20:15:50 2013
New Revision: 1488780

URL: http://svn.apache.org/r1488780
Log:
DOSGI-171 Fix several missing ungetService calls (resource leaks)

Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java
    cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.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/util/OsgiUtils.java
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/rsatracker/RemoteServiceAdminTracker.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=1488780&r1=1488779&r2=1488780&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
Sun Jun  2 20:15:50 2013
@@ -140,21 +140,27 @@ public class InterfaceMonitorManager {
             List<ServiceReference> relatedServiceListeners) {
         for (ServiceReference sref : relatedServiceListeners) {
             Object service = bctx.getService(sref);
-            if (!(service instanceof EndpointListener)) {
-                continue;
-            }
-            EndpointListener epl = (EndpointListener) service;
-            LOG.debug("matching {} against {}", epd, currentScope);
-            if (matches(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);
+            try {
+                if (!(service instanceof EndpointListener)) { // including null
+                    continue;
+                }
+                EndpointListener epl = (EndpointListener) service;
+                LOG.debug("matching {} against {}", epd, currentScope);
+                if (matches(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);
+                    }
+                }
+            } finally {
+                if (service != null) {
+                    bctx.ungetService(sref);
                 }
             }
         }

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java?rev=1488780&r1=1488779&r2=1488780&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java
Sun Jun  2 20:15:50 2013
@@ -81,6 +81,7 @@ public class PublishingEndpointListenerF
     public synchronized void stop() {
         if (serviceRegistration != null) {
             serviceRegistration.unregister();
+            serviceRegistration = null;
         }
 
         synchronized (listeners) {

Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java?rev=1488780&r1=1488779&r2=1488780&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
Sun Jun  2 20:15:50 2013
@@ -78,12 +78,19 @@ public class Activator implements Bundle
             throw new RuntimeException("This bundle must be started after the bundle with
the Zookeeper "
                                        + "Discovery Managed Service was started.");
         }
-        Object svc = context.getService(refs[0]);
-        ManagedService ms = (ManagedService) svc;
+
         Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put("zookeeper.host", "127.0.0.1");
         props.put("zookeeper.port", System.getProperty(ZOOKEEPER_PORT));
-        ms.updated(props);
+
+        ManagedService ms = (ManagedService) context.getService(refs[0]);
+        try {
+            ms.updated(props);
+        } finally {
+            if (ms != null) {
+                context.ungetService(refs[0]);
+            }
+        }
         LOG.debug("Passed the zookeeper.host property to the Zookeeper Client managed service.");
     }
     

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java?rev=1488780&r1=1488779&r2=1488780&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
Sun Jun  2 20:15:50 2013
@@ -84,15 +84,23 @@ public class SecurityDelegatingHttpConte
             return !requireFilter;
         }
         Filter[] filters = new Filter[refs.length];
-        for (int i = 0; i < refs.length; i++) {
-            filters[i] = (Filter)bundleContext.getService(refs[i]);
-        }
         try {
-            new Chain(filters).doFilter(request, response);
-            return !response.isCommitted();
-        } catch (ServletException e) {
-            LOG.warn(e.getMessage(), e);
-            return false;
+            for (int i = 0; i < refs.length; i++) {
+                filters[i] = (Filter)bundleContext.getService(refs[i]);
+            }
+            try {
+                new Chain(filters).doFilter(request, response);
+                return !response.isCommitted();
+            } catch (ServletException e) {
+                LOG.warn(e.getMessage(), e);
+                return false;
+            }
+        } finally {
+            for (int i = 0; i < refs.length; i++) {
+                if (filters[i] != null) {
+                    bundleContext.ungetService(refs[i]);
+                }
+            }
         }
     }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java?rev=1488780&r1=1488779&r2=1488780&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java
Sun Jun  2 20:15:50 2013
@@ -44,10 +44,10 @@ public class IntentTracker extends Servi
     @Override
     public Object addingService(ServiceReference reference) {
         String intentName = (String) reference.getProperty(Constants.INTENT_NAME_PROP);
-        Object intent = context.getService(reference);
+        Object intent = super.addingService(reference);
         IntentManagerImpl.LOG.info("Adding custom intent " + intentName);
         intentMap.put(intentName, intent);
-        return super.addingService(reference);
+        return intent;
     }
 
     @Override

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java?rev=1488780&r1=1488779&r2=1488780&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
Sun Jun  2 20:15:50 2013
@@ -90,16 +90,8 @@ public class EventAdminHelper {
         props.put("timestamp", System.currentTimeMillis());
         props.put("event", rsae);
 
-        Event ev = createEvent(props, topic);
-
-        EventAdmin[] eas = getEventAdmins();
-        if (eas != null) {
-            LOG.debug("Publishing event to {} EventAdmins;  Topic:[{}]", eas.length, topic);
-            for (EventAdmin eventAdmin : eas) {
-                eventAdmin.postEvent(ev);
-            }
-        }
-
+        Event event = createEvent(props, topic);
+        notifyEventAdmins(topic, event);
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
@@ -109,7 +101,7 @@ public class EventAdminHelper {
         }
     }
 
-    private EventAdmin[] getEventAdmins() {
+    private void notifyEventAdmins(String topic, Event event) {
         ServiceReference[] refs = null;
         try {
             refs = bctx.getAllServiceReferences(EventAdmin.class.getName(), null);
@@ -117,18 +109,19 @@ public class EventAdminHelper {
             LOG.error("Failed to get EventAdmin: " + e.getMessage(), e);
         }
 
-        if (refs == null) {
-            return null;
-        }
-
-        EventAdmin[] eas = new EventAdmin[refs.length];
-        for (int x = 0; x < refs.length; ++x) {
-
-            ServiceReference serviceReference = refs[x];
-            eas[x] = (EventAdmin)bctx.getService(serviceReference);
+        if (refs != null) {
+            LOG.debug("Publishing event to {} EventAdmins;  Topic:[{}]", refs.length, topic);
+            for (ServiceReference serviceReference : refs) {
+                EventAdmin eventAdmin = (EventAdmin) bctx.getService(serviceReference);
+                try {
+                    eventAdmin.postEvent(event);
+                } finally {
+                    if (eventAdmin != null) {
+                        bctx.ungetService(serviceReference);
+                    }
+                }
+            }
         }
-
-        return eas;
     }
 
     static String remoteServiceAdminEventTypeToString(int type) {

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=1488780&r1=1488779&r2=1488780&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
Sun Jun  2 20:15:50 2013
@@ -65,9 +65,15 @@ public class EventProducer {
             if (listenerRefs != null) {
                 for (ServiceReference sref : listenerRefs) {
                     RemoteServiceAdminListener rsal = (RemoteServiceAdminListener)bctx.getService(sref);
-                    LOG.debug("notify RemoteServiceAdminListener {} of bundle {}",
-                            rsal, sref.getBundle().getSymbolicName());
-                    rsal.remoteAdminEvent(rsae);
+                    try {
+                        LOG.debug("notify RemoteServiceAdminListener {} of bundle {}",
+                                rsal, sref.getBundle().getSymbolicName());
+                        rsal.remoteAdminEvent(rsae);
+                    } finally {
+                        if (rsal != null) {
+                            bctx.ungetService(sref);
+                        }
+                    }
                 }
             }
 

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=1488780&r1=1488779&r2=1488780&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
Sun Jun  2 20:15:50 2013
@@ -123,28 +123,33 @@ public final class OsgiUtils {
         ServiceReference paRef = bc.getServiceReference(PackageAdmin.class.getName());
         if (paRef != null) {
             PackageAdmin pa = (PackageAdmin)bc.getService(paRef);
+            try {
+                Bundle b = pa.getBundle(iClass);
+                if (b == null) {
+                    LOG.info("Unable to find interface version for interface " + iClass.getName()
+                            + ". Falling back to 0.0.0");
+                    return "0.0.0";
+                }
+                LOG.debug("Interface source bundle: {}", b.getSymbolicName());
 
-            Bundle b = pa.getBundle(iClass);
-            if (b == null) {
-                LOG.info("Unable to find interface version for interface " + iClass.getName()
-                        + ". Falling back to 0.0.0");
-                return "0.0.0";
-            }
-            LOG.debug("Interface source bundle: {}", b.getSymbolicName());
-
-            ExportedPackage[] ep = pa.getExportedPackages(b);
-            LOG.debug("Exported Packages of the source bundle: {}", ep);
+                ExportedPackage[] ep = pa.getExportedPackages(b);
+                LOG.debug("Exported Packages of the source bundle: {}", ep);
 
-            String pack = iClass.getPackage().getName();
-            LOG.debug("Looking for Package: {}", pack);
-            if (ep != null) {
-                for (ExportedPackage p : ep) {
-                    if (p != null
-                        && pack.equals(p.getName())) {
-                        LOG.debug("found package -> Version: {}", p.getVersion());
-                        return p.getVersion().toString();
+                String pack = iClass.getPackage().getName();
+                LOG.debug("Looking for Package: {}", pack);
+                if (ep != null) {
+                    for (ExportedPackage p : ep) {
+                        if (p != null
+                            && pack.equals(p.getName())) {
+                            LOG.debug("found package -> Version: {}", p.getVersion());
+                            return p.getVersion().toString();
+                        }
                     }
                 }
+            } finally {
+                if (pa != null) {
+                    bc.ungetService(paRef);
+                }
             }
         } else {
             LOG.error("Was unable to obtain the package admin service -> can't resolve
interface versions");

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/rsatracker/RemoteServiceAdminTracker.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/rsatracker/RemoteServiceAdminTracker.java?rev=1488780&r1=1488779&r2=1488780&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/rsatracker/RemoteServiceAdminTracker.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/rsatracker/RemoteServiceAdminTracker.java
Sun Jun  2 20:15:50 2013
@@ -19,6 +19,7 @@
 package org.apache.cxf.dosgi.topologymanager.rsatracker;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
@@ -45,27 +46,28 @@ public class RemoteServiceAdminTracker e
 
     @Override
     public Object addingService(ServiceReference reference) {
+        RemoteServiceAdmin rsa = (RemoteServiceAdmin) super.addingService(reference);
         for (RemoteServiceAdminLifeCycleListener listener : listeners) {
-            listener.added((RemoteServiceAdmin) context.getService(reference));
+            listener.added(rsa);
         }
-        return super.addingService(reference);
+        return rsa;
     }
 
     @Override
     public void removedService(ServiceReference reference, Object service) {
+        RemoteServiceAdmin rsa = (RemoteServiceAdmin) service;
         for (RemoteServiceAdminLifeCycleListener listener : listeners) {
-            listener.removed((RemoteServiceAdmin) context.getService(reference));
+            listener.removed(rsa);
         }
         super.removedService(reference, service);
     }
 
+    @SuppressWarnings("unchecked")
     public List<RemoteServiceAdmin> getList() {
-        List<RemoteServiceAdmin> list = new ArrayList<RemoteServiceAdmin>();
-        ServiceReference[] refs = getServiceReferences();
-        if (refs != null) {
-            for (ServiceReference ref : refs) {
-                list.add((RemoteServiceAdmin) context.getService(ref));
-            }
+        Object[] services = getServices();
+        List list = new ArrayList();
+        if (services != null) {
+            Collections.addAll(list, services);
         }
         return list;
     }



Mime
View raw message