Class Backend
java.lang.Object
org.polyfrost.oneconfig.api.config.v1.backend.Backend
A backend is a storage system for ConfigTrees.
It is responsible for getting and putting ConfigTrees, and by extension, serializing/deserializing them.
It is responsible for getting and putting ConfigTrees, and by extension, serializing/deserializing them.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.apache.logging.log4j.Loggerstatic final StringTrees marked with this metadata are listed in the UI only (e.g. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanExplicitly mark a tree as corrupted.protected abstract booleanfinal booleanUntrack and permanently delete the tree with the given ID.protected abstract booleanbooleanfinal Treefinal @UnmodifiableView Collection<Tree> getTrees()final @Nullable TreeLoad a tree with the given ID.final booleanLoad the tree with data stored in this backend.protected abstract TreeLoad in a tree with the given ID.protected voidRegister the given config with the system.protected voidrequestUpdate(String id) Request that the tree with the given ID needs to be updated, for example, the file has been edited externally.final booleanSave a tree with the given ID.final booleanSave the provided tree to the backend.protected abstract booleanfinal voidsaveAll()Save all trees registered to this backend.final voidSave all trees under the given path.
-
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 (e.g. Mod Menu compat entries). They are tracked in memory but never loaded from or written to backend storage.- 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, while existing trees will be loaded and data overwritten on them with the backend data.
NOTE: do NOT use the parameter tree after this method is called, as it may have been cleared. Use the returned tree instead. -
load0
Load in a tree with the given ID. if the tree does not exist, return null.- Throws:
Exception
-
load
Load the tree with data stored in this backend.- Returns:
- true if the tree was modified by the load operation, false otherwise.
-
load
Load a tree with the given ID.- Returns:
- the tree, or null if the tree 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, false otherwise.
- 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, false otherwise.
- 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. -
exists
-
get
-
getTrees
-
requestUpdate
Request that the tree with the given ID needs to be updated, for example, 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, false if the tree was not found.
-
corrupt0
-
putSafe
-