Author: pauls
Date: Sun Apr 13 12:05:16 2008
New Revision: 647610

URL: http://svn.apache.org/viewvc?rev=647610&view=rev
Log:
Reorder some statements to improve service lookup performance.

Modified:
    
felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java

Modified: 
felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java?rev=647610&r1=647609&r2=647610&view=diff
==============================================================================
--- 
felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
 (original)
+++ 
felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
 Sun Apr 13 12:05:16 2008
@@ -19,6 +19,7 @@
 package org.apache.felix.framework;
 
 import org.apache.felix.framework.util.Util;
+import org.apache.felix.moduleloader.IModule;
 import org.apache.felix.moduleloader.IWire;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
@@ -120,12 +121,9 @@
         // Get the package.
         String pkgName =
             Util.getClassPackage(className);
+        IModule current = ((FelixBundle) 
requester).getInfo().getCurrentModule();
         // Get package wiring from service requester.
-        IWire requesterWire = Util.getWire(
-            ((FelixBundle) requester).getInfo().getCurrentModule(), pkgName);
-        // Get package wiring from service provider.
-        IWire providerWire = Util.getWire(
-            ((FelixBundle) m_bundle).getInfo().getCurrentModule(), pkgName);
+        IWire requesterWire = Util.getWire(current, pkgName);
 
         // There are three situations that may occur here:
         //   1. The requester does not have a wire for the package.
@@ -144,11 +142,15 @@
         // Case 1: Always include service reference.
         if (requesterWire == null)
         {
-            // This is an intentional no-op.
+            return allow;
         }
+
+        // Get package wiring from service provider.
+        IWire providerWire = Util.getWire(current, pkgName);
+        
         // Case 2: Only include service reference if the service
         // object uses the same class as the requester.
-        else if (providerWire == null)
+        if (providerWire == null)
         {
             // If the provider is not the exporter of the requester's package,
             // then try to use the service registration to see if the 
requester's
@@ -158,8 +160,7 @@
                 try
                 {
                     // Load the class from the requesting bundle.
-                    Class requestClass =
-                        ((FelixBundle) 
requester).getInfo().getCurrentModule().getClass(className);
+                    Class requestClass = current.getClass(className);
                     // Get the service registration and ask it to check
                     // if the service object is assignable to the requesting
                     // bundle's class.
@@ -176,7 +177,7 @@
                 // O.k. the provider is the exporter of the requester's 
package, now check
                 // if the requester is wired to the latest version of the 
provider, if so
                 // then allow else don't (the provider has been updated but 
not refreshed).
-                allow = ((FelixBundle) m_bundle).getInfo().getCurrentModule() 
== requesterWire.getExporter();
+                allow = current == requesterWire.getExporter();
             }
         }
         // Case 3: Include service reference if the wires have the


Reply via email to