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

Improve InitialLoadContext loadedResources key - for unique loaded resources #180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rbygrave
Copy link
Contributor

@rbygrave rbygrave commented Oct 9, 2024

This is in preparation for using the existing InitialLoadContext.loadedResources set to determine if a resource has already been loaded.

@rbygrave rbygrave self-assigned this Oct 9, 2024
@rbygrave rbygrave added this to the 4.1 milestone Oct 9, 2024
@agentgt
Copy link

agentgt commented Oct 9, 2024

To relate how this would change if we did the #176 but where:

public @Nullable KeyValuesSource resolve(URI uri, ... some other stuff like where the URI came from and env) {
}

public KeyValues load(KeyValuesSource source) {
}

In our system there is not just File and Classpath Sources and they are not a singleton.

KeyValuesSource has flags (and methods but doing an EnumSet is easier than adding tons of boolean methods) where you can test whether it is unique.

KeyValuesSource source = resolve(...);
if (source.isUnqiue()) { // or check some enum is set like isFlag(SomeEnum) this is the LoadFlags stuff I have talked about in the past.
}

EDIT to make it clear there would be (replace KeyValues with Config if you like).

  • FileKeyValuesSource
  • ClasspathKeyValuesSource

These get resolved either by URI or by programmatically creating them.

EDIT again this is just to give ideas based on what we did:

	public interface KeyValuesSource {
		public URI getUri();
		public @Nullable KeyValue getReference();
		public @Nullable MediaType getMediaType();
		public KeyValues getParameters();
		public Set<LoadFlag> getLoadFlags(); }

The parser is

public interface KeyValuesParser {

	public Iterable<KeyValue> parse(
			KeyValuesSource source,
			InputStream is)
			throws IOException;
}

There is some screwed up instanceof which I would have done with sealed classes where a KeyValuesSource can do the loading itself because it implements KeyValuesLoader and thus does not need to be parsed (e.g. environment variables for example).

public interface KeyValuesLoader {
   public Iterable<KeyValue> load();
}

If a KeyValuesSource implements KeyValuesLoader we don't do the parsing.

A KeyValue unlike Entry<String,String> has more information like where it came from and what it was before it was interpolated etc.

cc @SentryMan

@agentgt agentgt mentioned this pull request Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants