felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uiter...@apache.org
Subject svn commit: r1303396 - in /felix/trunk/dependencymanager/core: ./ src/main/java/org/apache/felix/dm/impl/ src/main/java/org/apache/felix/dm/impl/index/ src/main/java/org/apache/felix/dm/tracker/
Date Wed, 21 Mar 2012 14:09:20 GMT
Author: uiterlix
Date: Wed Mar 21 14:09:19 2012
New Revision: 1303396

URL: http://svn.apache.org/viewvc?rev=1303396&view=rev
Log:
Added synchronization blocks to ServiceTracker and AspectFilterIndex to solve and prevent
concurrency issues.
Fixed issue in AdapterServiceImpl which did not handle aspect services correctly.

Modified:
    felix/trunk/dependencymanager/core/   (props changed)
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java

Propchange: felix/trunk/dependencymanager/core/
------------------------------------------------------------------------------
    svn:mergeinfo = /felix/sandbox/uiterlix/dependencymanager/core:1293216-1303391

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java?rev=1303396&r1=1303395&r2=1303396&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
Wed Mar 21 14:09:19 2012
@@ -87,15 +87,24 @@ public class AdapterServiceImpl extends 
             ServiceReference ref = (ServiceReference) properties[0]; 
             Properties props = new Properties();
             String[] keys = ref.getPropertyKeys();
