java.lang.Object
org.polyfrost.oneconfig.api.config.v1.backend.Backend

public abstract class Backend extends Object
A backend is a storage system for ConfigTrees.
It is responsible for getting and putting ConfigTrees, and by extension, serializing/deserializing them.
  • Field Details

    • LOGGER

      protected static final org.apache.logging.log4j.Logger LOGGER
    • UI_ONLY_METADATA

      public static final String 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:
    • UI_PLACEHOLDER_METADATA

      public static final String UI_PLACEHOLDER_METADATA
      See Also:
    • CUSTOM_SAVE_TRACKED_METADATA

      public static final String CUSTOM_SAVE_TRACKED_METADATA
      See Also:
    • CUSTOM_SAVE_DIRTY_METADATA

      public static final String CUSTOM_SAVE_DIRTY_METADATA
      See Also:
  • Constructor Details

    • Backend

      public Backend()
  • Method Details

    • register

      public final Backend.RegistrationResult register(@NotNull @NotNull Tree in)
      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

      protected abstract Tree load0(@NotNull @NotNull String id) throws Exception
      Load in a tree with the given ID. if the tree does not exist, return null.
      Throws:
      Exception
    • load

      public final boolean load(Tree tree)
      Load the tree with data stored in this backend.
      Returns:
      true if the tree was modified by the load operation, false otherwise.
    • load

      @Nullable public final @Nullable Tree load(@NotNull @NotNull String id)
      Load a tree with the given ID.
      Returns:
      the tree, or null if the tree could not be loaded or does not exist.
    • save0

      protected abstract boolean save0(@NotNull @NotNull Tree tree) throws Exception
      Throws:
      Exception
    • save

      public final boolean save(String id)
      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

      public final void saveAll(@Nullable @Nullable String matching)
      Save all trees under the given path.
    • saveAll

      public final void saveAll()
      Save all trees registered to this backend.
    • save

      public final boolean save(Tree tree)
      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

      protected abstract boolean delete0(@NotNull @NotNull Tree tree) throws Exception
      Throws:
      Exception
    • delete

      public final boolean delete(String id)
      Untrack and permanently delete the tree with the given ID.
    • exists

      public boolean exists(String id)
    • get

      public final Tree get(String id)
    • getTrees

      public final @UnmodifiableView Collection<Tree> getTrees()
    • requestUpdate

      @Experimental protected void requestUpdate(String id)
      Request that the tree with the given ID needs to be updated, for example, the file has been edited externally.
    • corrupt

      @Experimental public final boolean corrupt(String id)
      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

      protected abstract boolean corrupt0(Tree t)
    • putSafe

      protected void putSafe(Tree in)