Class DefaultCachedPermissionManagement
java.lang.Object
eu.cloudnetservice.driver.permission.DefaultPermissionManagement
eu.cloudnetservice.driver.permission.DefaultCachedPermissionManagement
- All Implemented Interfaces:
CachedPermissionManagement,PermissionManagement
public abstract class DefaultCachedPermissionManagement
extends DefaultPermissionManagement
implements CachedPermissionManagement
This management extends the default implementation of the permission management by implementing all methods needed
for caching of both permission users and groups. The caches are backed by Caffeine and expire after 5 minutes without
any access or locks on the specific permissible.
- Since:
- 4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.github.benmanes.caffeine.cache.Cache<String,PermissionGroup> protected final Map<String,AtomicInteger> protected final com.github.benmanes.caffeine.cache.Cache<UUID,PermissionUser> protected final Map<UUID,AtomicInteger> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacquireLock(@NonNull PermissionGroup group) Acquires a lock for the permission group.voidAcquires a lock for the permission user.cachedGroup(@NonNull String name) Searches the permission group cache for a permission group with the given name.Gets a map with all cached permission groups mapped to their name.Gets a map with all cached permission users mapped to their uuid.cachedUser(@NonNull UUID uniqueId) Searches the permission user cache for a permission user with the given unique id.protected voidhandleGroupRemove(@NonNull String key, @NonNull PermissionGroup group, @NonNull com.github.benmanes.caffeine.cache.RemovalCause cause) Handles the removal of the permission group in the cache.protected voidhandleUserRemove(@NonNull UUID key, @NonNull PermissionUser user, @NonNull com.github.benmanes.caffeine.cache.RemovalCause cause) Handles the removal of the permission user in the cache.booleanlocked(@NonNull PermissionGroup group) Checks if the given group has any locks locking the group in the cache.booleanlocked(@NonNull PermissionUser user) Checks if the given user has any locks locking the user in the cache.voidunlock(@NonNull PermissionGroup group) Removes exactly one lock of the group.voidunlock(@NonNull PermissionUser user) Removes exactly one lock of the user.voidunlockFully(@NonNull PermissionGroup group) Removes all locks that the given group has.voidRemoves all locks that the given user has.Methods inherited from class eu.cloudnetservice.driver.permission.DefaultPermissionManagement
allGroupPermissions, allPermissions, childPermissionManagement, collectAllGroupPermissionsInto, collectAllPermissions, collectAllPermissionsTo, collectPermissionsInto, findHighestPermission, groupPermissionResult, groupsOf, groupsPermissionResult, highestPermissionGroup, modifyGroup, modifyUser, modifyUsers, permissionResult, testPermissible, testPermissionUserMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.permission.PermissionManagement
addGroupAsync, addPermissionGroup, addPermissionGroup, addPermissionGroupAsync, addPermissionUser, addPermissionUser, addPermissionUserAsync, addUserAsync, allGroupPermissions, allPermissions, childPermissionManagement, close, containsGroup, containsGroupAsync, containsOneUser, containsOneUserAsync, containsUser, containsUserAsync, defaultPermissionGroup, defaultPermissionGroupAsync, deleteGroup, deleteGroupAsync, deletePermissionGroup, deletePermissionGroupAsync, deletePermissionUser, deletePermissionUserAsync, deleteUser, deleteUserAsync, findHighestPermission, firstUser, firstUserAsync, getOrCreateUser, getOrCreateUserAsync, group, groupAsync, groupPermissionResult, groups, groups, groupsAsync, groupsAsync, groupsOf, groupsOfAsync, groupsPermissionResult, hasGroupPermission, hasPermission, highestPermissionGroup, init, modifyGroup, modifyGroupAsync, modifyUser, modifyUserAsync, modifyUsers, modifyUsersAsync, permissionResult, reload, sendCommandLine, sendCommandLineAsync, testPermissible, testPermissionUser, updateGroup, updateGroupAsync, updateUser, updateUserAsync, user, userAsync, users, usersAsync, usersByGroup, usersByGroupAsync, usersByName, usersByNameAsync
-
Field Details
-
permissionUserLocks
-
permissionGroupLocks
-
permissionUserCache
-
permissionGroupCache
protected final com.github.benmanes.caffeine.cache.Cache<String,PermissionGroup> permissionGroupCache
-
-
Constructor Details
-
DefaultCachedPermissionManagement
public DefaultCachedPermissionManagement()
-
-
Method Details
-
cachedPermissionUsers
Gets a map with all cached permission users mapped to their uuid.- Specified by:
cachedPermissionUsersin interfaceCachedPermissionManagement- Returns:
- all cached permission users.
-
cachedPermissionGroups
Gets a map with all cached permission groups mapped to their name.- Specified by:
cachedPermissionGroupsin interfaceCachedPermissionManagement- Returns:
- all cached permission groups.
-
cachedUser
Searches the permission user cache for a permission user with the given unique id.- Specified by:
cachedUserin interfaceCachedPermissionManagement- Parameters:
uniqueId- the unique id associated with the permission user.- Returns:
- the cached permission user for the given unique id, null if no user was found in the cache.
-
cachedGroup
Searches the permission group cache for a permission group with the given name.- Specified by:
cachedGroupin interfaceCachedPermissionManagement- Parameters:
name- the name associated with the permission group.- Returns:
- the cached permission group for the given name, null if no group was found in the cache.
-
acquireLock
Acquires a lock for the permission user. The lock ensures that the user stays in cache.Each method call results in incrementing the lock count of the user. It's ensured that the user stays in the cache until the lock count is decreased again and reaches 0. After that event the normal cache invalidation rules of the permission management take effect again.
- Specified by:
acquireLockin interfaceCachedPermissionManagement- Parameters:
user- the user to acquire the lock for.
-
acquireLock
Acquires a lock for the permission group. The lock ensures that the group stays in cache.Each method call results in incrementing the lock count of the group. It's ensured that the group stays in the cache until the lock count is decreased again and reaches 0. After that event the normal cache invalidation rules of the permission management take effect again.
- Specified by:
acquireLockin interfaceCachedPermissionManagement- Parameters:
group- the group to acquire the lock for.
-
locked
Checks if the given user has any locks locking the user in the cache.- Specified by:
lockedin interfaceCachedPermissionManagement- Parameters:
user- the user to check for locks.- Returns:
- true if there are any locks for the given user, false otherwise.
-
locked
Checks if the given group has any locks locking the group in the cache.- Specified by:
lockedin interfaceCachedPermissionManagement- Parameters:
group- the group to check for locks.- Returns:
- true if there are any locks for the given group, false otherwise.
-
unlock
Removes exactly one lock of the user. If the user does not have any locks no changes are made. It's ensured that the user stays in the cache until the lock count is decreased again and reaches 0. After that event the normal cache invalidation rules of the permission management take effect again.- Specified by:
unlockin interfaceCachedPermissionManagement- Parameters:
user- the user to remove a lock for.
-
unlock
Removes exactly one lock of the group. If the group does not have any locks no changes are made. It's ensured that the group stays in the cache until the lock count is decreased again and reaches 0. After that event the normal cache invalidation rules of the permission management take effect again.- Specified by:
unlockin interfaceCachedPermissionManagement- Parameters:
group- the group to remove a lock for.
-
unlockFully
Removes all locks that the given user has. After that event the normal cache invalidation rules of the permission management take effect again.- Specified by:
unlockFullyin interfaceCachedPermissionManagement- Parameters:
user- the user to unlock completely.
-
unlockFully
Removes all locks that the given group has. After that event the normal cache invalidation rules of the permission management take effect again.- Specified by:
unlockFullyin interfaceCachedPermissionManagement- Parameters:
group- the group to unlock completely.
-
handleUserRemove
protected void handleUserRemove(@NonNull @NonNull UUID key, @NonNull @NonNull PermissionUser user, @NonNull @NonNull com.github.benmanes.caffeine.cache.RemovalCause cause) Handles the removal of the permission user in the cache. If the user still is locked and wasn't removed because he is replaced the user is added back to the cache.- Parameters:
key- the unique id of the removed user.user- the removed user.cause- the reason for the removal out of the cache.- Throws:
NullPointerException- if the given key, user or cause is null.
-
handleGroupRemove
protected void handleGroupRemove(@NonNull @NonNull String key, @NonNull @NonNull PermissionGroup group, @NonNull @NonNull com.github.benmanes.caffeine.cache.RemovalCause cause) Handles the removal of the permission group in the cache. If the group still is locked and wasn't removed because it is replaced the group is added back to the cache.- Parameters:
key- the unique id of the removed group.group- the removed group.cause- the reason for the removal out of the cache.- Throws:
NullPointerException- if the given key, group or cause is null.
-