geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r779905 - /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
Date Fri, 29 May 2009 09:40:06 GMT
Author: gnodet
Date: Fri May 29 09:40:03 2009
New Revision: 779905

URL: http://svn.apache.org/viewvc?rev=779905&view=rev
Log:
Use a one pass search for best service reference

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java?rev=779905&r1=779904&r2=779905&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
Fri May 29 09:40:03 2009
@@ -294,34 +294,16 @@
             }
             int index = 0;
             if (length > 1) { /* if more than one service, select highest ranking */
-                int rankings[] = new int[length];
-                int count = 0;
                 int maxRanking = Integer.MIN_VALUE;
+                long minId = Long.MAX_VALUE;
                 for (int i = 0; i < length; i++) {
                     Object property = references.get(i).getProperty(Constants.SERVICE_RANKING);
                     int ranking = (property instanceof Integer) ? (Integer) property : 0;
-                    rankings[i] = ranking;
-                    if (ranking > maxRanking) {
+                    long id = (Long) references.get(i).getProperty(Constants.SERVICE_ID);
+                    if ((ranking > maxRanking) || (ranking == maxRanking && id
< minId)) {
                         index = i;
                         maxRanking = ranking;
-                        count = 1;
-                    } else {
-                        if (ranking == maxRanking) {
-                            count++;
-                        }
-                    }
-                }
-                // TODO: we could use a one pass search ...
-                if (count > 1) { /* if still more than one service, select lowest id */
-                    long minId = Long.MAX_VALUE;
-                    for (int i = 0; i < length; i++) {
-                        if (rankings[i] == maxRanking) {
-                            long id = (Long) references.get(i).getProperty(Constants.SERVICE_ID);
-                            if (id < minId) {
-                                index = i;
-                                minId = id;
-                            }
-                        }
+                        minId = id;
                     }
                 }
             }



Mime
View raw message