- java.lang.Object
-
- aeonics.entity.Entity
-
- aeonics.manager.Manager.Type
-
- aeonics.manager.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Snapshot.ModuleAwareBiConsumer
This class is used to track the owning module of the handler.
-
Field Summary
Fields Modifier and Type Field Description protected static Callback<Data,Snapshot>
createCallback
The snapshot create callbackprotected static Callback<Data,Snapshot>
restoreCallback
The snapshot restore callback
-
Constructor Summary
Constructors Constructor Description Snapshot()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.abstract byte[]
download(java.lang.String snapshot)
Downloads a snapshot.abstract boolean
exists(java.lang.String snapshot)
Checks if a snapshot existsabstract java.lang.String
latest()
Gets the name of the latest snapshot ornull
if there are no snapshots.abstract java.util.Collection<java.lang.String>
list()
Lists all available snapshotsjava.lang.Class<? extends Manager.Type>
manager()
Hardcoded manager typestatic void
onRestore(Functions.Consumer<Data> handler)
Adds an event handler to react to the current restore phase.static void
onSnapshot(Functions.Consumer<Data> handler)
Adds an event handler to react to the current snapshot phase.abstract void
remove(java.lang.String snapshot)
Permanently removes a snapshotabstract Executor.Task<java.lang.Void>
restore(java.lang.String snapshot)
Checks if the specified snapshot exists and triggers the restore operation.abstract void
upload(byte[] snapshot)
Uploads a snapshot in this system.-
Methods inherited from class aeonics.manager.Manager.Type
category, internal
-
Methods inherited from class aeonics.entity.Entity
addRelation, addRelation, addRelation, cast, clearRelation, config, defineRelation, equals, export, firstRelation, hashCode, hasRelation, id, name, name, onCreate, onRemove, onUpdate, parameter, relations, relationships, removeRelation, snapshot, type, valueOf, valueOf
-
-
-
-
Method Detail
-
manager
public final java.lang.Class<? extends Manager.Type> manager()
Hardcoded manager type- Specified by:
manager
in classManager.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 ornull
if there are no snapshots.- Returns:
- the the latest snapshot name
-
-