FELIX-4692 Improve service access time
Applying patch FELIX-4692-2.patch:
* Guard matches.retainAll(caps) in CapabilitySet.match(Set, SimpleFilter)
* Return Collection from ServiceRegistry.getServiceReferences(String, SimpleFilter)
instead of creating a new ArrayList
* Use SimpleFilter.MATCH_ALL filter for service access without a service
class instead of SimpleFilter.PRESENT
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1649858 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index b7205fc..6400074 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -3532,27 +3532,26 @@
}
// Ask the service registry for all matching service references.
- final List refList = m_registry.getServiceReferences(className, filter);
+ final Collection refList = m_registry.getServiceReferences(className, filter);
// Filter on assignable references
if (checkAssignable)
{
- for (int refIdx = 0; (refList != null) && (refIdx < refList.size()); refIdx++)
+ for (Iterator refIter = refList.iterator(); refIter.hasNext();)
{
// Get the current service reference.
- ServiceReference ref = (ServiceReference) refList.get(refIdx);
+ ServiceReference ref = (ServiceReference) refIter.next();
// Now check for castability.
if (!Util.isServiceAssignable(bundle, ref))
{
- refList.remove(refIdx);
- refIdx--;
+ refIter.remove();
}
}
}
// If the requesting bundle is the system bundle, ignore the effects of the findhooks
- List resRefList = (bundle == this ? new ArrayList(refList) : refList);
+ Collection resRefList = (bundle == this ? new ArrayList(refList) : refList);
// activate findhooks
Set<ServiceReference<org.osgi.framework.hooks.service.FindHook>> findHooks =
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
index d95706b..7bd01d2 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
@@ -19,6 +19,7 @@
package org.apache.felix.framework;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
@@ -239,12 +240,12 @@
}
}
- public synchronized List getServiceReferences(String className, SimpleFilter filter)
+ public synchronized Collection getServiceReferences(String className, SimpleFilter filter)
{
if ((className == null) && (filter == null))
{
// Return all services.
- filter = new SimpleFilter(Constants.OBJECTCLASS, "*", SimpleFilter.PRESENT);
+ filter = new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
}
else if ((className != null) && (filter == null))
{
@@ -261,9 +262,7 @@
}
// else just use the specified filter.
- Set<BundleCapability> matches = m_regCapSet.match(filter, false);
-
- return new ArrayList<BundleCapability>(matches);
+ return m_regCapSet.match(filter, false);
}
public synchronized ServiceReference<?>[] getServicesInUse(Bundle bundle)
diff --git a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
index 982957e..8f0c605 100644
--- a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
+++ b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
@@ -239,7 +239,10 @@
if (existingCaps != null)
{
matches.addAll(existingCaps);
- matches.retainAll(caps);
+ if (caps != m_capSet)
+ {
+ matches.retainAll(caps);
+ }
}
}
else