|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.atlassian.crowd.integration.directory.cache.DefaultDirectoryCache
public class DefaultDirectoryCache
Default DirectoryCache implementation, backed by multiple eternal EhCache Cache implementations.
Caches include Entity caches (UNITARY): - userName -> User - groupName -> Group Aggregated name caches (COLLECTION): - static -> [userNames] - static -> [groupNames] Relationship caches (COLLECTION): - userName -> [groupNames] - groupName -> [userNames] (direct members) - groupName -> [child groupNames] (direct members) - groupName -> [parent groupNames] (direct parents) Membership caches (UNITARY): - userName, groupName -> Boolean (direct membership) - userName, roleName -> Boolean - child groupName, parent groupName -> Boolean (direct membership) All unitary caches support values of: - Entity value : when the entity is present - Boolean.FALSE : when the entity is KNOWN to be NOT present - null : when it is not known whether the entity exists or not All collection based caches have values that are PartialSets that can be: - complete PartialSet : when the set is known to be an accurate representation of the remote directory - incomplete PartialSet : when the set contains SOME of the values - null : when the value of the collection is completely unknown NOTE: implementation is case-insensitive for matching. Internal state stores keys (entity names) in lower-case. Queries always return values in the case in which they were stored. IMPORTANT: this cache may turn into a concurrency bottleneck as one read-write lock is used to ensure the threadsafety of the entire cache. All store/update/remove methods are guarded by a write lock and all retrieve methods are guarded by the corresponding read lock. If we experience a massive degredation in performance, we should investigate lock-striping or moving to a database (read: transactional) based cache implementation. Some words of warning regarding cache consistency (ie. caller must ensure): - If a group has it's members/memberships cached then the group itself MUST be cached, so don't call storeUserMembersOfGroup before storeGroup, etc. - If a user has it's memberships cached then the user itself MUST be cached. - If a user/group has any boolean membership information cached the user/group MUST be cached. These requirements are so that membership information is only cached when entity information is cached (eg. for DN mapping).
| Field Summary | |
|---|---|
protected net.sf.ehcache.CacheManager |
cacheManager
|
protected long |
directoryId
|
protected net.sf.ehcache.Cache |
groupCache
|
protected net.sf.ehcache.Cache |
groupChildGroupsCache
|
protected net.sf.ehcache.Cache |
groupGroupMembershipExistsCache
|
protected net.sf.ehcache.Cache |
groupNamesCache
|
protected net.sf.ehcache.Cache |
groupParentGroupsCache
|
protected net.sf.ehcache.Cache |
groupUsersCache
|
protected org.apache.log4j.Logger |
logger
|
protected int |
maxElementsInMemoryPerSubCache
|
protected net.sf.ehcache.Cache |
userCache
|
protected net.sf.ehcache.Cache |
userGroupMembershipExistsCache
|
protected net.sf.ehcache.Cache |
userGroupsCache
|
protected net.sf.ehcache.Cache |
userNamesCache
|
| Constructor Summary | |
|---|---|
DefaultDirectoryCache(long directoryId,
net.sf.ehcache.CacheManager ehcacheManager,
int maxElementsInMemoryPerSubCache)
|
|
| Method Summary | |
|---|---|
protected void |
addMembership(java.lang.String memberName,
java.lang.String containerName,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache booleanMembershipCache)
|
protected void |
addRelationship(java.lang.String entityName,
java.lang.String relationName,
net.sf.ehcache.Cache relationshipCache)
|
void |
clear()
Clear the contents of the entire cache. |
void |
close()
Close the cache and render it unuseable. |
protected net.sf.ehcache.Cache |
createAndConfigureCache(java.lang.String cacheName)
|
protected void |
doClear()
|
protected void |
doClose()
|
protected boolean |
doHandleEvent(com.atlassian.event.Event evt)
|
protected PartialSet<java.lang.String> |
getAllEntityNames(net.sf.ehcache.Cache entityNamesCache)
|
protected java.util.List<java.lang.String> |
getAllEntityNamesAsList(net.sf.ehcache.Cache entityNamesCache)
|
java.util.List<java.lang.String> |
getAllGroupNames()
Retrieves the complete collection of all group names for the cached directory or null if the
complete list is not cached. |
java.util.List<java.lang.String> |
getAllUserNames()
Retrieves the complete collection of all user names for the cached directory or null if the
complete list is not cached. |
protected java.util.List<java.lang.String> |
getCompleteRelationshipsAsList(java.lang.String entityName,
net.sf.ehcache.Cache relationshipCache,
net.sf.ehcache.Cache entityCache)
|
protected java.lang.Object |
getEntity(java.lang.String name,
net.sf.ehcache.Cache entityCache)
|
protected java.lang.Object |
getFromCache(java.io.Serializable name,
net.sf.ehcache.Cache cache)
|
Group |
getGroup(java.lang.String groupName)
Returns the cached Group matching the directoryID and groupName. |
java.util.List<java.lang.String> |
getGroupMembershipsOfGroup(java.lang.String groupName)
Returns a list of group membership names for a particular group. |
java.util.List<java.lang.String> |
getGroupMembershipsOfUser(java.lang.String userName)
Returns a list of group membership names for a particular user. |
java.util.List<java.lang.String> |
getGroupMembersOfGroup(java.lang.String groupName)
Returns a list of child group member names for a particular group. |
java.lang.Class[] |
getHandledEventClasses()
|
protected java.lang.String |
getKey(java.lang.String name)
Return a version of the name appropriate for use as a cache key. |
protected java.util.Collection<java.lang.String> |
getKeys(java.util.Collection<java.lang.String> names)
Applies getKey over a collection. |
protected PartialSet<java.lang.String> |
getRelationships(java.lang.String entityName,
net.sf.ehcache.Cache relationshipCache)
|
protected java.util.List<java.lang.String> |
getRelationshipsAsList(java.lang.String entityName,
net.sf.ehcache.Cache relationshipCache)
|
DirectoryCacheStatistics |
getStatistics()
Allows abstraction away from the underlying implementation. |
User |
getUser(java.lang.String userName)
Returns the cached User matching the directoryID and username. |
java.util.List<java.lang.String> |
getUserMembersOfGroup(java.lang.String groupName)
Returns a list of user member names for a particular group. |
void |
handleEvent(com.atlassian.event.Event evt)
|
protected boolean |
isEventForThisCache(com.atlassian.event.Event evt)
|
java.lang.Boolean |
isGroupGroupMember(java.lang.String childGroup,
java.lang.String parentGroup)
Determines if a childGroup is a direct member of a parentGroup. |
protected java.lang.Boolean |
isMember(java.lang.String memberName,
java.lang.String containerName,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache booleanMembershipCache)
|
java.lang.Boolean |
isUserGroupMember(java.lang.String userName,
java.lang.String groupName)
Determines if a user is a direct member of a group. |
protected void |
lockRead()
|
protected void |
lockWrite()
|
protected void |
removeAllRelations(java.lang.String entityName,
net.sf.ehcache.Cache relationsCache,
net.sf.ehcache.Cache inverseRelationsCache,
net.sf.ehcache.Cache booleanMembershipCache,
boolean isContainer)
|
protected void |
removeCache(java.lang.String cacheName)
|
protected void |
removeEntity(java.lang.String entityName,
net.sf.ehcache.Cache entityCache,
net.sf.ehcache.Cache entityNamesCache)
|
void |
removeGroup(java.lang.String groupName)
Removes a group (if it exists in the cache), along with any existing relationships of the group to users or groups. |
void |
removeGroupAsGroupMember(java.lang.String childGroup,
java.lang.String parentGroup)
Stores the fact that the childGroup is not a direct member of a parentGroup. |
protected void |
removeMembership(java.lang.String memberName,
java.lang.String containerName,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache booleanMembershipCache)
|
protected void |
removeRelationship(java.lang.String entityName,
java.lang.String relationName,
net.sf.ehcache.Cache relationshipCache)
|
void |
removeUser(java.lang.String userName)
Removes a user (if it exists in the cache), along with any existing relationships of the user to groups or roles. |
void |
removeUserAsGroupMember(java.lang.String userName,
java.lang.String groupName)
Stores the fact that the user is not a direct member of a group. |
void |
setGroupAsGroupMember(java.lang.String childGroup,
java.lang.String parentGroup)
Stores the fact that the childGroup is a direct member of a parentGroup. |
protected void |
setMembershipFlag(java.lang.String memberName,
java.lang.String containerName,
boolean membershipFlag,
net.sf.ehcache.Cache booleanMembershipCache)
|
void |
setUserAsGroupMember(java.lang.String userName,
java.lang.String groupName)
Stores the fact that the user is a direct member of a group. |
protected void |
storeAllEntityNames(java.util.List<java.lang.String> entityNames,
net.sf.ehcache.Cache entityNamesCache)
|
void |
storeAllGroupNames(java.util.List<java.lang.String> groupNames)
Store a complete list of all group names for the cached directory. |
void |
storeAllUserNames(java.util.List<java.lang.String> userNames)
Store a complete list of all user names for the cached directory. |
protected void |
storeEntity(DirectoryEntity entity,
net.sf.ehcache.Cache entityCache,
net.sf.ehcache.Cache entityNamesCache)
|
void |
storeGroup(Group group)
Stores a clone of the supplied group object in the cache. |
void |
storeGroupMembershipsOfGroup(java.lang.String groupName,
java.util.Collection<java.lang.String> parentGroupNames)
Stores a list of direct group membership names for a particular group. |
void |
storeGroupMembershipsOfUser(java.lang.String userName,
java.util.Collection<java.lang.String> groupNames)
Stores a list of direct group membership names for a particular user. |
void |
storeGroupMembersOfGroup(java.lang.String groupName,
java.util.Collection<java.lang.String> childGroupNames,
boolean complete)
Stores a list of group member names for a particular group. |
protected void |
storeMembers(java.lang.String containerName,
java.util.Collection<java.lang.String> memberNames,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache booleanMembershipCache,
boolean complete)
This first removes any existing relationships with the group (members, memberships, boolean membership) and then replaces them with the supplied member information. |
protected void |
storeMemberships(java.lang.String memberName,
java.util.Collection<java.lang.String> membershipNames,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache booleanMembershipCache)
|
void |
storeUser(User user)
Stores a clone of the supplied user object in the cache. |
void |
storeUserMembersOfGroup(java.lang.String groupName,
java.util.Collection<java.lang.String> userNames,
boolean complete)
Stores a list of user member names for a particular group. |
protected void |
unlockRead()
|
protected void |
unlockWrite()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final org.apache.log4j.Logger logger
protected final long directoryId
protected final int maxElementsInMemoryPerSubCache
protected final net.sf.ehcache.CacheManager cacheManager
protected final net.sf.ehcache.Cache userCache
protected final net.sf.ehcache.Cache groupCache
protected final net.sf.ehcache.Cache userNamesCache
protected final net.sf.ehcache.Cache groupNamesCache
protected final net.sf.ehcache.Cache userGroupsCache
protected final net.sf.ehcache.Cache groupUsersCache
protected final net.sf.ehcache.Cache groupChildGroupsCache
protected final net.sf.ehcache.Cache groupParentGroupsCache
protected final net.sf.ehcache.Cache userGroupMembershipExistsCache
protected final net.sf.ehcache.Cache groupGroupMembershipExistsCache
| Constructor Detail |
|---|
public DefaultDirectoryCache(long directoryId,
net.sf.ehcache.CacheManager ehcacheManager,
int maxElementsInMemoryPerSubCache)
| Method Detail |
|---|
protected net.sf.ehcache.Cache createAndConfigureCache(java.lang.String cacheName)
protected void removeCache(java.lang.String cacheName)
protected void lockRead()
protected void unlockRead()
protected void lockWrite()
protected void unlockWrite()
public void clear()
DirectoryCache
clear in interface DirectoryCacheprotected void doClear()
public void close()
DirectoryCache
close in interface DirectoryCacheprotected void doClose()
protected java.lang.String getKey(java.lang.String name)
name - key.
protected java.util.Collection<java.lang.String> getKeys(java.util.Collection<java.lang.String> names)
names - set of names.
protected java.lang.Object getEntity(java.lang.String name,
net.sf.ehcache.Cache entityCache)
throws ObjectNotFoundException
ObjectNotFoundException
protected java.lang.Object getFromCache(java.io.Serializable name,
net.sf.ehcache.Cache cache)
protected PartialSet<java.lang.String> getAllEntityNames(net.sf.ehcache.Cache entityNamesCache)
protected java.util.List<java.lang.String> getAllEntityNamesAsList(net.sf.ehcache.Cache entityNamesCache)
protected void storeAllEntityNames(java.util.List<java.lang.String> entityNames,
net.sf.ehcache.Cache entityNamesCache)
protected void storeEntity(DirectoryEntity entity,
net.sf.ehcache.Cache entityCache,
net.sf.ehcache.Cache entityNamesCache)
protected void removeEntity(java.lang.String entityName,
net.sf.ehcache.Cache entityCache,
net.sf.ehcache.Cache entityNamesCache)
protected void removeAllRelations(java.lang.String entityName,
net.sf.ehcache.Cache relationsCache,
net.sf.ehcache.Cache inverseRelationsCache,
net.sf.ehcache.Cache booleanMembershipCache,
boolean isContainer)
protected PartialSet<java.lang.String> getRelationships(java.lang.String entityName,
net.sf.ehcache.Cache relationshipCache)
protected java.util.List<java.lang.String> getRelationshipsAsList(java.lang.String entityName,
net.sf.ehcache.Cache relationshipCache)
protected java.util.List<java.lang.String> getCompleteRelationshipsAsList(java.lang.String entityName,
net.sf.ehcache.Cache relationshipCache,
net.sf.ehcache.Cache entityCache)
protected void removeRelationship(java.lang.String entityName,
java.lang.String relationName,
net.sf.ehcache.Cache relationshipCache)
protected void addRelationship(java.lang.String entityName,
java.lang.String relationName,
net.sf.ehcache.Cache relationshipCache)
protected void setMembershipFlag(java.lang.String memberName,
java.lang.String containerName,
boolean membershipFlag,
net.sf.ehcache.Cache booleanMembershipCache)
protected void removeMembership(java.lang.String memberName,
java.lang.String containerName,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache booleanMembershipCache)
protected void addMembership(java.lang.String memberName,
java.lang.String containerName,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache booleanMembershipCache)
protected void storeMembers(java.lang.String containerName,
java.util.Collection<java.lang.String> memberNames,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache booleanMembershipCache,
boolean complete)
containerName - name of group.memberNames - names of members.membersCache - cache to put members, ie. groupName -> [memberNames]membershipsCache - cache to put memberships, ie. memberName -> [groupNames]booleanMembershipCache - cache to put boolean membership, ie. memberName, groupName -> TRUEcomplete - if the collection of memberNames represents the complete/entire collection of direct members of the group.
protected void storeMemberships(java.lang.String memberName,
java.util.Collection<java.lang.String> membershipNames,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache booleanMembershipCache)
protected java.lang.Boolean isMember(java.lang.String memberName,
java.lang.String containerName,
net.sf.ehcache.Cache membershipsCache,
net.sf.ehcache.Cache membersCache,
net.sf.ehcache.Cache booleanMembershipCache)
public User getUser(java.lang.String userName)
throws ObjectNotFoundException
DirectoryCachenull is returned.
This signifies we do not know whether the user exists or not.
If it is known that the user does not exist, an
ObjectNotFoundException is thrown. For example,
if a user is removed, a subsequent getUser call attempting
to find the removed user will throw this exception.
The returning user is a clone of user object in the
cache. Callers are free to mutate the clone however they want.
getUser in interface DirectoryCacheuserName - name of user to find.
null.
ObjectNotFoundException - if the object does not exist.public java.util.List<java.lang.String> getAllUserNames()
DirectoryCachenull if the
complete list is not cached.
getAllUserNames in interface DirectoryCachenull
if the complete list is not cached.public void storeAllUserNames(java.util.List<java.lang.String> userNames)
DirectoryCache
storeAllUserNames in interface DirectoryCacheuserNames - complete list of all user names.public void storeUser(User user)
DirectoryCache
storeUser in interface DirectoryCacheuser - user to cache.public void removeUser(java.lang.String userName)
DirectoryCache
removeUser in interface DirectoryCacheuserName - name of user to remove from cache.
public Group getGroup(java.lang.String groupName)
throws ObjectNotFoundException
DirectoryCachenull is returned.
This signifies we do not know whether the group exists or not.
If it is known that the group does not exist, an
ObjectNotFoundException is thrown. For example,
if a group is removed, a subsequent getGroup call attempting
to find the removed group will throw this exception.
The returning group is a clone of group object in the
cache. Callers are free to mutate the clone however they want.
getGroup in interface DirectoryCachegroupName - name of group to find.
null.
ObjectNotFoundException - if the object does not exist.public java.util.List<java.lang.String> getAllGroupNames()
DirectoryCachenull if the
complete list is not cached.
getAllGroupNames in interface DirectoryCachenull
if the complete list is not cached.public void storeAllGroupNames(java.util.List<java.lang.String> groupNames)
DirectoryCache
storeAllGroupNames in interface DirectoryCachegroupNames - complete list of all group names.public void storeGroup(Group group)
DirectoryCache
storeGroup in interface DirectoryCachegroup - group to cache.public void removeGroup(java.lang.String groupName)
DirectoryCache
removeGroup in interface DirectoryCachegroupName - name of group to remove from cache.public java.util.List<java.lang.String> getUserMembersOfGroup(java.lang.String groupName)
DirectoryCache
getUserMembersOfGroup in interface DirectoryCachegroupName - name of group to lookup.
public void storeUserMembersOfGroup(java.lang.String groupName,
java.util.Collection<java.lang.String> userNames,
boolean complete)
DirectoryCachecomplete parameter is set to
true, the collection of user names is assumed
to be the complete collection of direct user members
of the group.
The usernames is allowed to be incomplete ONLY IF the missing usernames are
not stored in the cache at all (ie. the entities are not stored / the entities membership
information is not stored). Therefore the usernames ALWAYS represents the
COMPLETE list of members the cache knows about (regardless of the "complete" flag).
The "complete" flag denotes that the collection is the complete list of usernames in the entire directory
for the group.
storeUserMembersOfGroup in interface DirectoryCachegroupName - name of the group.userNames - collection of direct user members of the group.complete - true if and only if the collection of direct
user member names reflects the complete set of direct user members.public java.util.List<java.lang.String> getGroupMembershipsOfUser(java.lang.String userName)
DirectoryCache
getGroupMembershipsOfUser in interface DirectoryCacheuserName - name of user to lookup.
public void storeGroupMembershipsOfUser(java.lang.String userName,
java.util.Collection<java.lang.String> groupNames)
DirectoryCache
storeGroupMembershipsOfUser in interface DirectoryCacheuserName - name of the user.groupNames - collection of direct group memberships of the user.
group membership names reflects the complete set of direct group memberships.
public java.lang.Boolean isUserGroupMember(java.lang.String userName,
java.lang.String groupName)
DirectoryCache
isUserGroupMember in interface DirectoryCacheuserName - name of user.groupName - name of group.
true iff the user is a direct member of the group,
false iff the user is not a direct member of the group,
null iff there is insufficient information in the cache to
determine whether the user is a direct member of the group or not.
public void setUserAsGroupMember(java.lang.String userName,
java.lang.String groupName)
DirectoryCache
setUserAsGroupMember in interface DirectoryCacheuserName - name of user.groupName - name of group.
public void removeUserAsGroupMember(java.lang.String userName,
java.lang.String groupName)
DirectoryCache
removeUserAsGroupMember in interface DirectoryCacheuserName - name of user.groupName - name of group.public java.util.List<java.lang.String> getGroupMembersOfGroup(java.lang.String groupName)
DirectoryCache
getGroupMembersOfGroup in interface DirectoryCachegroupName - name of parent group to lookup.
public void storeGroupMembersOfGroup(java.lang.String groupName,
java.util.Collection<java.lang.String> childGroupNames,
boolean complete)
DirectoryCachecomplete parameter is set to
true, the collection of group names is assumed
to be the complete collection of direct group members
of the group.
The childGroupNames is allowed to be incomplete ONLY IF the missing childGroupNames are
not stored in the cache at all (ie. the entities are not stored / the entities membership
information is not stored). Therefore the childGroupNames ALWAYS represents the
COMPLETE list of members the cache knows about (regardless of the "complete" flag).
The "complete" flag denotes that the collection is the complete list of childGroupNames in the entire directory
for the group.
storeGroupMembersOfGroup in interface DirectoryCachegroupName - name of the group.childGroupNames - collection of direct group members of the group.complete - true if and only if the collection of direct
group member names reflects the complete set of direct group members.public java.util.List<java.lang.String> getGroupMembershipsOfGroup(java.lang.String groupName)
DirectoryCache
getGroupMembershipsOfGroup in interface DirectoryCachegroupName - name of group to lookup.
public void storeGroupMembershipsOfGroup(java.lang.String groupName,
java.util.Collection<java.lang.String> parentGroupNames)
DirectoryCache
storeGroupMembershipsOfGroup in interface DirectoryCachegroupName - name of the child group.parentGroupNames - collection of direct group memberships of the child group.
group membership names reflects the complete set of direct group memberships.
public java.lang.Boolean isGroupGroupMember(java.lang.String childGroup,
java.lang.String parentGroup)
DirectoryCache
isGroupGroupMember in interface DirectoryCachechildGroup - name of child group.parentGroup - name of parent group.
true iff the childGroup is a direct member of the parentGroup,
false iff the childGroup is not a direct member of the parentGroup,
null iff there is insufficient information in the cache to
determine whether the childGroup is a direct member of the parentGroup or not.
public void setGroupAsGroupMember(java.lang.String childGroup,
java.lang.String parentGroup)
DirectoryCache
setGroupAsGroupMember in interface DirectoryCachechildGroup - name of child group.parentGroup - name of parent group.
public void removeGroupAsGroupMember(java.lang.String childGroup,
java.lang.String parentGroup)
DirectoryCache
removeGroupAsGroupMember in interface DirectoryCachechildGroup - name of child group.parentGroup - name of parent group.protected boolean isEventForThisCache(com.atlassian.event.Event evt)
protected boolean doHandleEvent(com.atlassian.event.Event evt)
public void handleEvent(com.atlassian.event.Event evt)
handleEvent in interface com.atlassian.event.EventListenerpublic java.lang.Class[] getHandledEventClasses()
getHandledEventClasses in interface com.atlassian.event.EventListenerpublic DirectoryCacheStatistics getStatistics()
getStatistics in interface DirectoryCache
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||