felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uiter...@apache.org
Subject svn commit: r1293216 - /felix/sandbox/uiterlix/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
Date Fri, 24 Feb 2012 12:20:52 GMT
Author: uiterlix
Date: Fri Feb 24 12:20:52 2012
New Revision: 1293216

URL: http://svn.apache.org/viewvc?rev=1293216&view=rev
Log:
added synchronization to fix threadsafety of the ServiceTracker.

Modified:
    felix/sandbox/uiterlix/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java

Modified: felix/sandbox/uiterlix/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java?rev=1293216&r1=1293215&r2=1293216&view=diff
==============================================================================
--- felix/sandbox/uiterlix/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
(original)
+++ felix/sandbox/uiterlix/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
Fri Feb 24 12:20:52 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