Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into doc/perf-main
Browse files Browse the repository at this point in the history
  • Loading branch information
vy committed May 21, 2024
2 parents 611664b + cfedc22 commit f0f523e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,7 @@ public RecyclerFactory defaultRecyclerFactory(
.findFirst()
.orElse(null);
if (matchingProvider != null) {
@Nullable final RecyclerFactory factory = matchingProvider.createForEnvironment(environment);
if (factory != null) {
return factory;
} else {
statusLogger.error(
"Configured recycler factory provider `{}` is not applicable for the current environment! Available recycler factory providers: {}. Will choose the first one available for the current environment.",
providerName,
providerNames);
}
return matchingProvider.createForEnvironment(environment);
} else {
statusLogger.error(
"Configured recycler factory provider `{}` is not found! Available recycler factory providers: {}. Will choose the first one available for the current environment.",
Expand All @@ -152,7 +144,6 @@ public RecyclerFactory defaultRecyclerFactory(
// Fallback to the first available provider
return providers.stream()
.map(provider -> provider.createForEnvironment(environment))
.filter(Objects::nonNull)
.findFirst()
.orElseThrow(() -> new IllegalStateException(
"None of the available recycler factory providers are found to be available for the current environment: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.logging.log4j.kit.recycler;

import edu.umd.cs.findbugs.annotations.Nullable;
import org.apache.logging.log4j.kit.env.PropertyEnvironment;
import org.apache.logging.log4j.kit.recycler.internal.DummyRecyclerFactoryProvider;

Expand Down Expand Up @@ -51,14 +50,9 @@ default int getOrder() {

/**
* Creates a recycler factory for the provided environment.
* <p>
* The return value can be null indicating that the recycler factory is not available for the provided environment.
* For instance, the provider of a {@link ThreadLocal}-based recycler factory can return null if the environment is of a web application.
* </p>
*
* @param environment an environment
* @return either a recycler factory instance, or null, if the associated recycler factory is not available for the given environment
* @return a recycler factory instance for the given environment
*/
@Nullable
RecyclerFactory createForEnvironment(PropertyEnvironment environment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public String getName() {
@Override
public RecyclerFactory createForEnvironment(final PropertyEnvironment environment) {
requireNonNull(environment, "environment");

final int capacity = environment.getProperty(RecyclerProperties.class).capacity();
return new QueueingRecyclerFactory(capacity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ private RecyclerFactoryTestUtil() {}
if (capacity != null) {
properties.put("recycler.capacity", capacity.toString());
}
final PropertyEnvironment env = new TestPropertyEnvironment(properties);
final PropertyEnvironment environment = new TestPropertyEnvironment(properties);
return ServiceLoaderUtil.safeStream(
RecyclerFactoryProvider.class,
ServiceLoader.load(
RecyclerFactoryProvider.class, RecyclerFactoryTestUtil.class.getClassLoader()),
StatusLogger.getLogger())
.filter(p -> factory.equals(p.getName()))
.filter(factoryProvider -> factory.equals(factoryProvider.getName()))
.findFirst()
.map(p -> p.createForEnvironment(env))
.map(factoryProvider -> factoryProvider.createForEnvironment(environment))
.orElse(null);
}
}

0 comments on commit f0f523e

Please sign in to comment.