Module aeonics.core

Class Snapshot

  • All Implemented Interfaces:
    Exportable, Snapshotable

    public abstract class Snapshot
    extends Manager.Type
    Manages restore points of the system. This manager is responsible to create snapshots and to restore them. Entities or Plugins that want to react to such events may add a callback handler to be notified when such events happen.
    • Field Detail

      • createCallback

        protected static Callback<Data,​Snapshot> createCallback
        The snapshot create callback
      • restoreCallback

        protected static Callback<Data,​Snapshot> restoreCallback
        The snapshot restore callback
    • Constructor Detail

      • Snapshot

        public Snapshot()
    • Method Detail

      • manager

        public final java.lang.Class<? extends Manager.Type> manager()
        Hardcoded manager type
        Specified by:
        manager in class Manager.Type
        Returns:
        the type of manager
      • onSnapshot

        public static void onSnapshot​(Functions.Consumer<Data> handler)
        Adds an event handler to react to the current snapshot phase. Implementations may store elements in the provided data object that will be persisted at the end of the snapshot phase. For isolation purposes, a new empty data object will be provided per plugin (java module scope).
        Parameters:
        handler - the snapshot handler
      • onRestore

        public static void onRestore​(Functions.Consumer<Data> handler)
        Adds an event handler to react to the current restore phase. Implementations may fetch elements from the provided data object. For isolation purposes, each plugin (java module scope) will be given its own data object.
        Parameters:
        handler - the restore handler
      • create

        public abstract Executor.Task<java.lang.String> create​(java.lang.String suffix)
        Creates a new snapshot using the specified suffix while the prefix is usually the date of the snapshot.

        Snapshots are always performed asynchronously and handlers are called sequentially. When all onSnapshot(Consumer) handlers have executed, the returned task will complete with the final snapshot name.

        Parameters:
        suffix - the snapshot suffix (will be sanitized to contain 0 to 30 alpha numerical characters a-zA-Z0-9)
        Returns:
        the asynchronous snapshot task
      • restore

        public abstract Executor.Task<java.lang.Void> restore​(java.lang.String snapshot)
        Checks if the specified snapshot exists and triggers the restore operation.

        Snapshots are always performed asynchronously and handlers are called sequentially. When all onRestore(Consumer) handlers have executed, the returned task will complete.

        Parameters:
        snapshot - the snapshot name
        Returns:
        the asynchronous restore task
        Throws:
        java.lang.IllegalArgumentException - if the specified snapshot does not exist
      • upload

        public abstract void upload​(byte[] snapshot)
        Uploads a snapshot in this system.
        Parameters:
        snapshot - the snapshot content
        Throws:
        java.lang.IllegalArgumentException - if the snapshot is not compatible with this system
      • download

        public abstract byte[] download​(java.lang.String snapshot)
        Downloads a snapshot.
        Parameters:
        snapshot - the snapshot name
        Returns:
        the opaque snapshot content
        Throws:
        java.lang.IllegalArgumentException - if the specified snapshot does not exist
      • list

        public abstract java.util.Collection<java.lang.String> list()
        Lists all available snapshots
        Returns:
        the list of snapshots
      • remove

        public abstract void remove​(java.lang.String snapshot)
        Permanently removes a snapshot
        Parameters:
        snapshot - the snapshot to remove
      • exists

        public abstract boolean exists​(java.lang.String snapshot)
        Checks if a snapshot exists
        Parameters:
        snapshot - the snapshot to check
        Returns:
        true if the snapshot exists, false otherwise
      • latest

        public abstract java.lang.String latest()
        Gets the name of the latest snapshot or null if there are no snapshots.
        Returns:
        the the latest snapshot name