Package org.wildfly.security.cache
Class LRURealmIdentityCache
- java.lang.Object
-
- org.wildfly.security.cache.LRURealmIdentityCache
-
- All Implemented Interfaces:
RealmIdentityCache
public final class LRURealmIdentityCache extends Object implements RealmIdentityCache
ARealmIdentityCache
implementation providing a LRU cache.- Author:
- Pedro Igor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
LRURealmIdentityCache.CacheEntry
-
Field Summary
Fields Modifier and Type Field Description private static float
DEFAULT_LOAD_FACTOR
The load factor.private Map<Principal,Set<Principal>>
domainPrincipalMap
Holds a mapping between a realm principal and domain principalsprivate Map<Principal,LRURealmIdentityCache.CacheEntry>
identityCache
Holds the cached identitys where the key is the domain principal, the one used to lookup the identityprivate long
maxAge
private AtomicBoolean
writing
-
Constructor Summary
Constructors Constructor Description LRURealmIdentityCache(int maxEntries)
Creates a new instance.LRURealmIdentityCache(int maxEntries, long maxAge)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all cached identities from this cache.RealmIdentity
get(Principal key)
Obtains a previously cachedRealmIdentity
ornull
if no entry could be found with the specifiedPrincipal
.private boolean
parkForReadAndCheckInterrupt()
private boolean
parkForWriteAndCheckInterrupt()
void
put(Principal key, RealmIdentity newValue)
Puts a newRealmIdentity
into the cache and referenced by the specifiedPrincipal
.void
remove(Principal key)
Removes a specific cached identity from the cache and referenced by the specifiedPrincipal
.private RealmIdentity
removeIfExpired(LRURealmIdentityCache.CacheEntry cached)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.wildfly.security.cache.RealmIdentityCache
computeIfAbsent
-
-
-
-
Field Detail
-
DEFAULT_LOAD_FACTOR
private static final float DEFAULT_LOAD_FACTOR
The load factor.- See Also:
- Constant Field Values
-
identityCache
private final Map<Principal,LRURealmIdentityCache.CacheEntry> identityCache
Holds the cached identitys where the key is the domain principal, the one used to lookup the identity
-
domainPrincipalMap
private final Map<Principal,Set<Principal>> domainPrincipalMap
Holds a mapping between a realm principal and domain principals
-
writing
private final AtomicBoolean writing
-
maxAge
private final long maxAge
-
-
Constructor Detail
-
LRURealmIdentityCache
public LRURealmIdentityCache(int maxEntries)
Creates a new instance.- Parameters:
maxEntries
- the maximum number of entries to keep in the cache
-
LRURealmIdentityCache
public LRURealmIdentityCache(int maxEntries, long maxAge)
Creates a new instance.- Parameters:
maxEntries
- the maximum number of entries to keep in the cachemaxAge
- the time in milliseconds that an entry can stay in the cache. If-1
, entries never expire
-
-
Method Detail
-
put
public void put(Principal key, RealmIdentity newValue)
Description copied from interface:RealmIdentityCache
Puts a newRealmIdentity
into the cache and referenced by the specifiedPrincipal
.- Specified by:
put
in interfaceRealmIdentityCache
- Parameters:
key
- thePrincipal
that references the realm identity being cachednewValue
- theRealmIdentity
instance
-
get
public RealmIdentity get(Principal key)
Description copied from interface:RealmIdentityCache
Obtains a previously cachedRealmIdentity
ornull
if no entry could be found with the specifiedPrincipal
.- Specified by:
get
in interfaceRealmIdentityCache
- Parameters:
key
- thePrincipal
that references a previously cached realm identity- Returns:
- a cached
RealmIdentity
instance ornull
if no entry could be found with the specifiedprincipal
.
-
remove
public void remove(Principal key)
Description copied from interface:RealmIdentityCache
Removes a specific cached identity from the cache and referenced by the specifiedPrincipal
.- Specified by:
remove
in interfaceRealmIdentityCache
- Parameters:
key
- thePrincipal
that references a previously cached realm identity
-
clear
public void clear()
Description copied from interface:RealmIdentityCache
Removes all cached identities from this cache.- Specified by:
clear
in interfaceRealmIdentityCache
-
removeIfExpired
private RealmIdentity removeIfExpired(LRURealmIdentityCache.CacheEntry cached)
-
parkForWriteAndCheckInterrupt
private boolean parkForWriteAndCheckInterrupt()
-
parkForReadAndCheckInterrupt
private boolean parkForReadAndCheckInterrupt()
-
-