felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r987468 - /felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java
Date Fri, 20 Aug 2010 12:12:49 GMT
Author: marrs
Date: Fri Aug 20 12:12:49 2010
New Revision: 987468

URL: http://svn.apache.org/viewvc?rev=987468&view=rev
Log:
Fixed a scenario where aspects that were part of the initial set of tracked services were
not correctly identified as such, causing them to show up (instead of being properly hidden).

Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java?rev=987468&r1=987467&r2=987468&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java
Fri Aug 20 12:12:49 2010
@@ -878,6 +878,7 @@ public class ServiceTracker implements S
          * @param ref the service reference to add to the hidden list
          */
         private void hide(ServiceReference ref) {
+            if (DEBUG) { System.out.println("ServiceTracker.Tracked.hide " + ServiceUtil.toString(ref));
}
             m_hidden.add(ref);
         }
         
@@ -887,6 +888,7 @@ public class ServiceTracker implements S
          * @param ref the service reference to remove from the hidden list
          */
         private void unhide(ServiceReference ref) {
+            if (DEBUG) { System.out.println("ServiceTracker.Tracked.unhide " + ServiceUtil.toString(ref));
}
             m_hidden.remove(ref);
         }
 	    
@@ -896,6 +898,58 @@ public class ServiceTracker implements S
 		Tracked() {
 			super();
 		}
+		
+		void setInitial(Object[] list) {
+		    if (list == null) {
+		        return;
+		    }
+		    // we need to split this list into the highest matching service references for each
aspect
+		    // and a list of 'hidden' service references
+		    int counter = list.length;
+		    for (int i = 0; i < list.length; i++) {
+		        ServiceReference sr = (ServiceReference) list[i];
+		        if (sr != null) {
+		            for (int j = 0; j < list.length; j++) {
+		                ServiceReference sr2 = (ServiceReference) list[j];
+		                if (sr2 != null && j != i) {
+		                    long sid = ServiceUtil.getServiceId(sr);
+                            long sid2 = ServiceUtil.getServiceId(sr2);
+                            if (sid == sid2) {
+                                long r = ServiceUtil.getRanking(sr);
+                                long r2 = ServiceUtil.getRanking(sr2);
+                                if (r > r2) {
+                                    if (DEBUG) { System.out.println("ServiceTracker.Tracked.setInitial:
hiding " + ServiceUtil.toString(sr2)); }
+                                    hide(sr2);
+                                    list[j] = null;
+                                    counter--;
+                                }
+                                else {
+                                    if (DEBUG) { System.out.println("ServiceTracker.Tracked.setInitial:
hiding " + ServiceUtil.toString(sr)); }
+                                    hide(sr);
+                                    list[i] = null;
+                                    counter--;
+                                    break;
+                                }
+                            }
+		                }
+		            }
+		        }
+		    }
+		    if (counter > 0) {
+		        Object[] result = new Object[counter];
+		        int index = 0;
+		        for (int i = 0; i < list.length; i++) {
+		            if (list[i] != null) {
+                        if (DEBUG) { System.out.println("ServiceTracker.Tracked.setInitial:
propagating " + ServiceUtil.toString((ServiceReference) list[i])); }
+		                result[index] = list[i];
+		                index++;
+		            }
+		        }
+		        // we only invoke super if we actually have
+		        // results in our initial list
+		        super.setInitial(result);
+		    }
+		}
 
 		/**
 		 * <code>ServiceListener</code> method for the



Mime
View raw message