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 Details

    • permissionUserLocks

      protected final Map<UUID,AtomicInteger> permissionUserLocks
    • permissionGroupLocks

      protected final Map<String,AtomicInteger> permissionGroupLocks
    • permissionUserCache

      protected final com.github.benmanes.caffeine.cache.Cache<UUID,PermissionUser> permissionUserCache
    • permissionGroupCache

      protected final com.github.benmanes.caffeine.cache.Cache<String,PermissionGroup> permissionGroupCache
  • Constructor Details

    • DefaultCachedPermissionManagement

      public DefaultCachedPermissionManagement()
  • Method Details

    • cachedPermissionUsers

      @NonNull public @NonNull Map<UUID,PermissionUser> cachedPermissionUsers()
      Gets a map with all cached permission users mapped to their uuid.
      Specified by:
      cachedPermissionUsers in interface CachedPermissionManagement
      Returns:
      all cached permission users.
    • cachedPermissionGroups

      @NonNull public @NonNull Map<String,PermissionGroup> cachedPermissionGroups()
      Gets a map with all cached permission groups mapped to their name.
      Specified by:
      cachedPermissionGroups in interface CachedPermissionManagement
      Returns:
      all cached permission groups.
    • cachedUser

      @Nullable public @Nullable PermissionUser cachedUser(@NonNull @NonNull UUID uniqueId)
      Searches the permission user cache for a permission user with the given unique id.
      Specified by:
      cachedUser in interface CachedPermissionManagement
      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:
      cachedGroup in interface CachedPermissionManagement
      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

      public void acquireLock(@NonNull @NonNull PermissionUser user)
      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:
      acquireLock in interface CachedPermissionManagement
      Parameters:
      user - the user to acquire the lock for.
    • acquireLock

      public void acquireLock(@NonNull @NonNull PermissionGroup group)
      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:
      acquireLock in interface CachedPermissionManagement
      Parameters:
      group - the group to acquire the lock for.
    • locked

      public boolean locked(@NonNull @NonNull PermissionUser user)
      Checks if the given user has any locks locking the user in the cache.
      Specified by:
      locked in interface CachedPermissionManagement
      Parameters:
      user - the user to check for locks.
      Returns:
      true if there are any locks for the given user, false otherwise.
    • locked

      public boolean locked(@NonNull @NonNull PermissionGroup group)
      Checks if the given group has any locks locking the group in the cache.
      Specified by:
      locked in interface CachedPermissionManagement
      Parameters:
      group - the group to check for locks.
      Returns:
      true if there are any locks for the given group, false otherwise.
    • unlock

      public void unlock(@NonNull @NonNull PermissionUser user)
      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:
      unlock in interface CachedPermissionManagement
      Parameters:
      user - the user to remove a lock for.
    • unlock

      public void unlock(@NonNull @NonNull PermissionGroup group)
      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:
      unlock in interface CachedPermissionManagement
      Parameters:
      group - the group to remove a lock for.
    • unlockFully

      public void unlockFully(@NonNull @NonNull PermissionUser user)
      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:
      unlockFully in interface CachedPermissionManagement
      Parameters:
      user - the user to unlock completely.
    • unlockFully

      public void unlockFully(@NonNull @NonNull PermissionGroup group)
      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:
      unlockFully in interface CachedPermissionManagement
      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.