Interface DataStore
-
public interface DataStore
Data type abstraction for permissions data.This is the low-level interface used by the engine for querying data. It should perform minimal caching, but is responsible for update notifications.
- Since:
- 2.0.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()Free any resources this data store may be using.booleanfirstRun()Get whether or not this is this data store's first run.Stream<Map.Entry<SubjectRef<?>,ImmutableSubjectData>>getAll()Returns all subjects present in this data storedefault <I> Stream<Map.Entry<I,ImmutableSubjectData>>getAll(SubjectType<I> type)Get all data for subjects of the specified type.Stream<Map.Entry<String,ImmutableSubjectData>>getAll(String type)Get all data for subjects of the specified type.Stream<String>getAllIdentifiers(String type)Get all subject identifiers for subjects of the given type.Stream<String>getAllRankLadders()Get all rank ladders.CompletableFuture<ContextInheritance>getContextInheritance(@Nullable Consumer<ContextInheritance> inheritance)Get context inheritance information.default CompletableFuture<ImmutableSubjectData>getData(SubjectRef<?> subject, @Nullable Consumer<ImmutableSubjectData> listener)Loads the data at the specified type and identifier.CompletableFuture<ImmutableSubjectData>getData(String type, String identifier, @Nullable Consumer<ImmutableSubjectData> listener)Loads the data at the specified type and identifier.CompletableFuture<Set<String>>getDefinedContextKeys()Enumerate all contexts defined within this data storeCompletableFuture<RankLadder>getRankLadder(String ladder, @Nullable Consumer<RankLadder> listener)Get a specific rank ladder, with a possible update listener.Set<String>getRegisteredTypes()Return all subject types that contain dataCompletableFuture<Boolean>hasRankLadder(String ladder)Whether a rank ladder by the given name is present.default CompletableFuture<Boolean>isRegistered(SubjectRef<?> subject)Return if the given subject has any data stored in this store.CompletableFuture<Boolean>isRegistered(String type, String identifier)Return if the given subject has any data stored in this store.default CompletableFuture<Void>moveData(SubjectRef<?> from, SubjectRef<?> to)Move data from one subject to anotherCompletableFuture<Void>moveData(String oldType, String oldIdentifier, String newType, String newIdentifier)Move data from one subject to anotherStringname()Get the identifier that refers to this instance of the data store uniquely.<T> CompletableFuture<T>performBulkOperation(Function<DataStore,T> function)Perform a bulk operation on this data store.CompletableFuture<ContextInheritance>setContextInheritance(ContextInheritance inheritance)Uppdate the stored context inheritance information.default CompletableFuture<ImmutableSubjectData>setData(SubjectRef<?> subject, @Nullable ImmutableSubjectData data)Sets the data at the specified type and identifier.CompletableFuture<ImmutableSubjectData>setData(String type, String identifier, @Nullable ImmutableSubjectData data)Sets the data at the specified type and identifier.CompletableFuture<RankLadder>setRankLadder(String identifier, @Nullable RankLadder ladder)Set the rank ladder at the given identifier.
-
-
-
Method Detail
-
name
String name()
Get the identifier that refers to this instance of the data store uniquely.This is generally user-defined in the configuration.
- Returns:
- The name of the current data store instance.
- Since:
- 2.0.0
-
firstRun
boolean firstRun()
Get whether or not this is this data store's first run.If this is the first run for a data store, PermissionsEx will try to populate it with default data.
- Returns:
- if this is the first run
- Since:
- 2.0.0
-
close
void close()
Free any resources this data store may be using.- Since:
- 2.0.0
-
getData
CompletableFuture<ImmutableSubjectData> getData(String type, String identifier, @Nullable Consumer<ImmutableSubjectData> listener)
Loads the data at the specified type and identifier.Implementations of this method do not need to perform any caching.
- Parameters:
type- The type of subject to getidentifier- The subject's identifierlistener- The update listener for this subject- Returns:
- The relevant subject data
- Since:
- 2.0.0
-
getData
default CompletableFuture<ImmutableSubjectData> getData(SubjectRef<?> subject, @Nullable Consumer<ImmutableSubjectData> listener)
Loads the data at the specified type and identifier.Implementations of this method do not need to perform any caching.
- Parameters:
subject- The identity of the subject data is being set forlistener- The update listener for this subject- Returns:
- The relevant subject data
- Since:
- 2.0.0
-
setData
CompletableFuture<ImmutableSubjectData> setData(String type, String identifier, @Nullable ImmutableSubjectData data)
Sets the data at the specified type and identifier.- Parameters:
type- The type of subject data is being fetched foridentifier- The identifier of the subject data is being fetched fordata- The data to commit to this backend. This being null deletes any data for the given identifier- Returns:
- A future that can be used to listen for completion of writing the changed data
- Since:
- 2.0.0
-
setData
default CompletableFuture<ImmutableSubjectData> setData(SubjectRef<?> subject, @Nullable ImmutableSubjectData data)
Sets the data at the specified type and identifier.- Parameters:
subject- The identity of the subject data is being set fordata- The data to commit to this backend. This being null deletes any data for the given subject- Returns:
- A future that can be used to listen for completion of writing the changed data
- Since:
- 2.0.0
-
moveData
CompletableFuture<Void> moveData(String oldType, String oldIdentifier, String newType, String newIdentifier)
Move data from one subject to another- Parameters:
oldType- The old subject's typeoldIdentifier- The old subject's identifiernewType- The new subject's typenewIdentifier- The new subject's identifier- Returns:
- A future that will complete when the move is complete
- Since:
- 2.0.0
-
moveData
default CompletableFuture<Void> moveData(SubjectRef<?> from, SubjectRef<?> to)
Move data from one subject to another- Parameters:
from- the old subjectto- the new subject- Returns:
- A future that will complete when the move is complete
- Since:
- 2.0.0
-
isRegistered
CompletableFuture<Boolean> isRegistered(String type, String identifier)
Return if the given subject has any data stored in this store.- Parameters:
type- The subject's typeidentifier- The subject's identifier- Returns:
- whether any data is stored
- Since:
- 2.0.0
-
isRegistered
default CompletableFuture<Boolean> isRegistered(SubjectRef<?> subject)
Return if the given subject has any data stored in this store.- Parameters:
subject- the subject to check- Returns:
- whether any data is stored
- Since:
- 2.0.0
-
getAll
Stream<Map.Entry<String,ImmutableSubjectData>> getAll(String type)
Get all data for subjects of the specified type. ThisStreammay be filled asynchronously- Parameters:
type- The type to get all data for- Returns:
- An iterable providing data
- Since:
- 2.0.0
-
getAll
default <I> Stream<Map.Entry<I,ImmutableSubjectData>> getAll(SubjectType<I> type)
Get all data for subjects of the specified type. ThisStreammay be filled asynchronously.- Parameters:
type- The type to get all data for- Returns:
- An iterable providing data
- Since:
- 2.0.0
-
getAllIdentifiers
Stream<String> getAllIdentifiers(String type)
Get all subject identifiers for subjects of the given type.- Parameters:
type- The type of subject to get identifiers for- Returns:
- The registered identifiers of subjects of type
type - Since:
- 2.0.0
-
getRegisteredTypes
Set<String> getRegisteredTypes()
Return all subject types that contain data- Returns:
- The registered subject types
- Since:
- 2.0.0
-
getDefinedContextKeys
CompletableFuture<Set<String>> getDefinedContextKeys()
Enumerate all contexts defined within this data store- Returns:
- The contexts available within this data store
- Since:
- 2.0.0
-
getAll
Stream<Map.Entry<SubjectRef<?>,ImmutableSubjectData>> getAll()
Returns all subjects present in this data store- Returns:
- An iterable containing all subjects
- Since:
- 2.0.0
-
performBulkOperation
<T> CompletableFuture<T> performBulkOperation(Function<DataStore,T> function)
Perform a bulk operation on this data store. While this operation is in progress, all writes must be suppressed (meaning changes must be cached in memory until the operation is complete). Bulk operations may be executed asynchronously.- Type Parameters:
T- return value type- Parameters:
function- The function to call containing the operation.- Returns:
- a future completing with the result of the operation or an error
- Since:
- 2.0.0
-
getAllRankLadders
Stream<String> getAllRankLadders()
Get all rank ladders.- Returns:
- The names of all rank ladders
- Since:
- 2.0.0
-
getRankLadder
CompletableFuture<RankLadder> getRankLadder(String ladder, @Nullable Consumer<RankLadder> listener)
Get a specific rank ladder, with a possible update listener.- Parameters:
ladder- The ladder to get. Case-insensitivelistener- The listener to track possible updates- Returns:
- the ladder
- Since:
- 2.0.0
-
hasRankLadder
CompletableFuture<Boolean> hasRankLadder(String ladder)
Whether a rank ladder by the given name is present.- Parameters:
ladder- The ladder to check. Case-insensitive- Returns:
- Whether a ladder by the provided name exists
- Since:
- 2.0.0
-
setRankLadder
CompletableFuture<RankLadder> setRankLadder(String identifier, @Nullable RankLadder ladder)
Set the rank ladder at the given identifier.- Parameters:
identifier- The name of the ladder. Case-insensitive for overwriting existing laddersladder- The ladder to update- Returns:
- a future tracking the status of this operation
- Since:
- 2.0.0
-
getContextInheritance
CompletableFuture<ContextInheritance> getContextInheritance(@Nullable Consumer<ContextInheritance> inheritance)
Get context inheritance information.- Parameters:
inheritance- The listener to notify about changes- Returns:
- A future that will supply context inheritance
- Since:
- 2.0.0
-
setContextInheritance
CompletableFuture<ContextInheritance> setContextInheritance(ContextInheritance inheritance)
Uppdate the stored context inheritance information.- Parameters:
inheritance- inheritance to apply- Returns:
- a future completing with the previous inheritance data
- Since:
- 2.0.0
-
-