Class ConfigReferenceManager

java.lang.Object
tech.guilhermekaua.spigotboot.config.reference.ConfigReferenceManager

public class ConfigReferenceManager extends Object
Manages config reference resolution infrastructure.
  • 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 lookups
      logger - 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 lookups
      errorHandler - the error handler for reference resolution errors
  • Method Details

    • getPreprocessor

      @NotNull public @NotNull ReferenceResolvingPreprocessor getPreprocessor()
      Gets the preprocessor for binder integration.

      This preprocessor resolves ${...} references during binding.

      Returns:
      the preprocessor
    • getResolver

      @NotNull public @NotNull ConfigReferenceResolver getResolver()
      Gets the reference resolver.
      Returns:
      the resolver
    • getDependencyGraph

      @NotNull public @NotNull DependencyGraph<ReferenceKey> 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 scanned
      node - the config node to scan
    • getLoadOrder

      @NotNull public @NotNull List<ReferenceKey> getLoadOrder() throws CycleDetectedException
      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

      @NotNull public @NotNull Optional<List<ReferenceKey>> detectCycle()
      Checks if the dependency graph has a cycle.
      Returns:
      the cycle chain if exists, empty otherwise
    • getDependentsOf

      @NotNull public @NotNull Set<ReferenceKey> getDependentsOf(@NotNull @NotNull ReferenceKey key)
      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

      @NotNull public @NotNull Map<ReferenceKey,Set<ReferenceKey>> 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 changed
      newNode - 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

      public void setCurrentSourceKey(@NotNull @NotNull ReferenceKey sourceKey)
      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

      public boolean isReference(@Nullable @Nullable String value)
      Checks if a string is a reference pattern.
      Parameters:
      value - the string to check
      Returns:
      true if it matches the reference pattern