Class Backend
java.lang.Object
org.polyfrost.oneconfig.api.config.v1.backend.Backend
A backend is a storage system for ConfigTrees
It handles getting and putting ConfigTrees and also serializing and deserializing them
It handles getting and putting ConfigTrees and also serializing and deserializing them
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected static final org.apache.logging.log4j.Loggerstatic final StringTrees marked with this metadata are listed in the UI only such as Mod Menu compat entries
They are tracked in memory but never loaded from or written to backend storagestatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanExplicitly mark a tree as corrupted
The given tree if present will be untracked by this backend
this method is also automatically called when a tree fails to load (implementation specific operation)protected abstract booleanfinal booleanUntrack and permanently delete the tree with the given IDprotected abstract booleanbooleanfinal Treefinal @UnmodifiableView Collection<Tree> getTrees()final @Nullable TreeLoad a tree with the given IDfinal booleanLoad the tree with data stored in this backendprotected abstract TreeLoad in a tree with the given ID
Returns null if the tree does not existprotected voidRegister the given config with the system
This is a hybrid of the load and save methods depending on the state of the given tree
New trees will be saved to the backend
Existing trees will be loaded and have the backend data overwritten onto them
NOTE do NOT use the parameter tree after this method is called because it may have been cleared
Use the returned tree insteadprotected voidrequestUpdate(String id) Request that the tree with the given ID needs to be updated for example when the file has been edited externallyfinal booleanSave a tree with the given IDfinal booleanSave the provided tree to the backend
If it is not registered when this is called it will be registeredprotected abstract booleanfinal voidsaveAll()Save all trees registered to this backendfinal voidSave all trees under the given pathfinal @Nullable Treeunregister(String id) Stops tracking a tree without deleting its stored data.
-
Field Details
-
LOGGER
protected static final org.apache.logging.log4j.Logger LOGGER -
UI_ONLY_METADATA
Trees marked with this metadata are listed in the UI only such as Mod Menu compat entries
They are tracked in memory but never loaded from or written to backend storage- See Also:
-
UI_PLACEHOLDER_METADATA
- See Also:
-
CUSTOM_SAVE_TRACKED_METADATA
- See Also:
-
CUSTOM_SAVE_DIRTY_METADATA
- See Also:
-
-
Constructor Details
-
Backend
public Backend()
-
-
Method Details
-
register
Register the given config with the system
This is a hybrid of the load and save methods depending on the state of the given tree
New trees will be saved to the backend
Existing trees will be loaded and have the backend data overwritten onto them
NOTE do NOT use the parameter tree after this method is called because it may have been cleared
Use the returned tree instead -
load0
Load in a tree with the given ID
Returns null if the tree does not exist- Throws:
Exception
-
load
Load the tree with data stored in this backend- Returns:
- true if the tree was modified by the load operation
-
load
Load a tree with the given ID- Returns:
- the tree or null if it could not be loaded or does not exist
-
save0
- Throws:
Exception
-
save
Save a tree with the given ID- Returns:
- true if the tree was saved successfully
- Throws:
IllegalArgumentException- if no tree with the given ID is registered
-
saveAll
Save all trees under the given path -
saveAll
public final void saveAll()Save all trees registered to this backend -
save
Save the provided tree to the backend
If it is not registered when this is called it will be registered- Returns:
- true if the tree was saved successfully
- Throws:
IllegalStateException- if the tree has become synchronized with the backend
-
delete0
- Throws:
Exception
-
delete
Untrack and permanently delete the tree with the given ID -
unregister
Stops tracking a tree without deleting its stored data. -
exists
-
get
-
getTrees
-
requestUpdate
Request that the tree with the given ID needs to be updated for example when the file has been edited externally -
corrupt
Explicitly mark a tree as corrupted
The given tree if present will be untracked by this backend
this method is also automatically called when a tree fails to load (implementation specific operation)- Parameters:
id- the ID of the tree to mark as corrupted- Returns:
- true if the tree was marked as corrupted or false if the tree was not found
-
corrupt0
-
putSafe
-