+            String serviceIdToTrack = null;
             for (int i = 0; i < keys.length; i++) {
                 String key = keys[i];
-                if (key.equals(Constants.SERVICE_ID) || key.equals(Constants.SERVICE_RANKING)
|| key.equals(DependencyManager.ASPECT) || key.equals(Constants.OBJECTCLASS)) {
-                    // do not copy these
+                if (key.equals(DependencyManager.ASPECT)) {
+                	// if we're handed an aspect fetch the aspect property as the service id
to track, but do not copy it
+                	serviceIdToTrack = ref.getProperty(key).toString();
+                }
+                if (key.equals(Constants.SERVICE_ID) || key.equals(Constants.SERVICE_RANKING)
|| key.equals(Constants.OBJECTCLASS)) {
+                    // do not copy these either
                 }
                 else {
                     props.put(key, ref.getProperty(key));
                 }
             }
+            if (serviceIdToTrack == null) {
+            	// we're not handed an aspect so we can use the service id to track
+            	serviceIdToTrack = ref.getProperty(Constants.SERVICE_ID).toString();
+            }
             if (m_serviceProperties != null) {
                 Enumeration e = m_serviceProperties.keys();
                 while (e.hasMoreElements()) {
@@ -107,8 +116,8 @@ public class AdapterServiceImpl extends 
             dependencies.remove(0);
             ServiceDependency dependency = m_manager.createServiceDependency()
             	 // create a dependency on both the service id we're adapting and possible aspects
for this given service id
-            	 .setService(m_adapteeInterface, "(|(" + Constants.SERVICE_ID + "=" + ref.getProperty(Constants.SERVICE_ID)

-            			 	+ ")(" + DependencyManager.ASPECT + "=" + ref.getProperty(Constants.SERVICE_ID)
+ "))")
+            	 .setService(m_adapteeInterface, "(|(" + Constants.SERVICE_ID + "=" + serviceIdToTrack

+            			 	+ ")(" + DependencyManager.ASPECT + "=" + serviceIdToTrack + "))")
                  .setRequired(true);
             if (m_autoConfig != null) {
                 dependency.setAutoConfig(m_autoConfig);
@@ -116,7 +125,7 @@ public class AdapterServiceImpl extends 
             if (m_add != null || m_change != null || m_remove != null || m_swap != null)
{
                 dependency.setCallbacks(m_add, m_change, m_remove, m_swap);
             }
-            
+
             Component service = m_manager.createComponent()
                 .setInterface(m_serviceInterfaces, props)
                 .setImplementation(m_serviceImpl)

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java?rev=1303396&r1=1303395&r2=1303396&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java
Wed Mar 21 14:09:19 2012
@@ -129,7 +129,10 @@ public class AspectFilterIndex implement
         List /* <ServiceReference> */ result = new ArrayList();
         FilterData data = getFilterData(clazz, filter);
         if (data != null) {
-            SortedSet /* <ServiceReference> */ list = (SortedSet) m_sidToServiceReferencesMap.get(Long.valueOf(data.serviceId));
+        	SortedSet /* <ServiceReference> */ list = null;
+        	synchronized (m_sidToServiceReferencesMap) {
+        		list = (SortedSet) m_sidToServiceReferencesMap.get(Long.valueOf(data.serviceId));
+			}
             if (list != null) {
                 Iterator iterator = list.iterator();
                 while (iterator.hasNext()) {

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java?rev=1303396&r1=1303395&r2=1303396&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
Wed Mar 21 14:09:19 2012
@@ -928,64 +928,78 @@ public class ServiceTracker implements S
         
         private ServiceReference highestTrackedCache(long serviceId) {
             Long sid = Long.valueOf(serviceId);
-            TreeSet services = (TreeSet) m_highestTrackedCache.get(sid);
-            if (services != null && services.size() > 0) {
-                ServiceReference result = (ServiceReference) services.last();
-                return result;
-            }
+            synchronized (this) {
+            	TreeSet services = (TreeSet) m_highestTrackedCache.get(sid);
+            	if (services != null && services.size() > 0) {
+            		ServiceReference result = (ServiceReference) services.last();
+            		return result;
+            	}
+			}
             return null;
         }
         
         private void addHighestTrackedCache(ServiceReference reference) {
             Long serviceId = ServiceUtil.getServiceIdObject(reference);
-            TreeSet services = (TreeSet) m_highestTrackedCache.get(serviceId);
-            if (services == null) {
-                services = new TreeSet();
-                m_highestTrackedCache.put(serviceId, services);
-            }
-            services.add(reference);
+            synchronized (this) {
+            	TreeSet services = (TreeSet) m_highestTrackedCache.get(serviceId);
+            	if (services == null) {
+            		services = new TreeSet();
+            		m_highestTrackedCache.put(serviceId, services);
+            	}
+            	services.add(reference);
+			}
         }
         
         private void removeHighestTrackedCache(ServiceReference reference) {
             Long serviceId = ServiceUtil.getServiceIdObject(reference);
-            TreeSet services = (TreeSet) m_highestTrackedCache.get(serviceId);
-            if (services != null) {
-                services.remove(reference);
-            }
+            synchronized (this) {
+            	TreeSet services = (TreeSet) m_highestTrackedCache.get(serviceId);
+            	if (services != null) {
+            		services.remove(reference);
+            	}
+			}
         }
         
         private void clearHighestTrackedCache() {
-            m_highestTrackedCache.clear();
+        	synchronized (this) {
+        		m_highestTrackedCache.clear();
+			}
         }
         
         private final HashMap m_highestHiddenCache = new HashMap();
         
         private ServiceReference highestHiddenCache(long serviceId) {
             Long sid = Long.valueOf(serviceId);
-            TreeSet services = (TreeSet) m_highestHiddenCache.get(sid);
-            if (services != null && services.size() > 0) {
-                ServiceReference result = (ServiceReference) services.last();
-                return result;
+            synchronized (this) {
+            	TreeSet services = (TreeSet) m_highestHiddenCache.get(sid);
+	            if (services != null && services.size() > 0) {
+	                ServiceReference result = (ServiceReference) services.last();
+	                return result;
+	            }
             }
             return null;
         }
         
         private void addHighestHiddenCache(ServiceReference reference) {
             Long serviceId = ServiceUtil.getServiceIdObject(reference);
-            TreeSet services = (TreeSet) m_highestHiddenCache.get(serviceId);
-            if (services == null) {
-                services = new TreeSet();
-                m_highestHiddenCache.put(serviceId, services);
-            }
-            services.add(reference);
+            synchronized (this) {
+            	TreeSet services = (TreeSet) m_highestHiddenCache.get(serviceId);
+            	if (services == null) {
+            		services = new TreeSet();
+            		m_highestHiddenCache.put(serviceId, services);
+            	}
+            	services.add(reference);
+			}
         }
         
         private void removeHighestHiddenCache(ServiceReference reference) {
             Long serviceId = ServiceUtil.getServiceIdObject(reference);
-            TreeSet services = (TreeSet) m_highestHiddenCache.get(serviceId);
-            if (services != null) {
-                services.remove(reference);
-            }
+            synchronized (this) {
+            	TreeSet services = (TreeSet) m_highestHiddenCache.get(serviceId);
+            	if (services != null) {
+            		services.remove(reference);
+            	}
+			}
         }
 
         /**



Mime
View raw message