Class PermissionsEx<P>
- java.lang.Object
-
- ca.stellardrift.permissionsex.impl.PermissionsEx<P>
-
- All Implemented Interfaces:
ca.stellardrift.permissionsex.context.ContextDefinitionProvider,ca.stellardrift.permissionsex.datastore.DataStoreContext,ca.stellardrift.permissionsex.PermissionsEngine,Consumer<ca.stellardrift.permissionsex.context.ContextInheritance>
public class PermissionsEx<P> extends Object implements Consumer<ca.stellardrift.permissionsex.context.ContextInheritance>, ca.stellardrift.permissionsex.context.ContextDefinitionProvider, ca.stellardrift.permissionsex.PermissionsEngine, ca.stellardrift.permissionsex.datastore.DataStoreContext
The entry point to the PermissionsEx engine.The fastest way to get going with working with subjects is to access a subject type collection with
subjects(SubjectType)and request aCalculatedSubjectImplto query data from. Directly working withToDataSubjectRefImpls is another option, preferable if most of the operations being performed are writes, or querying data directly defined on a subject.Keep in mind most of PEX's core data objects are immutable and must be resubmitted to their holders to apply updates. Most write operations are done asynchronously, and futures are returned that complete when the backend is finished writing out data. For larger operations, it can be useful to perform changes within
performBulkOperation(Supplier), which will reduce unnecessary writes to the backing data store in some cases.
-
-
Constructor Summary
Constructors Constructor Description PermissionsEx(PermissionsExConfiguration<P> config, ImplementationInterface impl)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept(ca.stellardrift.permissionsex.context.ContextInheritance newData)Listener method that handles changes to context inheritance.ca.stellardrift.permissionsex.datastore.DataStoreactiveDataStore()ExecutorasyncExecutor()Get an executor to run tasks asynchronously on.PathbaseDirectory()PathbaseDirectory(BaseDirectoryScope scope)voidclose()Shut down the PEX engine.PermissionsExConfiguration<P>config()Get the current configuration PEX is operating with.@Nullable ca.stellardrift.permissionsex.context.ContextDefinition<?>contextDefinition(String definitionKey, boolean allowFallbacks)CompletableFuture<ca.stellardrift.permissionsex.context.ContextInheritance>contextInheritance(@Nullable Consumer<ca.stellardrift.permissionsex.context.ContextInheritance> listener)Get context inheritance data.CompletableFuture<ca.stellardrift.permissionsex.context.ContextInheritance>contextInheritance(ca.stellardrift.permissionsex.context.ContextInheritance newInheritance)Update the context inheritance when values have been changed@Nullable DataSourcedataSourceForUrl(String url)Deprecated.booleandebugMode()Know whether or not debug mode is enabledvoiddebugMode(boolean debug, @Nullable Pattern filterPattern)Set whether or not debug mode is enabled.ca.stellardrift.permissionsex.subject.SubjectRef<?>deserializeSubjectRef(String type, String name)<V> CompletableFuture<V>doBulkOperation(Function<ca.stellardrift.permissionsex.datastore.DataStore,CompletableFuture<V>> actor)ca.stellardrift.permissionsex.PermissionsEngineengine()List<ca.stellardrift.permissionsex.datastore.ConversionResult>getAvailableConversions()ca.stellardrift.permissionsex.logging.PermissionCheckNotifiergetNotifier()Get the currently active notifier.RecordingPermissionCheckNotifiergetRecordingNotifier()Get the base notifier that logs any permission checks that gave taken place.CompletableFuture<?>importDataFrom(ca.stellardrift.permissionsex.datastore.ConversionResult conversion)CompletableFuture<?>importDataFrom(String dataStoreIdentifier)Imports data into the currently active backend from another configured backend.Set<ca.stellardrift.permissionsex.subject.SubjectType<?>>knownSubjectTypes()Get all registered subject types in the active data store.ca.stellardrift.permissionsex.rank.RankLadderCollectionladders()Access rank ladders through a cached interfaceca.stellardrift.permissionsex.subject.SubjectRef<?>lazySubjectRef(String type, String identifier)Collection<SubjectTypeCollectionImpl<?>>loadedSubjectTypes()Get a view of the currently cached subject typesca.stellardrift.permissionsex.logging.FormattedLoggerlogger()<T> CompletableFuture<T>performBulkOperation(Supplier<CompletableFuture<T>> func)Suppress writes to the data store for the duration of a specific operation.<T> booleanregisterContextDefinition(ca.stellardrift.permissionsex.context.ContextDefinition<T> contextDefinition)intregisterContextDefinitions(ca.stellardrift.permissionsex.context.ContextDefinition<?>... definitions)List<ca.stellardrift.permissionsex.context.ContextDefinition<?>>registeredContextTypes()CompletableFuture<Void>reload()Reload the configuration file in use and refresh backend data<I> SubjectTypeCollectionImpl<I>subjects(ca.stellardrift.permissionsex.subject.SubjectType<I> type)Get the collection of subjects of a given type.CompletableFuture<Set<ca.stellardrift.permissionsex.context.ContextDefinition<?>>>usedContextTypes()Stringversion()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ca.stellardrift.permissionsex.context.ContextDefinitionProvider
contextDefinition
-
-
-
-
Constructor Detail
-
PermissionsEx
public PermissionsEx(PermissionsExConfiguration<P> config, ImplementationInterface impl) throws ca.stellardrift.permissionsex.exception.PermissionsLoadingException
- Throws:
ca.stellardrift.permissionsex.exception.PermissionsLoadingException
-
-
Method Detail
-
subjects
public <I> SubjectTypeCollectionImpl<I> subjects(ca.stellardrift.permissionsex.subject.SubjectType<I> type)
Get the collection of subjects of a given type. No data is loaded in this operation. Any string is supported as a subject type, but some common types have been provided as constants in this class for convenience.- Specified by:
subjectsin interfaceca.stellardrift.permissionsex.PermissionsEngine- Parameters:
type- The type identifier requested. Can be any string- Returns:
- The subject type collection
- See Also:
PermissionsEngine.SUBJECTS_DEFAULTS
-
loadedSubjectTypes
public Collection<SubjectTypeCollectionImpl<?>> loadedSubjectTypes()
Get a view of the currently cached subject types- Specified by:
loadedSubjectTypesin interfaceca.stellardrift.permissionsex.PermissionsEngine- Returns:
- Unmodifiable view of the currently cached subject types
-
knownSubjectTypes
public Set<ca.stellardrift.permissionsex.subject.SubjectType<?>> knownSubjectTypes()
Get all registered subject types in the active data store. The set is an immutable copy of the backend data.- Specified by:
knownSubjectTypesin interfaceca.stellardrift.permissionsex.PermissionsEngine- Returns:
- A set of registered subject types
-
engine
public ca.stellardrift.permissionsex.PermissionsEngine engine()
- Specified by:
enginein interfaceca.stellardrift.permissionsex.datastore.DataStoreContext
-
deserializeSubjectRef
public ca.stellardrift.permissionsex.subject.SubjectRef<?> deserializeSubjectRef(String type, String name)
- Specified by:
deserializeSubjectRefin interfaceca.stellardrift.permissionsex.datastore.DataStoreContext
-
lazySubjectRef
public ca.stellardrift.permissionsex.subject.SubjectRef<?> lazySubjectRef(String type, String identifier)
- Specified by:
lazySubjectRefin interfaceca.stellardrift.permissionsex.datastore.DataStoreContext
-
doBulkOperation
public <V> CompletableFuture<V> doBulkOperation(Function<ca.stellardrift.permissionsex.datastore.DataStore,CompletableFuture<V>> actor)
- Specified by:
doBulkOperationin interfaceca.stellardrift.permissionsex.PermissionsEngine
-
performBulkOperation
public <T> CompletableFuture<T> performBulkOperation(Supplier<CompletableFuture<T>> func)
Suppress writes to the data store for the duration of a specific operation. Only really useful for extremely large operations- Type Parameters:
T- The type of data that will be returned- Parameters:
func- The operation to perform- Returns:
- A future that completes once all data has been written to the store
-
ladders
public ca.stellardrift.permissionsex.rank.RankLadderCollection ladders()
Access rank ladders through a cached interface- Specified by:
laddersin interfaceca.stellardrift.permissionsex.PermissionsEngine- Returns:
- Access to rank ladders
-
importDataFrom
public CompletableFuture<?> importDataFrom(String dataStoreIdentifier)
Imports data into the currently active backend from another configured backend.- Parameters:
dataStoreIdentifier- The identifier of the backend to import from- Returns:
- A future that completes once the import operation is complete
-
importDataFrom
public CompletableFuture<?> importDataFrom(ca.stellardrift.permissionsex.datastore.ConversionResult conversion)
-
getNotifier
public ca.stellardrift.permissionsex.logging.PermissionCheckNotifier getNotifier()
Get the currently active notifier. This object has callbacks triggered on every permission check- Returns:
- The active notifier
-
getRecordingNotifier
public RecordingPermissionCheckNotifier getRecordingNotifier()
Get the base notifier that logs any permission checks that gave taken place.- Returns:
- the notifier, even if not active
-
debugMode
public boolean debugMode()
Know whether or not debug mode is enabled- Specified by:
debugModein interfaceca.stellardrift.permissionsex.PermissionsEngine- Returns:
- true if debug mode is enabled
-
debugMode
public void debugMode(boolean debug, @Nullable Pattern filterPattern)
Set whether or not debug mode is enabled. Debug mode logs all permission, option, and inheritance checks made to the console.- Specified by:
debugModein interfaceca.stellardrift.permissionsex.PermissionsEngine- Parameters:
debug- Whether to enable debug modefilterPattern- A pattern to filter which permissions are logged. Null for no filter.
-
reload
public CompletableFuture<Void> reload()
Reload the configuration file in use and refresh backend data- Returns:
- A future that completes once a reload has finished
-
close
public void close()
Shut down the PEX engine. Once this has been done, no further action can be taken until the engine is reinitialized with a fresh configuration.
-
getAvailableConversions
public List<ca.stellardrift.permissionsex.datastore.ConversionResult> getAvailableConversions()
-
logger
public ca.stellardrift.permissionsex.logging.FormattedLogger logger()
- Specified by:
loggerin interfaceca.stellardrift.permissionsex.datastore.DataStoreContext
-
baseDirectory
public Path baseDirectory()
- Specified by:
baseDirectoryin interfaceca.stellardrift.permissionsex.datastore.DataStoreContext
-
baseDirectory
public Path baseDirectory(BaseDirectoryScope scope)
-
dataSourceForUrl
@Deprecated public @Nullable DataSource dataSourceForUrl(String url) throws SQLException
Deprecated.- Specified by:
dataSourceForUrlin interfaceca.stellardrift.permissionsex.datastore.DataStoreContext- Throws:
SQLException
-
asyncExecutor
public Executor asyncExecutor()
Get an executor to run tasks asynchronously on.- Specified by:
asyncExecutorin interfaceca.stellardrift.permissionsex.datastore.DataStoreContext- Returns:
- The async executor
-
config
public PermissionsExConfiguration<P> config()
Get the current configuration PEX is operating with. This object is immutable.- Returns:
- The current configuration object
-
activeDataStore
public ca.stellardrift.permissionsex.datastore.DataStore activeDataStore()
-
contextInheritance
public CompletableFuture<ca.stellardrift.permissionsex.context.ContextInheritance> contextInheritance(@Nullable Consumer<ca.stellardrift.permissionsex.context.ContextInheritance> listener)
Get context inheritance data.The result of the future is immutable -- to take effect, the object returned by any update methods in
ContextInheritancemust be passed tocontextInheritance(ContextInheritance). It follows that anybody else's changes will not appear in the returned inheritance object -- so if updates are desired providing a callback function is important.- Specified by:
contextInheritancein interfaceca.stellardrift.permissionsex.PermissionsEngine- Parameters:
listener- A callback function that will be triggered whenever there is a change to the context inheritance- Returns:
- A future providing the current context inheritance data
-
contextInheritance
public CompletableFuture<ca.stellardrift.permissionsex.context.ContextInheritance> contextInheritance(ca.stellardrift.permissionsex.context.ContextInheritance newInheritance)
Update the context inheritance when values have been changed- Specified by:
contextInheritancein interfaceca.stellardrift.permissionsex.PermissionsEngine- Parameters:
newInheritance- The modified inheritance object- Returns:
- A future containing the latest context inheritance object
-
accept
public void accept(ca.stellardrift.permissionsex.context.ContextInheritance newData)
Listener method that handles changes to context inheritance. Should not be called by outside users
-
usedContextTypes
public CompletableFuture<Set<ca.stellardrift.permissionsex.context.ContextDefinition<?>>> usedContextTypes()
- Specified by:
usedContextTypesin interfaceca.stellardrift.permissionsex.context.ContextDefinitionProvider
-
registerContextDefinition
public <T> boolean registerContextDefinition(ca.stellardrift.permissionsex.context.ContextDefinition<T> contextDefinition)
- Specified by:
registerContextDefinitionin interfaceca.stellardrift.permissionsex.context.ContextDefinitionProvider
-
registerContextDefinitions
public int registerContextDefinitions(ca.stellardrift.permissionsex.context.ContextDefinition<?>... definitions)
- Specified by:
registerContextDefinitionsin interfaceca.stellardrift.permissionsex.context.ContextDefinitionProvider
-
registeredContextTypes
public List<ca.stellardrift.permissionsex.context.ContextDefinition<?>> registeredContextTypes()
- Specified by:
registeredContextTypesin interfaceca.stellardrift.permissionsex.context.ContextDefinitionProvider
-
contextDefinition
public @Nullable ca.stellardrift.permissionsex.context.ContextDefinition<?> contextDefinition(String definitionKey, boolean allowFallbacks)
- Specified by:
contextDefinitionin interfaceca.stellardrift.permissionsex.context.ContextDefinitionProvider
-
-