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>
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 Summary
ConstructorsConstructorDescriptionDefaultFolderConfigRef(@NotNull Class<T> itemType, @NotNull String folderConfigName, @NotNull FolderConfigEditor<T> editor, @NotNull Runnable reloadAllHandler, @NotNull Consumer<String> reloadItemHandler) Creates a new folder config reference. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(@NotNull FolderConfigChangeListener<T> listener) Adds a listener for folder config changes.@NotNull FolderConfigEditor<T>edit()Gets an editor for modifying the folder config.@NotNull FolderConfigSnapshot<T>get()Gets the current snapshot of the folder config.@NotNull StringGets the folder config name.Gets the item type class.voidnotifyListeners(@NotNull FolderConfigItemChange<T> change) Notifies listeners of a single change.voidReloads the entire folder config from disk.voidreloadItem(@NotNull String id) Reloads a single item from disk.voidremoveListener(@NotNull FolderConfigChangeListener<T> listener) Removes a previously added listener.voidsetSnapshot(@NotNull FolderConfigSnapshot<T> newSnapshot) Updates the snapshot without notifying listeners.voidupdateSnapshot(@NotNull FolderConfigSnapshot<T> newSnapshot, @NotNull List<FolderConfigItemChange<T>> changes) Updates the snapshot and notifies listeners of changes.
-
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 classfolderConfigName- the folder config nameeditor- the folder config editorreloadAllHandler- handler for reloading all itemsreloadItemHandler- handler for reloading a single item
-
-
Method Details
-
get
Description copied from interface:FolderConfigRefGets the current snapshot of the folder config. -
edit
Description copied from interface:FolderConfigRefGets 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:
editin interfaceFolderConfigRef<T>- Returns:
- the folder config editor
-
reloadAll
public void reloadAll()Description copied from interface:FolderConfigRefReloads 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:
reloadAllin interfaceFolderConfigRef<T>
-
reloadItem
Description copied from interface:FolderConfigRefReloads 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:
reloadItemin interfaceFolderConfigRef<T>- Parameters:
id- the item ID to reload
-
addListener
Description copied from interface:FolderConfigRefAdds a listener for folder config changes.- Specified by:
addListenerin interfaceFolderConfigRef<T>- Parameters:
listener- the listener to add
-
removeListener
Description copied from interface:FolderConfigRefRemoves a previously added listener.- Specified by:
removeListenerin interfaceFolderConfigRef<T>- Parameters:
listener- the listener to remove
-
getItemType
Description copied from interface:FolderConfigRefGets the item type class.- Specified by:
getItemTypein interfaceFolderConfigRef<T>- Returns:
- the item class
-
getFolderConfigName
Description copied from interface:FolderConfigRefGets the folder config name.- Specified by:
getFolderConfigNamein interfaceFolderConfigRef<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 snapshotchanges- the list of changes
-
setSnapshot
Updates the snapshot without notifying listeners.- Parameters:
newSnapshot- the new snapshot
-
notifyListeners
Notifies listeners of a single change.- Parameters:
change- the change
-