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.
  • Nested Class Summary

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

    Fields
    Modifier and Type
    Field
    Description
    protected static final org.apache.logging.log4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Explicitly mark a tree as corrupted.
    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 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.
    protected void
     
    register(@NotNull Tree in)
    Register the given config with the system.
    protected void
    Request that the tree with the given ID needs to be updated, for example, the file has been edited externally.
    final boolean
    Save a tree with the given ID.
    final boolean
    save(Tree tree)
    Save the provided tree to the backend.
    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.

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