Class DefaultFolderConfigRef<T>

java.lang.Object
tech.guilhermekaua.spigotboot.config.folder.DefaultFolderConfigRef<T>
Type Parameters:
T - the item type
All Implemented Interfaces:
Supplier<FolderConfigSnapshot<T>>, FolderConfigRef<T>

public final class DefaultFolderConfigRef<T> extends Object implements FolderConfigRef<T>
Default implementation of FolderConfigRef.

This class provides thread-safe access to the folder config snapshot using atomic reference swapping. All reads are lock-free.

  • Constructor Details

    • DefaultFolderConfigRef

      public DefaultFolderConfigRef(@NotNull @NotNull Class<T> itemType, @NotNull @NotNull String folderConfigName, @NotNull @NotNull FolderConfigEditor<T> editor, @NotNull @NotNull Runnable reloadAllHandler, @NotNull @NotNull Consumer<String> reloadItemHandler)
      Creates a new folder config reference.
      Parameters:
      itemType - the item type class
      folderConfigName - the folder config name
      editor - the folder config editor
      reloadAllHandler - handler for reloading all items
      reloadItemHandler - handler for reloading a single item
  • Method Details

    • get

      @NotNull public @NotNull FolderConfigSnapshot<T> get()
      Description copied from interface: FolderConfigRef
      Gets the current snapshot of the folder config.
      Specified by:
      get in interface FolderConfigRef<T>
      Specified by:
      get in interface Supplier<T>
      Returns:
      the current snapshot, never null
    • edit

      @NotNull public @NotNull FolderConfigEditor<T> edit()
      Description copied from interface: FolderConfigRef
      Gets an editor for modifying the folder config.

      The editor provides create/update/delete operations that persist to disk and update the in-memory snapshot atomically.

      Specified by:
      edit in interface FolderConfigRef<T>
      Returns:
      the folder config editor
    • reloadAll

      public void reloadAll()
      Description copied from interface: FolderConfigRef
      Reloads the entire folder config from disk.

      This scans the folder, loads all matching files, and swaps the snapshot atomically. Listeners are notified of any changes.

      Specified by:
      reloadAll in interface FolderConfigRef<T>
    • reloadItem

      public void reloadItem(@NotNull @NotNull String id)
      Description copied from interface: FolderConfigRef
      Reloads a single item from disk.

      If the file no longer exists, the item is removed from the folder config. If this is a new file, the item is added. Listeners are notified.

      Specified by:
      reloadItem in interface FolderConfigRef<T>
      Parameters:
      id - the item ID to reload
    • addListener

      public void addListener(@NotNull @NotNull FolderConfigChangeListener<T> listener)
      Description copied from interface: FolderConfigRef
      Adds a listener for folder config changes.
      Specified by:
      addListener in interface FolderConfigRef<T>
      Parameters:
      listener - the listener to add
    • removeListener

      public void removeListener(@NotNull @NotNull FolderConfigChangeListener<T> listener)
      Description copied from interface: FolderConfigRef
      Removes a previously added listener.
      Specified by:
      removeListener in interface FolderConfigRef<T>
      Parameters:
      listener - the listener to remove
    • getItemType

      @NotNull public @NotNull Class<T> getItemType()
      Description copied from interface: FolderConfigRef
      Gets the item type class.
      Specified by:
      getItemType in interface FolderConfigRef<T>
      Returns:
      the item class
    • getFolderConfigName

      @NotNull public @NotNull String getFolderConfigName()
      Description copied from interface: FolderConfigRef
      Gets the folder config name.
      Specified by:
      getFolderConfigName in interface FolderConfigRef<T>
      Returns:
      the folder config name
    • updateSnapshot

      public void updateSnapshot(@NotNull @NotNull FolderConfigSnapshot<T> newSnapshot, @NotNull @NotNull List<FolderConfigItemChange<T>> changes)
      Updates the snapshot and notifies listeners of changes.
      Parameters:
      newSnapshot - the new snapshot
      changes - the list of changes
    • setSnapshot

      public void setSnapshot(@NotNull @NotNull FolderConfigSnapshot<T> newSnapshot)
      Updates the snapshot without notifying listeners.
      Parameters:
      newSnapshot - the new snapshot
    • notifyListeners

      public void notifyListeners(@NotNull @NotNull FolderConfigItemChange<T> change)
      Notifies listeners of a single change.
      Parameters:
      change - the change