Class VariablesStorage

java.lang.Object
ch.njol.skript.variables.VariablesStorage
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
DatabaseStorage, FlatFileStorage

public abstract class VariablesStorage extends Object implements Closeable
  • Field Details

    • closed

      protected volatile boolean closed
    • databaseName

      protected final String databaseName
    • file

      protected @Nullable File file
    • connectionLock

      protected final Object connectionLock
      Must be locked after Variables.getReadLock() (if that lock is used at all)
    • backupTask

      protected @Nullable Task backupTask
  • Constructor Details

    • VariablesStorage

      protected VariablesStorage(String name)
  • Method Details

    • getValue

      protected @Nullable String getValue(SectionNode n, String key)
    • getValue

      protected <T> @Nullable T getValue(SectionNode n, String key, Class<T> type)
    • load

      public final boolean load(SectionNode n)
    • load_i

      protected abstract boolean load_i(SectionNode n)
      Loads variables stored here.
      Returns:
      Whether the database could be loaded successfully, i.e. whether the config is correct and all variables could be loaded
    • allLoaded

      protected abstract void allLoaded()
      Called after all storages have been loaded, and variables have been redistributed if settings have changed. This should commit the first transaction (which is not empty if variables have been moved from another database to this one or vice versa), and start repeating transactions if applicable.
    • requiresFile

      protected abstract boolean requiresFile()
    • getFile

      protected abstract File getFile(String file)
    • connect

      protected abstract boolean connect()
      (Re)connects to the database (not called on the first connect - do this in load_i(SectionNode)).
      Returns:
      Whether the connection could be re-established. An error should be printed by this method prior to returning false.
    • disconnect

      protected abstract void disconnect()
      Disconnects from the database.
    • startBackupTask

      public void startBackupTask(Timespan t)
    • close

      public void close()
      Called when Skript gets disabled. The default implementation will wait for all variables to be saved before setting closed to true and stopping the write thread, thus super.close() must be called if this method is overridden!
      Specified by:
      close in interface Closeable
    • clearChangesQueue

      protected void clearChangesQueue()
      Clears the saveQueue of unsaved variables. Only used if all variables are saved immediately after calling this method.
    • save

      protected abstract boolean save(String name, @Nullable String type, @org.eclipse.jdt.annotation.Nullable byte[] value)
      Saves a variable. This is called from the main thread while variables are transferred between databases, and from the writeThread afterwards.
      Parameters:
      name -
      type -
      value -
      Returns:
      Whether the variable was saved