You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2019/08/20 23:08:38 UTC
[sling-org-apache-sling-feature-launcher] branch issues/SLING-8483
updated: SLING-8483 - Streamlined the Iterator into Ordered List handling
This is an automated email from the ASF dual-hosted git repository.
andysch pushed a commit to branch issues/SLING-8483
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git
The following commit(s) were added to refs/heads/issues/SLING-8483 by this push:
new d3669ff SLING-8483 - Streamlined the Iterator into Ordered List handling
d3669ff is described below
commit d3669ff256db6f2ef2250d5684da4bb2dd0b18a6
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Tue Aug 20 16:08:26 2019 -0700
SLING-8483 - Streamlined the Iterator into Ordered List handling
---
.../sling/feature/launcher/impl/FeatureProcessor.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java b/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
index 2fd5bc7..5607f2d 100644
--- a/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
+++ b/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
@@ -22,6 +22,7 @@ import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
@@ -165,13 +166,13 @@ public class FeatureProcessor {
}
extensions: for(final Extension ext : app.getExtensions()) {
- List<ExtensionHandler> extensionHandlerList = new ArrayList<>();
- for (ExtensionHandler handler : ServiceLoader.load(ExtensionHandler.class, FeatureProcessor.class.getClassLoader())) {
- extensionHandlerList.add(handler);
- }
- List<ExtensionHandler> prioritizedExtensionHandlerList = extensionHandlerList.stream()
- .sorted(Comparator.comparingInt(ExtensionHandler::getPriority).reversed())
- .collect(Collectors.toList());
+ Iterator<ExtensionHandler> i = ServiceLoader.load(ExtensionHandler.class, FeatureProcessor.class.getClassLoader()).iterator();
+ // Stream the iterator, sort them based on Priority in reversed order and then collection into a list
+ List<ExtensionHandler> prioritizedExtensionHandlerList =
+ StreamSupport
+ .stream(Spliterators.spliteratorUnknownSize(i, Spliterator.ORDERED), false)
+ .sorted(Comparator.comparingInt(ExtensionHandler::getPriority).reversed())
+ .collect(Collectors.toList());
for (ExtensionHandler handler : prioritizedExtensionHandlerList)
{
if (handler.handle(new ExtensionContextImpl(ctx, config.getInstallation(), loadedFeatures), ext)) {