Package org.apache.cassandra.auth
Class AuthCache<K,V>
- java.lang.Object
-
- org.apache.cassandra.auth.AuthCache<K,V>
-
- All Implemented Interfaces:
AuthCacheMBean,Shutdownable
- Direct Known Subclasses:
AuthorizationProxy.JmxPermissionsCache,NetworkPermissionsCache,PasswordAuthenticator.CredentialsCache,PermissionsCache,RolesCache
public class AuthCache<K,V> extends java.lang.Object implements AuthCacheMBean, Shutdownable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAuthCache.BulkLoader<K,V>
-
Field Summary
Fields Modifier and Type Field Description protected com.github.benmanes.caffeine.cache.LoadingCache<K,V>cacheUnderlying cache.static java.lang.StringMBEAN_NAME_BASE
-
Constructor Summary
Constructors Modifier Constructor Description protectedAuthCache(java.lang.String name, java.util.function.IntConsumer setValidityDelegate, java.util.function.IntSupplier getValidityDelegate, java.util.function.IntConsumer setUpdateIntervalDelegate, java.util.function.IntSupplier getUpdateIntervalDelegate, java.util.function.IntConsumer setMaxEntriesDelegate, java.util.function.IntSupplier getMaxEntriesDelegate, java.util.function.Consumer<java.lang.Boolean> setActiveUpdate, java.util.function.BooleanSupplier getActiveUpdate, java.util.function.Function<K,V> loadFunction, java.util.function.Supplier<java.util.Map<K,V>> bulkLoadFunction, java.util.function.BooleanSupplier cacheEnabledDelegate)protectedAuthCache(java.lang.String name, java.util.function.IntConsumer setValidityDelegate, java.util.function.IntSupplier getValidityDelegate, java.util.function.IntConsumer setUpdateIntervalDelegate, java.util.function.IntSupplier getUpdateIntervalDelegate, java.util.function.IntConsumer setMaxEntriesDelegate, java.util.function.IntSupplier getMaxEntriesDelegate, java.util.function.Consumer<java.lang.Boolean> setActiveUpdate, java.util.function.BooleanSupplier getActiveUpdate, java.util.function.Function<K,V> loadFunction, java.util.function.Supplier<java.util.Map<K,V>> bulkLoadFunction, java.util.function.BooleanSupplier cacheEnabledDelegate, java.util.function.BiPredicate<K,V> invalidationCondition)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, java.util.concurrent.TimeUnit units)Await termination of this object, i.e.Vget(K k)Retrieve a value from the cache.booleangetActiveUpdate()java.util.Map<K,V>getAll()Retrieve all cached entries.longgetEstimatedSize()intgetMaxEntries()protected java.lang.StringgetObjectName()intgetUpdateInterval()intgetValidity()protected voidinit()Do setup for the cache and MBean.protected com.github.benmanes.caffeine.cache.LoadingCache<K,V>initCache(com.github.benmanes.caffeine.cache.LoadingCache<K,V> existing)(Re-)initialise the underlying cache.voidinvalidate()Invalidate the entire cache.voidinvalidate(K k)Invalidate a key.booleanisTerminated()voidsetActiveUpdate(boolean update)voidsetMaxEntries(int maxEntries)Set maximum number of entries in the cache.voidsetUpdateInterval(int updateInterval)Time in milliseconds after which an entry in the cache should be refreshed (it's load function called again)voidsetValidity(int validityPeriod)Time in milliseconds that a value in the cache will expire after.voidshutdown()Shutdown once any remaining work has completed (however this is defined for the implementation).static voidshutdownAllAndWait(long timeout, java.util.concurrent.TimeUnit unit)java.lang.ObjectshutdownNow()Shutdown immediately, possibly interrupting ongoing work, and cancelling work that is queued.protected voidunregisterMBean()voidwarm()
-
-
-
Field Detail
-
MBEAN_NAME_BASE
public static final java.lang.String MBEAN_NAME_BASE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AuthCache
protected AuthCache(java.lang.String name, java.util.function.IntConsumer setValidityDelegate, java.util.function.IntSupplier getValidityDelegate, java.util.function.IntConsumer setUpdateIntervalDelegate, java.util.function.IntSupplier getUpdateIntervalDelegate, java.util.function.IntConsumer setMaxEntriesDelegate, java.util.function.IntSupplier getMaxEntriesDelegate, java.util.function.Consumer<java.lang.Boolean> setActiveUpdate, java.util.function.BooleanSupplier getActiveUpdate, java.util.function.Function<K,V> loadFunction, java.util.function.Supplier<java.util.Map<K,V>> bulkLoadFunction, java.util.function.BooleanSupplier cacheEnabledDelegate)- Parameters:
name- Used for MBeansetValidityDelegate- Used to set cache validity period. SeePolicy.expireAfterWrite()getValidityDelegate- Getter for validity periodsetUpdateIntervalDelegate- Used to set cache update interval. SeePolicy.refreshAfterWrite()getUpdateIntervalDelegate- Getter for update intervalsetMaxEntriesDelegate- Used to set max # entries in cache. SeePolicy.Eviction.setMaximum(long)getMaxEntriesDelegate- Getter for max entries.setActiveUpdate- Method to process config to actively update the auth cache prior to configured cache expirationgetActiveUpdate- Getter for active updateloadFunction- Function to load the cache. Called onget(Object)cacheEnabledDelegate- Used to determine if cache is enabled.
-
AuthCache
protected AuthCache(java.lang.String name, java.util.function.IntConsumer setValidityDelegate, java.util.function.IntSupplier getValidityDelegate, java.util.function.IntConsumer setUpdateIntervalDelegate, java.util.function.IntSupplier getUpdateIntervalDelegate, java.util.function.IntConsumer setMaxEntriesDelegate, java.util.function.IntSupplier getMaxEntriesDelegate, java.util.function.Consumer<java.lang.Boolean> setActiveUpdate, java.util.function.BooleanSupplier getActiveUpdate, java.util.function.Function<K,V> loadFunction, java.util.function.Supplier<java.util.Map<K,V>> bulkLoadFunction, java.util.function.BooleanSupplier cacheEnabledDelegate, java.util.function.BiPredicate<K,V> invalidationCondition)- Parameters:
name- Used for MBeansetValidityDelegate- Used to set cache validity period. SeePolicy.expireAfterWrite()getValidityDelegate- Getter for validity periodsetUpdateIntervalDelegate- Used to set cache update interval. SeePolicy.refreshAfterWrite()getUpdateIntervalDelegate- Getter for update intervalsetMaxEntriesDelegate- Used to set max # entries in cache. SeePolicy.Eviction.setMaximum(long)getMaxEntriesDelegate- Getter for max entries.setActiveUpdate- Actively update the cache before expirygetActiveUpdate- Getter for active updateloadFunction- Function to load the cache. Called onget(Object)cacheEnabledDelegate- Used to determine if cache is enabled.invalidationCondition- Used during active updates to determine if a refreshed value indicates a missing entry in the underlying table. If satisfied, the key will be invalidated.
-
-
Method Detail
-
shutdownAllAndWait
public static void shutdownAllAndWait(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.TimeoutException
-
init
protected void init()
Do setup for the cache and MBean.
-
unregisterMBean
protected void unregisterMBean()
-
getObjectName
protected java.lang.String getObjectName()
-
getAll
public java.util.Map<K,V> getAll()
Retrieve all cached entries. Will callCache.asMap()which does not trigger "load".- Returns:
- a map of cached key-value pairs
-
get
public V get(K k)
Retrieve a value from the cache. Will callLoadingCache.get(Object)which will "load" the value if it's not present, thus populating the key.- Parameters:
k-- Returns:
- The current value of
Kif cached or loaded. SeeLoadingCache.get(Object)for possible exceptions.
-
invalidate
public void invalidate()
Invalidate the entire cache.- Specified by:
invalidatein interfaceAuthCacheMBean
-
invalidate
public void invalidate(K k)
Invalidate a key.- Parameters:
k- key to invalidate
-
setValidity
public void setValidity(int validityPeriod)
Time in milliseconds that a value in the cache will expire after.- Specified by:
setValidityin interfaceAuthCacheMBean- Parameters:
validityPeriod- in milliseconds
-
getValidity
public int getValidity()
- Specified by:
getValidityin interfaceAuthCacheMBean
-
setUpdateInterval
public void setUpdateInterval(int updateInterval)
Time in milliseconds after which an entry in the cache should be refreshed (it's load function called again)- Specified by:
setUpdateIntervalin interfaceAuthCacheMBean- Parameters:
updateInterval- in milliseconds
-
getUpdateInterval
public int getUpdateInterval()
- Specified by:
getUpdateIntervalin interfaceAuthCacheMBean
-
setMaxEntries
public void setMaxEntries(int maxEntries)
Set maximum number of entries in the cache.- Specified by:
setMaxEntriesin interfaceAuthCacheMBean- Parameters:
maxEntries-
-
getMaxEntries
public int getMaxEntries()
- Specified by:
getMaxEntriesin interfaceAuthCacheMBean
-
getActiveUpdate
public boolean getActiveUpdate()
- Specified by:
getActiveUpdatein interfaceAuthCacheMBean
-
setActiveUpdate
public void setActiveUpdate(boolean update)
- Specified by:
setActiveUpdatein interfaceAuthCacheMBean
-
getEstimatedSize
public long getEstimatedSize()
- Specified by:
getEstimatedSizein interfaceAuthCacheMBean
-
initCache
protected com.github.benmanes.caffeine.cache.LoadingCache<K,V> initCache(com.github.benmanes.caffeine.cache.LoadingCache<K,V> existing)
(Re-)initialise the underlying cache. Will update validity, max entries, and update interval if any have changed. The underlyingLoadingCachewill be initiated based on the providedloadFunction. Note: If you need some unhandled cache setting to be set you should extendAuthCacheand override this method.- Parameters:
existing- If not null will only update cache update validity, max entries, and update interval.- Returns:
- New
LoadingCacheif existing was null, otherwise the existingcache
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfaceShutdownable
-
shutdown
public void shutdown()
Description copied from interface:ShutdownableShutdown once any remaining work has completed (however this is defined for the implementation).- Specified by:
shutdownin interfaceShutdownable
-
shutdownNow
public java.lang.Object shutdownNow()
Description copied from interface:ShutdownableShutdown immediately, possibly interrupting ongoing work, and cancelling work that is queued.- Specified by:
shutdownNowin interfaceShutdownable
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit units) throws java.lang.InterruptedExceptionDescription copied from interface:ShutdownableAwait termination of this object, i.e. the cessation of all current and future work.- Specified by:
awaitTerminationin interfaceShutdownable- Throws:
java.lang.InterruptedException
-
warm
public void warm()
-
-