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 handles getting and putting ConfigTrees and also serializing and deserializing them
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    protected static final org.apache.logging.log4j.Logger
     
    static final String
    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
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    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)
    protected abstract boolean
     
    final boolean
    Untrack and permanently delete the tree with the given ID
    protected abstract boolean
    delete0(@NotNull Tree tree)
     
    boolean
     
    final Tree
    get(String id)
     
    final @UnmodifiableView Collection<Tree>
     
    final @Nullable Exception
     
    final @Nullable Tree
    load(@NotNull String id)
    Load a tree with the given ID
    final boolean
    load(Tree tree)
    Load the tree with data stored in this backend
    protected abstract Tree
    load0(@NotNull String id)
    Load in a tree with the given ID
    Returns null if the tree does not exist
    protected void
     
    register(@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
    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
    protected void
    Request that the tree with the given ID needs to be updated for example when the file has been edited externally
    protected void
     
    final boolean
    Save a tree with the given ID
    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
    protected abstract boolean
    save0(@NotNull Tree tree)
     
    final void
    Save all trees registered to this backend
    final void
    saveAll(@Nullable String matching)
    Save all trees under the given path
    final @Nullable Tree
    Stops tracking a tree without deleting its stored data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 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

      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
      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

      protected abstract Tree load0(@NotNull @NotNull String id) throws Exception
      Load in a tree with the given ID
      Returns null if the tree does not exist
      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
    • load

      @Nullable public final @Nullable Tree load(@NotNull @NotNull String id)
      Load a tree with the given ID
      Returns:
      the tree or null if it 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
      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
      Throws:
      IllegalStateException - if the tree has become synchronized with the backend
    • lastSaveFailure

      @Nullable public final @Nullable Exception lastSaveFailure()
    • 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
    • unregister

      @Internal @Nullable public final @Nullable Tree unregister(String id)
      Stops tracking a tree without deleting its stored data.
    • 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 when the file has been edited externally
    • requestUpdate

      protected void requestUpdate(String id, BooleanSupplier isActive)
    • 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 or false if the tree was not found
    • corrupt0

      protected abstract boolean corrupt0(Tree t)
    • putSafe

      protected void putSafe(Tree in)