Class ConfigReferenceManager
java.lang.Object
tech.guilhermekaua.spigotboot.config.reference.ConfigReferenceManager
Manages config reference resolution infrastructure.
-
Constructor Summary
ConstructorsConstructorDescriptionConfigReferenceManager(@NotNull DefaultConfigManager configManager, @NotNull Logger logger) Creates a new reference manager with default error handling.ConfigReferenceManager(@NotNull DefaultConfigManager configManager, @NotNull ConfigReferenceErrorHandler errorHandler) Creates a new reference manager with custom error handling. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the current source key.voidClears all dependency tracking.@NotNull Optional<List<ReferenceKey>>Checks if the dependency graph has a cycle.@NotNull DependencyGraph<ReferenceKey>Gets the dependency graph.@NotNull Set<ReferenceKey>getDependentsOf(@NotNull ReferenceKey key) Gets all configs that depend (transitively) on the given config.@NotNull Set<ReferenceKey>getImpactedKeys(@NotNull ReferenceKey changedKey) Gets keys impacted by a change to the given key.@NotNull List<ReferenceKey>Gets the topological load order for all registered configs.@NotNull List<ReferenceKey>getLoadOrderForSubset(@NotNull Set<ReferenceKey> keys) Gets topological order for a subset of keys.@NotNull ReferenceResolvingPreprocessorGets the preprocessor for binder integration.@NotNull ConfigReferenceResolverGets the reference resolver.@NotNull Map<ReferenceKey,Set<ReferenceKey>> Gets the reverse dependencies map.booleanisReference(@Nullable String value) Checks if a string is a reference pattern.voidPrepares for full reload by clearing all dependencies.@Nullable ConfigNoderesolveReference(@NotNull String reference, @NotNull ReferenceKey sourceKey) Resolves a reference string to its target node.voidscanAndRegister(@NotNull ReferenceKey sourceKey, @NotNull ConfigNode node) Scans a config node for references and registers them in the graph.voidsetCurrentSourceKey(@NotNull ReferenceKey sourceKey) Sets the current source key for resolution context.voidupdateDependenciesForKey(@NotNull ReferenceKey key, @NotNull ConfigNode newNode) Updates dependencies for a key after its node changed.
-
Constructor Details
-
ConfigReferenceManager
public ConfigReferenceManager(@NotNull @NotNull DefaultConfigManager configManager, @NotNull @NotNull Logger logger) Creates a new reference manager with default error handling.- Parameters:
configManager- the config manager for lookupslogger- the logger for error messages
-
ConfigReferenceManager
public ConfigReferenceManager(@NotNull @NotNull DefaultConfigManager configManager, @NotNull @NotNull ConfigReferenceErrorHandler errorHandler) Creates a new reference manager with custom error handling.- Parameters:
configManager- the config manager for lookupserrorHandler- the error handler for reference resolution errors
-
-
Method Details
-
getPreprocessor
Gets the preprocessor for binder integration.This preprocessor resolves
${...}references during binding.- Returns:
- the preprocessor
-
getResolver
Gets the reference resolver.- Returns:
- the resolver
-
getDependencyGraph
Gets the dependency graph.- Returns:
- the graph
-
scanAndRegister
public void scanAndRegister(@NotNull @NotNull ReferenceKey sourceKey, @NotNull @NotNull ConfigNode node) Scans a config node for references and registers them in the graph.- Parameters:
sourceKey- the key of the config being scannednode- the config node to scan
-
getLoadOrder
Gets the topological load order for all registered configs.Configs that are depended upon come first.
- Returns:
- the load order
- Throws:
CycleDetectedException- if a cycle is detected
-
detectCycle
Checks if the dependency graph has a cycle.- Returns:
- the cycle chain if exists, empty otherwise
-
getDependentsOf
Gets all configs that depend (transitively) on the given config.Used for reload propagation - when config X changes, all its dependents need to be re-resolved.
- Parameters:
key- the config key- Returns:
- set of dependent config keys
-
getReverseDependencies
Gets the reverse dependencies map.- Returns:
- map from each key to its dependents
-
clearDependencies
public void clearDependencies()Clears all dependency tracking.Call this before a full reload to rebuild the graph.
-
resetDependencies
public void resetDependencies()Prepares for full reload by clearing all dependencies.Alias for
clearDependencies()with a more descriptive name. -
updateDependenciesForKey
public void updateDependenciesForKey(@NotNull @NotNull ReferenceKey key, @NotNull @NotNull ConfigNode newNode) Updates dependencies for a key after its node changed.Removes old outgoing edges and scans for new references.
- Parameters:
key- the key that changednewNode- the new node to scan for references
-
getImpactedKeys
@NotNull public @NotNull Set<ReferenceKey> getImpactedKeys(@NotNull @NotNull ReferenceKey changedKey) Gets keys impacted by a change to the given key.Includes the key itself plus all transitive dependents.
- Parameters:
changedKey- the key that changed- Returns:
- set of impacted keys (includes changedKey)
-
getLoadOrderForSubset
@NotNull public @NotNull List<ReferenceKey> getLoadOrderForSubset(@NotNull @NotNull Set<ReferenceKey> keys) throws CycleDetectedException Gets topological order for a subset of keys.- Parameters:
keys- the keys to order- Returns:
- ordered list (dependencies first)
- Throws:
CycleDetectedException- if a cycle exists in the subset
-
setCurrentSourceKey
Sets the current source key for resolution context.Call this before binding a config to provide context for error messages.
- Parameters:
sourceKey- the key of the config being bound
-
clearCurrentSourceKey
public void clearCurrentSourceKey()Clears the current source key. -
resolveReference
@Nullable public @Nullable ConfigNode resolveReference(@NotNull @NotNull String reference, @NotNull @NotNull ReferenceKey sourceKey) Resolves a reference string to its target node.- Parameters:
reference- the reference string (e.g., "${items:custom_item}")sourceKey- the key of the config containing the reference- Returns:
- the resolved node, or null if not found
-
isReference
Checks if a string is a reference pattern.- Parameters:
value- the string to check- Returns:
- true if it matches the reference pattern
-