[jboss-cvs] JBossAS SVN: r97182 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 30 13:34:13 EST 2009
Author: alesj
Date: 2009-11-30 13:34:12 -0500 (Mon, 30 Nov 2009)
New Revision: 97182
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
Log:
No need for duplicate getServiceRef call.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-30 17:51:29 UTC (rev 97181)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-30 18:34:12 UTC (rev 97182)
@@ -39,8 +39,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
@@ -1200,7 +1198,7 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- Collection<ControllerContext> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
+ Collection<ServiceReference> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
{
Set<ControllerContext> contexts;
KernelController controller = kernel.getController();
@@ -1230,9 +1228,10 @@
if (filter == null)
filter = NoFilter.INSTANCE;
- // Use a sorted set to order services according to spec
- SortedSet<ControllerContext> result = new TreeSet<ControllerContext>(ContextComparator.INSTANCE);
- for (ControllerContext context : contexts)
+ List<ControllerContext> sorted = new ArrayList<ControllerContext>(contexts);
+ Collections.sort(sorted, ContextComparator.INSTANCE); // Sort by the spec, should bubble up
+ Collection<ServiceReference> result = new ArrayList<ServiceReference>();
+ for (ControllerContext context : sorted)
{
if (isUnregistered(context) == false)
{
@@ -1243,7 +1242,7 @@
{
// Check the assignability
if (checkAssignable == false || MDRUtils.isAssignableTo(context, bundle))
- result.add(context);
+ result.add(ref);
}
}
}
@@ -1260,12 +1259,11 @@
*/
ServiceReference getServiceReference(AbstractBundleState bundle, String clazz)
{
- Collection<ControllerContext> contexts = getServices(bundle, clazz, null, true);
- if (contexts == null || contexts.isEmpty())
+ Collection<ServiceReference> services = getServices(bundle, clazz, null, true);
+ if (services == null || services.isEmpty())
return null;
- ControllerContext context = contexts.iterator().next();
- return getServiceReferenceForContext(context);
+ return services.iterator().next();
}
/**
@@ -1279,17 +1277,11 @@
*/
ServiceReference[] getServiceReferences(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
{
- Collection<ControllerContext> contexts = getServices(bundle, clazz, filter, checkAssignable);
- if (contexts == null || contexts.isEmpty())
+ Collection<ServiceReference> services = getServices(bundle, clazz, filter, checkAssignable);
+ if (services == null || services.isEmpty())
return null;
- ServiceReference[] result = new ServiceReference[contexts.size()];
-
- int i = 0;
- for (ControllerContext context : contexts)
- result[i++] = getServiceReferenceForContext(context);
-
- return result;
+ return services.toArray(new ServiceReference[services.size()]);
}
/**
More information about the jboss-cvs-commits
mailing list