Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRESOLVER-628] Explicit cache key for prioritized components #601

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public LocalRepositoryManager newLocalRepositoryManager(RepositorySystemSession
requireNonNull(repository, "repository cannot be null");

PrioritizedComponents<LocalRepositoryManagerFactory> factories = PrioritizedComponents.reuseOrCreate(
session, localRepositoryManagerFactories, LocalRepositoryManagerFactory::getPriority);
session,
LocalRepositoryManagerFactory.class,
localRepositoryManagerFactories,
LocalRepositoryManagerFactory::getPriority);

List<NoLocalRepositoryManagerException> errors = new ArrayList<>();
for (PrioritizedComponent<LocalRepositoryManagerFactory> factory : factories.getEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public RepositoryConnector newRepositoryConnector(RepositorySystemSession sessio
}

PrioritizedComponents<RepositoryConnectorFactory> factories = PrioritizedComponents.reuseOrCreate(
session, connectorFactories, RepositoryConnectorFactory::getPriority);
session, RepositoryConnectorFactory.class, connectorFactories, RepositoryConnectorFactory::getPriority);

RemoteRepositoryFilter filter = remoteRepositoryFilterManager.getRemoteRepositoryFilter(session);
List<NoRepositoryConnectorException> errors = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public RepositoryLayout newRepositoryLayout(RepositorySystemSession session, Rem
requireNonNull(session, "session cannot be null");
requireNonNull(repository, "remote repository cannot be null");

PrioritizedComponents<RepositoryLayoutFactory> factories =
PrioritizedComponents.reuseOrCreate(session, layoutFactories, RepositoryLayoutFactory::getPriority);
PrioritizedComponents<RepositoryLayoutFactory> factories = PrioritizedComponents.reuseOrCreate(
session, RepositoryLayoutFactory.class, layoutFactories, RepositoryLayoutFactory::getPriority);

List<NoRepositoryLayoutException> errors = new ArrayList<>();
for (PrioritizedComponent<RepositoryLayoutFactory> factory : factories.getEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public Transporter newTransporter(RepositorySystemSession session, RemoteReposit
requireNonNull(session, "session cannot be null");
requireNonNull(repository, "repository cannot be null");

PrioritizedComponents<TransporterFactory> factories =
PrioritizedComponents.reuseOrCreate(session, transporterFactories, TransporterFactory::getPriority);
PrioritizedComponents<TransporterFactory> factories = PrioritizedComponents.reuseOrCreate(
session, TransporterFactory.class, transporterFactories, TransporterFactory::getPriority);

List<NoTransporterException> errors = new ArrayList<>();
for (PrioritizedComponent<TransporterFactory> factory : factories.getEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
*/
public final class PrioritizedComponents<T> {
/**
* Reuses or creates and stores (if session data does not contain yet) prioritized components under this key into
* given session. Same session is used to configure prioritized components.
* Reuses or creates and stores (if session data does not contain yet) prioritized components under certain key into
* given session. Same session is used to configure prioritized components, so priority sorted components during
* session are immutable and reusable.
* <p>
* The {@code components} are expected to be Sisu injected {@link Map<String, C>}-like component maps. There is a
* simple "change detection" in place, as injected maps are dynamic, they are atomically expanded or contracted
Expand All @@ -46,11 +47,14 @@ public final class PrioritizedComponents<T> {
*/
@SuppressWarnings("unchecked")
public static <C> PrioritizedComponents<C> reuseOrCreate(
RepositorySystemSession session, Map<String, C> components, Function<C, Float> priorityFunction) {
RepositorySystemSession session,
Class<C> discriminator,
Map<String, C> components,
Function<C, Float> priorityFunction) {
boolean cached = ConfigUtils.getBoolean(
session, ConfigurationProperties.DEFAULT_CACHED_PRIORITIES, ConfigurationProperties.CACHED_PRIORITIES);
if (cached) {
String key = PrioritizedComponents.class.getName() + ".pc" + Integer.toHexString(components.hashCode());
String key = PrioritizedComponents.class.getName() + ".pc." + discriminator.getName();
return (PrioritizedComponents<C>)
session.getData().computeIfAbsent(key, () -> create(session, components, priorityFunction));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ private Utils() {}

private static PrioritizedComponents<ArtifactDecoratorFactory> sortArtifactDecoratorFactories(
RepositorySystemSession session, Map<String, ArtifactDecoratorFactory> factories) {
return PrioritizedComponents.reuseOrCreate(session, factories, ArtifactDecoratorFactory::getPriority);
return PrioritizedComponents.reuseOrCreate(
session, ArtifactDecoratorFactory.class, factories, ArtifactDecoratorFactory::getPriority);
}

public static List<? extends ArtifactDecorator> getArtifactDecorators(
Expand All @@ -67,7 +68,8 @@ public static List<? extends ArtifactDecorator> getArtifactDecorators(

private static PrioritizedComponents<ArtifactGeneratorFactory> sortArtifactGeneratorFactories(
RepositorySystemSession session, Map<String, ArtifactGeneratorFactory> factories) {
return PrioritizedComponents.reuseOrCreate(session, factories, ArtifactGeneratorFactory::getPriority);
return PrioritizedComponents.reuseOrCreate(
session, ArtifactGeneratorFactory.class, factories, ArtifactGeneratorFactory::getPriority);
}

private static List<? extends ArtifactGenerator> doGetArtifactGenerators(
Expand Down Expand Up @@ -107,7 +109,8 @@ public static List<? extends ArtifactGenerator> getArtifactGenerators(

private static PrioritizedComponents<MetadataGeneratorFactory> sortMetadataGeneratorFactories(
RepositorySystemSession session, Map<String, MetadataGeneratorFactory> factories) {
return PrioritizedComponents.reuseOrCreate(session, factories, MetadataGeneratorFactory::getPriority);
return PrioritizedComponents.reuseOrCreate(
session, MetadataGeneratorFactory.class, factories, MetadataGeneratorFactory::getPriority);
}

private static List<? extends MetadataGenerator> doGetMetadataGenerators(
Expand Down