Issue #4340 - Changes from review

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-03-02 10:16:38 +11:00
parent 97c55e27cc
commit 355d21317b
4 changed files with 10 additions and 6 deletions

View File

@ -812,7 +812,9 @@ public class AnnotationConfiguration extends AbstractConfiguration
long start = 0;
if (LOG.isDebugEnabled())
start = System.nanoTime();
List<ServletContainerInitializer> scis = ServiceLoader.load(ServletContainerInitializer.class).stream().flatMap(TypeUtil::providerMap).collect(Collectors.toList());
List<ServletContainerInitializer> scis = ServiceLoader.load(ServletContainerInitializer.class).stream()
.flatMap(TypeUtil::providerMap)
.collect(Collectors.toList());
if (LOG.isDebugEnabled())
LOG.debug("Service loaders found in {}ms", (TimeUnit.MILLISECONDS.convert((System.nanoTime() - start), TimeUnit.NANOSECONDS)));

View File

@ -19,9 +19,9 @@
package org.eclipse.jetty.http;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Collectors;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
@ -43,11 +43,10 @@ public class PreEncodedHttpField extends HttpField
static
{
List<HttpFieldPreEncoder> encoders = new ArrayList<>();
ServiceLoader.load(HttpFieldPreEncoder.class).stream()
List<HttpFieldPreEncoder> encoders = ServiceLoader.load(HttpFieldPreEncoder.class).stream()
.flatMap(TypeUtil::providerMap)
.filter(encoder -> index(encoder.getHttpVersion()) >= 0)
.forEach(encoders::add);
.collect(Collectors.toList());
LOG.debug("HttpField encoders loaded: {}", encoders);
int size = encoders.size();

View File

@ -78,7 +78,8 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
static
{
ServiceLoader.load(Authenticator.Factory.class).stream()
.flatMap(TypeUtil::providerMap).forEach(__knownAuthenticatorFactories::add);
.flatMap(TypeUtil::providerMap)
.forEach(__knownAuthenticatorFactories::add);
__knownAuthenticatorFactories.add(new DefaultAuthenticatorFactory());
}

View File

@ -760,6 +760,8 @@ public class TypeUtil
* Used on a {@link ServiceLoader#stream()} with {@link Stream#flatMap(Function)},
* so that in the case a {@link ServiceConfigurationError} is thrown it warns and
* continues iterating through the service loader.
* <br>Usage Example:
* <p>{@code ServiceLoader.load(Service.class).stream().flatMap(TypeUtil::providerMap).collect(Collectors.toList());}</p>
* @param <T> The class of the service type.
* @param provider The service provider to instantiate.
* @return a stream of the loaded service providers.